Polynomial Fit - Maple Help

Statistics

 PolynomialFit
 fit a polynomial to data

 Calling Sequence PolynomialFit(d, X, Y, v, options) PolynomialFit(d, XY, v, options)

Parameters

 d - posint; degree of polynomial model function X - Vector; values of independent variable Y - Vector; values of dependent variable XY - Matrix; values of independent and dependent variables v - name; (optional) independent variable name options - (optional) equation(s) of the form option=value where option is one of output, summarize, svdtolerance or weights; specify options for the PolynomialFit command

Description

 • The PolynomialFit command fits a univariate polynomial to data by minimizing the least-squares error.  Consider a model polynomial $p\left(x\right)$ of independent variable $x$ and a dependent variable $y$.  Given k data points, where each point is a pair of numerical values for $\left[x,y\right]$, this command finds coefficients of $p\left(x\right)$ such that the sum of the k residuals squared is minimized.  The ith residual is the value $y-p\left(x\right)$ at the ith data point.
 • The first parameter d is the degree of $p\left(x\right)$.
 • In the first calling sequence, the second parameter X is a Vector containing the k values of the independent variable $x$, and the third parameter Y is a Vector containing the k values of the dependent variable $y$. In the second calling sequence XY is a Matrix with two columns, where the first column corresponds to X and the second column to Y. For X, Y, and XY, one can also use lists or Arrays; for details, see the Input Forms help page.
 • By default, the PolynomialFit command returns a Vector of dimension $d+1$ containing the coefficients of the polynomial resulting in the best fit, ordered from lowest to highest degree.  If the optional parameter v is provided, then a polynomial in this variable name is returned instead.
 • By default, either the least-squares polynomial or a Vector containing the parameter values is returned, depending on the input arguments. 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.

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, rsquared, rsquaredadjusted, standarderrors, tprobability, tvalue, variancecovariancematrix. For more information, see the Statistics/Regression/Solution help page.
 • summarize = identical( true, false, embed ) -- Display a summary of the regression model
 • svdtolerance = realcons(nonnegative) -- Set the tolerance that determines whether a singular-value decomposition is performed.
 • weights = Vector -- Provide weights for the data points.

Notes

 • 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 PolynomialFit 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.

Examples

 > $\mathrm{with}\left(\mathrm{Statistics}\right):$
 > $X≔\mathrm{Vector}\left(\left[1,2,3,4,5,6\right],\mathrm{datatype}=\mathrm{float}\right):$
 > $Y≔\mathrm{Vector}\left(\left[2,3,4,3.5,5.8,7\right],\mathrm{datatype}=\mathrm{float}\right):$
 > $\mathrm{PolynomialFit}\left(2,X,Y\right)$
 $\left[\begin{array}{c}{1.96000000000000}\\ {0.164999999999999}\\ {0.110714285714286}\end{array}\right]$ (1)
 > $\mathrm{PolynomialFit}\left(2,X,Y,v\right)$
 ${1.96000000000000}{+}{0.164999999999999}{}{v}{+}{0.110714285714286}{}{{v}}^{{2}}$ (2)

