CLsqFit:GetCovar


The GetCovar method returns the covariance between fit coefficients. The covariance measures the degree of relationship between the calculated coefficients. A lower value indicates greater significance in the independence between coefficient values.

Syntax

nC = CLsqFit:GetCovar( nIndex1, nIndex2 )

nC = CLsqFit:GetCovar( nIndex1, nIndex2, nChan )

nC1, nC2, nC3, nC4 = CLsqFit:GetCovar( nIndex1, nIndex2 )

where

    nIndex1 and nIndex2 are the coefficient indices. Both are numbers between 1 and GetNumCoefs().

    nC is the returned value of the covariance.

    nChan is an optional argument that specifies the channel for multi-channel (RGB) data.

    nC1, nC2, nC3, and nC4 are the covariance values returned for multi-channel data when no channel is specified.

  

This function returns the covariance between coefficients at two indices, nIndex1 and nIndex2. If multi-channel data has been enabled, then values are returned for all channels unless you specifically specify a channel. The errors of the coefficients can be obtained using GetCoefErr and the coefficients themselves can be obtained using GetCoef.

If using the built-in n-dimensional polynomial basis function with n > 1, then the index of the coefficient must be determined by calculating it from the polynomial dimensions or by using GetPolyCoefIndex.

Example

The following script fits a 2x2 polynomial, then retrieves the covariance between coefficients at 1, 1 and at 2, 2.

L = CLsqFit:new()

-- create a CLsqFit object

L:SetNumCoefs( {2.2} )

-- set 2x2 coefficients to fit a warped plane

L:AddPt( {3, 5}, 5.15 )

-- add a point with x = 3, y = 5, z = 5.15

 

-- add more points

L:Fit()

-- Fit the polynomial

n1 = L:GetPolyCoefIndex( 1, 1 )

-- fetch the index of the coefficient at 1, 1

n2 = L:GetPolyCoefIndex( 2, 2 )

-- fetch the index of the coefficient at 2, 2

v = L:GetCovar( n1, n2 )

-- fetch the covariance between 1,1 and 2,2

Printf( "Cov[%d][%d]= %lg\n", n1, n2, v )

-- list the covariance

Related Topics

GetCoef

GetCoefErr

SetNumCoefs

GetPolyCoefIndex

CLsqFit class