Statistics[Fit]  fit a model function to data

Calling Sequence


Fit(f, X, Y, v, options)
Fit(f, XY, v, options)


Parameters


f



algebraic; model function

X



Vector or Matrix; values of independent variable(s)

Y



Vector; values of dependent variable

XY



Matrix; values of independent and dependent variables

v



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

options



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





Description


•

The first parameter f is an algebraic expression in the independent variables and the model parameters .

•

In the first calling sequence, the second 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 . If there is only one independent variable, X can be either a Vector or a kby1 Matrix. The third parameter Y is a Vector containing the k values of the dependent variable y.

•

In the second calling sequence, the second parameter XY is a Matrix containing the values of both the independent and the dependent variables, consisting of k rows and n + 1 columns. The first n columns correspond to X, the final column to Y. That is, the ith row of XY contains first the n values for the ith data point of variables through , then the value of the dependent variable y.

•

The parameters X, Y, and XY can also be specified as lists or Arrays; for details, see the Input Forms help page.

•

The parameter v is a list of the independent variable names used in f. 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.

•

The Fit command returns the model function, with the final parameter values, in terms of the independent variables. 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.

•

The Fit command determines if the model function is linear or nonlinear in the model parameters. (Note that a model function can be nonlinear in the independent variables but linear in the model parameters.) It then calls either Statistics[LinearFit] or Statistics[NonlinearFit]. The most commonly used options are described below. Additional options accepted by LinearFit or NonlinearFit are passed directly to those commands. Note in particular the (recommended) use of the initialvalues option.

•

The Fit command accepts the model function only as an algebraic expression. Different input forms, allowing for greater flexibility and efficiency, are offered by the LinearFit and NonlinearFit commands. For more information, see the Input Forms help page.



Options



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 singularvalue decomposition is performed.

•

weights = Vector  Provide weights for the data points.



Notes


•

The Fit command uses various methods implemented in a builtin library provided by the Numerical Algorithms Group (NAG). The underlying computation is done in floatingpoint; therefore, all data points must have type realcons and all returned solutions are floatingpoint, 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.

•

See infolevel[Statistics] to 1 or higher to see messages about the progress of the solvers. In particular, these userinfo messages indicate whether the LinearFit command or the NonlinearFit command is being used.



Compatibility


•

The XY parameter was introduced in Maple 15.



Examples


>


>


>


Fit a model that is linear in the parameters.
>


 (1) 
Fit a model that is nonlinear in the parameters.
>


 (2) 
Consider now an experiment where quantities , , and are quantities influencing a quantity according to an approximate relationship
with unknown parameters , , and . Six data points are given by the following matrix, with respective columns for , , , and .
>


 (3) 
We take an initial guess that the first term will be approximately quadratic in , that will be approximately , and for we don't even know whether it's going to be positive or negative, so we guess . We compute both the model function and the residuals. Also, we select more verbose operation by setting .
>


>


In NonlinearFit (algebraic form)
 
 (4) 
We note that Maple selected the nonlinear fitting method. Furthermore, the exponent on is only about , and the other guesses were not very good either. However, this problem is conditioned well enough that Maple finds a good fit anyway.
Now suppose that the relationship that is used to model the data is altered as follows:
We adapt the calling sequence very slightly:
>


In Fit
In LinearFit (container form)
 
 (5) 
This time, Maple could select the linear fitting method, because the expression is linear in the parameters. The initial values for the parameters are not used.