Use the summarize=true option to return a summary of the regression:

 > $\mathrm{ls}≔\mathrm{PolynomialFit}\left(2,X,Y,v,\mathrm{summarize}=\mathrm{true}\right):$
 Summary: ---------------- Model: 1.9600000+.16500000*v+.11071429*v^2 ---------------- Coefficients:               Estimate  Std. Error  t-value  P(>|t|) Parameter 1    1.9600    1.1720      1.6724   0.1930 Parameter 2    0.1650    0.7667      0.2152   0.8434 Parameter 3    0.1107    0.1072      1.0325   0.3778 ---------------- R-squared: 0.9252, Adjusted R-squared: 0.8753
 > $\mathrm{ls}$
 ${1.96000000000000}{+}{0.164999999999999}{}{v}{+}{0.110714285714286}{}{{v}}^{{2}}$ (3)

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

 > $m≔\mathrm{PolynomialFit}\left(2,X,Y,\mathrm{output}=\mathrm{solutionmodule}\right)$
 ${m}{≔}{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{export}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{Results}}{,}{\mathrm{Settings}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}$ (4)
 > $m:-\mathrm{Results}\left(\right)$
 $\left[{"residualmeansquare"}{=}{0.429238095238095}{,}{"residualsumofsquares"}{=}{1.28771428571429}{,}{"residualstandarddeviation"}{=}{0.655162647926525}{,}{"degreesoffreedom"}{=}{3}{,}{"parametervalues"}{=}\left[\begin{array}{c}{1.96000000000000}\\ {0.164999999999999}\\ {0.110714285714286}\end{array}\right]{,}{"parametervector"}{=}\left[\begin{array}{c}{1.96000000000000}\\ {0.164999999999999}\\ {0.110714285714286}\end{array}\right]{,}{"standarderrors"}{=}\left[\begin{array}{ccc}{1.17199057366598}& {0.766748258006800}& {0.107226158093964}\end{array}\right]{,}{"confidenceintervals"}{=}\left[\begin{array}{c}{-1.76980025750745}{..}{5.68980025750746}\\ {-2.27513724548285}{..}{2.60513724548284}\\ {-0.230527496478056}{..}{0.451956067906628}\end{array}\right]{,}{"rsquared"}{=}{0.925169145624351}{,}{"rsquaredadjusted"}{=}{0.875281909373919}{,}{"residuals"}{=}\left[\begin{array}{cccccc}{-0.235714285714286}& {0.267142857142857}& {0.548571428571429}& {-0.891428571428571}& {0.247142857142857}& {0.0642857142857140}\end{array}\right]{,}{"leverages"}{=}\left[\begin{array}{cccccc}{0.821428571428572}& {0.307142857142857}& {0.371428571428571}& {0.371428571428571}& {0.307142857142857}& {0.821428571428572}\end{array}\right]{,}{"variancecovariancematrix"}{=}\left[\begin{array}{ccc}{1.37356190476190}& {-0.837014285714286}& {0.107309523809524}\\ {-0.837014285714286}& {0.587902891156463}& {-0.0804821428571428}\\ {0.107309523809524}& {-0.0804821428571428}& {0.0114974489795918}\end{array}\right]{,}{"internallystandardizedresiduals"}{=}\left[\begin{array}{c}{-0.851394397843296}\\ {0.489860687557646}\\ {1.05610411939691}\\ {-1.71616919401998}\\ {0.453186625387555}\\ {0.232198472139079}\end{array}\right]{,}{"externallystandardizedresiduals"}{=}\left[\begin{array}{c}{-0.798257317827523}\\ {0.416994351642331}\\ {1.08794530190289}\\ {-10.3712309269066}\\ {0.383380972298048}\\ {0.191316224811661}\end{array}\right]{,}{"CookDstatistic"}{=}\left[\begin{array}{c}{1.11147104504106}\\ {0.0354585230523070}\\ {0.219691315804433}\\ {0.580122380796079}\\ {0.0303479692422574}\\ {0.0826714000443752}\end{array}\right]{,}{"AtkinsonTstatistic"}{=}\left[\begin{array}{c}{-1.71207121030052}\\ {0.277637760733747}\\ {0.836310206125244}\\ {-7.97242863136875}\\ {0.255257737275190}\\ {0.410327588921895}\end{array}\right]{,}{"tvalue"}{=}\left[{1.67236839957606}{,}{0.215194489556356}{,}{1.03253056607013}\right]{,}{"tprobability"}{=}\left[{0.193045057943908}{,}{0.843415034784358}{,}{0.377768512636454}\right]\right]$ (5)

Compatibility

 • The XY parameter was introduced in Maple 15.