CLsqFit:Eval CLsqFit:GetSampleMean

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( n, nChan* )

r = CLsqFit:GetResid( n, nChan* )

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

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

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 = CLsqFit:new()

-- 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

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 = CLsqFit:new()

-- 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 a point for x = 3.5 and y = "12, 242, 5.1"

 

-- add more points

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

  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