fit(deprecated)/leastsqu - Help

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

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+12y+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=133x76y+1

(2)

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

z=133x76y+1

(3)

A fit to a quadratic:

Xvalues:=1,2,3,4

Xvalues:=1,2,3,4

(4)

Yvalues:=0,6,14,24

Yvalues:=0,6,14,24

(5)

eq_fit:=fitleastsquarex,y,y=ax2+bx+c,a,b,cXvalues,Yvalues

eq_fit:=y=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_fit:=fitleastsquarex,y,y=ax2+bx+cXvalues,Yvalues

eq_fit:=y=x2+3x4

(7)

Transform this into a procedure

eq_function:=unapplyrhseq_fit,x

eq_function:=x→x2+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_predicted:=transformapplyeq_functionXvalues

Yvalues_predicted:=0,6,14,24

(9)

Find the residuals:

Residuals:=transformmultiapplyx,y→xyYvalues,Yvalues_predicted

Residuals:=0,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]


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam