Performs Least Squares Polynomial fitting with error statistics.
PFIT(series, order, mode, form)
(coef, R2, Se, res) = PFIT(series, order, mode, form)
series 
 
An input series 

order 
 
An integer, the polynomial order. 

mode 
 
Optional. An integer, the error statistics flag:


form 
 
Optional. An integer, form of the polynomial coefficients:

A series or table.
(coef, R2, Se, res) = pfit(series, order, mode, form) returns the polynomial coefficients, residual squared, standard error and residual in separate variables.
W1: gsin(100, 0.01, 0.8)
W2: pfit(W1, 2)
W3: polygraph(col(W2,1),xvals(W1));overplot(W1,lred)
W2 contains the table:
Coeff R^{2} Se
0.349702 0.896020 0.232544
2.744303
4.769116
W3 contains the fitted result with an overplot of the original data.
W4: pfit(W1, 4)
W4 contains the table:
Coeff R^{2} Se
0.044900 0.999201 0.020604
6.293248
6.989869
12.180623
12.057509
The increase in R^{2} and the corresponding decrease in Se indicates the 4th order fit performs better in the least squares sense than the previous 2nd order fit.
pfit(series, N) performs a least squares fit of a series to
where y is the input series and N is the order of the fit.
PFIT returns the coefficients, a[k], of the above power series.
If form is 1 then:
R^{2}, sometimes called the Coefficient of Determination, is an indication of how the fit accounts for the variability of the data. R^{2} can be thought of as:
An R^{2} of 1 indicates the model accounts for ALL the variability of the data. An R^{2} of 0 indicates no data variability is accounted for by the model.
The Standard Error of Estimate, Se, can be thought of as a normalized standard deviation of the residuals, or prediction errors. Given:
The residual or error between sample point i and fitted point i is:
The Standard Error of Estimate is defined as:
where L is the series length and N is the degree of the fitting polynomial. As the model fits the data better, Se approaches 0.
See LINFIT to fit linear combination of arbitrary basis functions to a series using the method of least squares with QR decomposition.