fit(deprecated)/leastsqu - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : fit(deprecated)/leastsqu

stats[fit, leastsquare]

Fit a curve to data using the least square method

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

stats[fit, leastsquare[vars, eqn, parms]]( data)

fit[leastsquare[vars, eqn, parms]]( data)

Parameters

data

-

list of statistical lists

vars

-

list of variables, corresponding, in order, to the lists in data

eqn

-

The equation to fit (optional, default = a linear equation with the last variable in vars as dependent variable and with a constant term).

parms

-

Set of parameters that will be replaced (optional, default = indets(eqn) minus op(vars)).

Description

• 

Important: The stats package has been deprecated. Use the superseding package Statistics instead.

• 

The function leastsquare of the subpackage stats[fit, ...] fits a curve to the given data using the method of least squares.

• 

The equation to fit must be linear in the unknown parameters. The equation itself need not be linear. For example, y=ax2+bx+c with the parameters a, b, c is accepted. Note that some equations which have their parameters appearing nonlinearly can be transformed to linear ones. y=aⅇbx can be transformed into lny=A+bx, where A=loga.  The leastsquares command does not apply this transformation automatically, but the Statistics[ExponentialFit] command can be used instead.

• 

Missing data  and ranges cannot be handled.

• 

Weighted data are handled in the following fashion. The weight associated with the dependent variable is the weight given to the corresponding point. The weight specifications corresponding to the independent variables are ignored.

• 

Data fitting routines are also available in the Statistics package.  For more information, see the Statistics[Regression] help page.

• 

The command with(stats[fit],leastsquare) allows the use of the abbreviated form of this command.

Examples

Important: The stats package has been deprecated. Use the superseding package Statistics instead.

withstats:

fitleastsquarex,y,z1,2,3,5,2,4,6,8,3,5,7,10

z=x+y2+1

(1)

Here's an example using Weight

fitleastsquarex,y,z1,2,3,5,5,5,2,4,6,8,8,8,3,5,7,10,15,15

z=13x37y6+1

(2)

fitleastsquarex,y,z1,2,3,5,5,2,4,6,8,8,3,5,7,10,Weight15,2

z=13x37y6+1

(3)

A fit to a quadratic:

Xvalues1,2,3,4

Xvalues1,2,3,4

(4)

Yvalues0,6,14,24

Yvalues0,6,14,24

(5)

eq_fitfitleastsquarex,y,y=ax2+bx+c,a,b,cXvalues,Yvalues

eq_fity=x2+3x4

(6)

The {a,b,c} parameter is optional in this case, since there are no extra Maple variables in the equation (compare with  y=a*x^2+b*x+c+Pi*x^3, where Pi is definitely not a parameter.)

eq_fitfitleastsquarex,y,y=ax2+bx+cXvalues,Yvalues

eq_fity=x2+3x4

(7)

Transform this into a procedure

eq_functionunapplyrhseq_fit,x

eq_functionxx2+3x4

(8)

Then give the predicted values  (we could have used map() in this case, since the data does not involve classes or weights)

Yvalues_predictedtransformapplyeq_functionXvalues

Yvalues_predicted0,6,14,24

(9)

Find the residuals:

Residualstransformmultiapplyx,yxyYvalues,Yvalues_predicted

Residuals0,0,0,0

(10)

The residuals are all zero since all the points fall on the quadratic.

See Also

describe(deprecated)[linearcorrelation]

Statistics

Statistics[Regression]