CLsqFit:GetSampleMean


The GetSampleMean method returns the mean value of points in the sample for the n-th independent variable.

Syntax

nMean = CLsqFit:GetSampleMean()

nMean = CLsqFit:GetSampleMean( nDimension )

bullet.gif    nDimension specifies the basis dimension (index of the independent variable). If not specified, 1 is assumed for a 1-dimensional fit.

bullet.gif    nMean is the sample mean for the specified nDimension or the only dimension.

Remarks

The sample means may be useful to know, especially when the basis function fits about the mean rather than about the origin (see Basis Functions). A table containing the sample means is passed to a user-defined basis function declared in the script, but the function does not have to use them to fit about the mean. The built-in basis functions fit about the mean automatically. In all cases,. the sample means are calculated even if you do not use them. You should not use the sample means in your calculations; The basis function determines whether the fit is done about the mean or the origin, so Mira automatically handles the sample means when you call Eval or other methods.

Example

The following script adds points, fits a line, and then lists the sample mean. If there were two independent variables, like fitting a surface to x and y, then you could query GetSampleMean(1) and GetSampleMean(2) to get the means in the x and y data.

L = new_lsqfit()

-- create a CLsqFit object

L:SetNumCoefs( 2 )

-- set 2 coefficients to fit a line

L:AddPt( -3, -1 )

-- add data points

L:AddPt( 4, 12 )

 

L:AddPt( -1, 3 )

 

L:AddPt( 5, -10 )

 

L:AddPt( 6, 16.5 )

 

L:AddPt( 12, 29 )

 

L:AddPt( 3, 10.7 )

 

L:AddPt( 5, 15.3 )

 

L:AddPt( 2, 9.3 )

 

L:AddPt( 8, 20.8 )

 

L:AddPt( 4, 12.7 )

 

L:AddPt( 5, 15.3 )

 

L:AddPt( 3, 11.3 )

 

L:AddPt( 11, 27.1 )

 

L:Fit()

-- Fit the polynomial

m = GetSampleMean()

-- get the sample mean for the x data

Printf( "Mean x = %lg\n", m )

-- result: Mean x = 4.57143

Related Topics

CLsqFit class, SetBasisFunc, GetBasisDim


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