CLsqFit:GetResid


The GetResid method returns the residual of a sample point defined as observed value minus the value predicted from the fit. use this method to assess the quality of data points and their effect on the resulting fit.

Syntax

r = CLsqFit:GetResid( nIndex )

r = CLsqFit:GetResid( nIndex, nChannel )

r1, r2, r3, r4 = CLsqFit:GetResid( nIndex )

bullet.gif    nIndex is the index of the point in the sample data.

bullet.gif    nChannel is an optional parameter for the channel to search. If omitted, all channels are searched.

bullet.gif    r, r1, r2, r3, and r4 are the residual values of the point in the sample data or in the channels of multi-channel (e.g., RGB) data. The number of values returned equals the number of channels.

Remarks

The GetResid method returns the residual value for the point at an index in the sample data. If the fit uses more than 1 channel, then the two forms are used to retrieve either a single value or the number of values specified by the SetNumChannels method.

This function is equivalent to computing the value of fit for a point using its basis coordinates and then subtracting that from its actual value in the data sample.

Examples

The following example illustrates how to retrieve the residuals of all data points in a fit to numeric (single channel) data.

L = new_lsqfit()

-- create a CLsqFit object

L:SetNumCoefs( 2 )

-- set 2 coefficients

L:AddPt( 3.5, 5.15 )

-- add a point for x = 3.5 and y = 5.15

-- add more points to the fit

 

L:Fit()

-- Fit the line

n = L:GetNumPts()

-- get the number of points added to the fit

for i = 1, n do

-- loop over all points

  r = L:GetResid( i )

-- fetch the residual for the i-th point

  Printf( "r[%d]= %lg\n", i, r )

-- list the residual

end

 

 

The next example is similar to the first example, except that the fit involved RGB data. Note that 3 values are returned for the residuals of the i-th point because the fit used SetNumChannels( 3 ):

L = new_lsqfit()

-- create a CLsqFit object

L:SetNumChannels( 3 )

-- specify 3 channels

L:SetNumCoefs( 2 )

-- set 2 coefficients

L:AddPt( 3.5, "12, 242,5.1" )

-- add point for x = 3.5, y = "12, 242, 5.1"

-- add more points to the fit

 

L:Fit()

-- Fit the line

n = L:GetNumPts()

-- get the number of points to fit

for i = 1, n do

-- loop over all points

  r1, r2, r3 = L:GetResid( i )

-- fetch the residuals for the i-th point

  Printf( "r[%d]= %lg,%lg,%lg\n", i, r1, r2, r3 )

-- list the residual

end

 

Related Topics

CLsqFit class, GetNumPts, GetNumPtsUsed, SetNumChannels, Eval


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics, Inc. All Rights Reserved.