fit a linear model function to data - Maple Help

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : Statistics : Statistics Package : Regression : Statistics/LinearFit

Statistics[LinearFit] - fit a linear model function to data

Calling Sequence

LinearFit(flst, X, Y, v, options)

LinearFit(flst, XY, v, options)

LinearFit(falg, X, Y, v, options)

LinearFit(falg, XY, v, options)

LinearFit(fop, X, Y, options)

LinearFit(fop, XY, options)




list(algebraic) or Vector(algebraic); component functions in algebraic form



Vector or Matrix; values of independent variable(s)



Vector; values of dependent variable



Matrix; values of independent and dependent variables



name or list(names); name(s) of independent variables in the component functions



algebraic expression, linear in all its variables except the ones in v; model



list(procedure) or Vector(procedure); component functions in operator form



(optional) equation(s) of the form option=value where option is one of output, svdtolerance or weights; specify options for the LinearFit command



The LinearFit command fits a model function that is linear in the model parameters to data by minimizing the least-squares error.  It performs both simple and multiple linear regression.  This command accepts the model function in algebraic form in two variants, and in operator form, and data for independent and dependent variables can be specified together or separately.  For more information about the input forms, see the Input Forms help page.


Consider the model y=fx1,x2,...,xn where y is the dependent variable and f is the model function of n independent variables x1,x2,...,xn.  This function is a linear combination a1f1+a2f2+amfm+... of component functions fjx1,x2,...,xn, for j from 1 to n.  Given k data points, where each data point is an (n+1)-tuple of numerical values for x1,x2,...,xn,y, the LinearFit command finds values of model parameters a1,a2,...,am such that the sum of the k residuals squared is minimized.  The ith residual is the value of yfx1,x2,...,xn evaluated at the ith data point.


In the first two calling sequences, the first parameter flst is a list or Vector of component functions in algebraic form.  Each component is an algebraic expression in the independent variables x1,x2,...,xn.


In the second pair of calling sequences, the first parameter is an algebraic expression for fx1,x2,...,xn, including the parameters a1,a2,...,am.


In the last two calling sequences, the first parameter fop is a list or Vector of component functions in operator form. The jth component is a procedure having n input parameters representing the independent variables x1,x2,...,xn and returning the single value fjx1,x2,...,xn.


The parameter X is a Matrix containing the values of the independent variables.  Row i in the Matrix contains the n values for the ith data point while column j contains all values of the single variable xj.  If there is only one independent variable, X can be either a Vector or a k-by-1 Matrix.  The parameter Y is a Vector containing the k values of the dependent variable y. The parameter XY is a Matrix consisting of the n columns of X and, as last column, Y. For X, Y, and XY, one can also use lists or Arrays; for details, see the Input Forms help page.


The parameter v is a list of the independent variable names used in falg.  If there is only one independent variable, then v can be a single name.  The order of the names in the list must match exactly the order in which the independent variable values are placed in the columns of X.


By default, either the model function with the final parameter values or a Vector containing the parameter values is returned, depending on the input form.  Additional results or a solution module that allows you to query for various settings and results can be obtained with the output option.  For more information, see the Statistics/Regression/Solution help page.


Weights for the data points can be supplied through the weights option.



The options argument can contain one or more of the options shown below.  These options are described in more detail on the Statistics/Regression/Options help page.


output = name or string -- Specify the form of the solution.  The output option can take as a value the name solutionmodule, or one of the following names (or a list of these names): AtkinsonTstatistic, confidenceintervals, CookDstatistic, degreesoffreedom, externallystandardizedresiduals, internallystandardizedresiduals, leastsquaresfunction, leverages, parametervalues, parametervector, residuals, residualmeansquare, residualstandarddeviation, residualsumofsquares, standarderrors, variancecovariancematrix. For more information, see the Statistics/Regression/Solution help page.


svdtolerance = realcons(nonnegative) -- Set the tolerance that determines whether a singular-value decomposition is performed.


weights = Vector -- Provide weights for the data points.



The underlying computation is done in floating-point; therefore, all data points must have type realcons and all returned solutions are floating-point, even if the problem is specified with exact values.  For more information about numeric computation in the Statistics package, see the Statistics/Computation help page.


The LinearFit command uses various methods implemented in a built-in library provided by the Numerical Algorithms Group (NAG).  Normally, a method using QR decomposition is applied.  If it is determined that the system does not have full rank, then a singular-value decomposition (SVD) is performed. The svdtolerance option allows you to specify when an SVD should be performed.  See the Statistics/Regression/Options help page for additional details.


To obtain more details as the least-squares problem is being solved, set infolevel[Statistics] to 1 or higher.



A simple example using the first form for the first argument, flst:






Here is the same example using the second form for the first argument, falg:




And finally using the third form, fop:













Use the output=solutionmodule option to see the full results.


m:=moduleexportResults,Settings;end module





Consider now an experiment where quantities x, y, and z are quantities influencing a quantity w according to an approximate relationship


with unknown parameters a, b, and c. Six data points are given by the following matrix, with respective columns for x, y, z, and w.




We can find the fitted model function as follows:




Alternatively, if we have the input and output data separately, we can use the following calling sequence.










We might want to know the residuals and the parameter values instead of just the model function.




See Also

CurveFitting, Statistics, Statistics/Computation, Statistics/Fit, Statistics/Regression, Statistics/Regression/InputForms, Statistics/Regression/Options, Statistics/Regression/Solution

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