StatBean Name: PolynomialRegression

Purpose: Fits a polynomial model to describe the relationship between two numeric variables.

DataSource: any.

Read/Write Properties
NameTypeDescriptionPossible ValuesDefault Value
xVariableNameStringThe name of the column with data values to be used for the independent (X) variable.Any string."X"
yVariableNameStringThe name of the column with data values to be used for the dependent (Y) variable.Any string."Y"
tablewiseExclusionbooleanWhether all rows of the data table containing a missing value in any column should be excluded from the calculations.true,falsefalse
modelOrderintOrder of the polynomial to be fit.2-82
includeLackOfFitbooleanWhether to divide the residual sum of squares into lack-of-fit and pure error components.true,falsefalse
selectionMethodStringSelection method for polynomial terms."All",
"Forward,"
"Backward"
"All"
pToEnterdoubleP value to enter coefficient into model.0.000001-0.9999990.05
pToRemovedoubleP value to remove coefficient into model.0.000001-0.999999,
>= pToEnter
0.05

Other Public Methods
NameDescriptionArgumentsReturn Value
double getAdjustedRSquared()Returns the adjusted coefficient of determination.None.Adjusted R-squared, or missingValueCode if model cannot be fit.
void getCoefficients(double[1+modelOrder])Returns the estimated coefficients.Double output array.None.
void getCooksDistance(double c[n])Returns Cook's distance corresponding to each row in the datasource.Double output array.None.
void getDegreesOfFreedom(int df[5])Returns the degrees of freedom corresponding to the sums of squares.Double output array.None.
void getDFFITS(double d[n])Returns the DFFITS statistic corresponding to each row in the datasource.Double output array.None.
double getDurbinWatson()Returns the Durbin-Watson statistic.None.DW, or missingValueCode if model cannot be fit.
int getFittedModelOrder()Returns the order of the fitted model.None.Model order.
double getLackOfFitPValue()Returns the P-value for lack-of-fit test.None.P-value.
double getLastPValue()Returns the P-value of the highest order term.None.P-value.
void getLeverages(double h[n])Returns the leverage corresponding to each row in the datasource.Double output array.None.
double getLowerConfidenceLimit(double x,double conflevel)Returns the lower confidence limit for the mean value of Y.Value of X at which to make prediction, and the percentage confidence.Lower limit.
double getLowerPredictionLimit(double x,double meansize,double conflevel)Returns the lower prediction limit for a new value of Y.Value of X at which to make prediction,number of observations at X, and the percentage confidence.Lower limit.
void getMahalanobisDistance(double c[n])Returns the Mahalanobis distance corresponding to each row in the datasource.Double output array.None.
double getMeanAbsoluteError()Returns the residual mean absolute error.None.MAE, or missingValueCode if model cannot be fit.
double getMeanSquaredError()Returns the residual mean squared error.None.MSE, or missingValueCode if model cannot be fit.
double getModelPValue()Returns the P-value for the fitted model.None.P-value.
void getPredictedValues(double p[n])Returns the predicted value of Y corresponding to each row in the datasource.Double output array.None.
double getPrediction(double x)Returns the predicted value of Y.Value of X at which to make prediction.Predicted value.
double getResidualDegreesOfFreedom()Returns the d.f. for the error term used to estimate the standard errors.None.Residual df, or 0 if model cannot be fit.
void getResiduals(double r[n])Returns the residual corresponding to each row in the datasource.Double output array.Residual or missingValueCode.
double getResidualStandardError()Returns the estimated standard deviation of the residuals.None.Standard error of the estimate, or missingValueCode if model cannot be fit.
double getRSquared()Returns the coefficient of determination.None.R-squared, or missingValueCode if model cannot be fit.
double getSampleSize()Returns the number of non-missing data values.None.Sample size.
void getStandardErrors(double[1+modelOrder])Returns the coefficient standard errors.Double output array.None.
void getStudentizedResiduals(double s[n])Returns the studentized deleted residual corresponding to each row in the datasource.Double output array.None.
void getSumsOfSquares(double ss[5])Returns the following sums of squares: total, model, residual, lack-of-fit, pure error.Double output array.None.
double getUpperConfidenceLimit(double x,double conflevel)Returns the upper confidence limit for the mean value of Y.Value of X at which to make prediction, and the percentage confidence.Upper limit.
double getUpperPredictionLimit(double x,double meansize,double conflevel)Returns the upper prediction limit for a new value of Y.Value of X at which to make prediction, number of observations at X, and the percentage confidence.Upper limit.

Output Variables
NameDescription
CooksDCook's distance corresponding to each row in the datasource.
DFFITSThe DFFITS statistic corresponding to each row in the datasource.
LeverageThe leverage corresponding to each row in the datasource.
MahalanobisDThe Mahalanobis distance corresponding to each row in the datasource.
PredictedThe predicted value of Y corresponding to each row in the datasource.
ResidualThe residual corresponding to each row in the datasource.
SResidualThe studentized deleted residual corresponding to each row in the datasource.

Other properties are inherited from the general CalculationStatbean class.

Code Sample

//create a datasource bean
FileDataSource fileDataSource1 = new STATBEANS.FileDataSource();

//set the file name to be read
fileDataSource1.setFileName("c:\\statbeans\\samples\\cardata.txt");

//create a calculation bean
PolynomialRegression polynomialRegression1 = new STATBEANS.PolynomialRegression();

//create a table bean
SimpleRegressionTable simpleRegressionTable1 = new STATBEANS.SimpleRegressionTable();

//create a plot bean
SimpleRegressionPlot simpleRegressionPlot1 = new STATBEANS.SimpleRegressionPlot();

//set the columns for the x and y axes
polynomialRegression1.setYVariableName("mpg");
polynomialRegression1.setXVariableName("weight");

//set the order of the polynomial
polynomialRegression1.setModelOrder(2);

//make the calculation bean a listener for changes in the FileDataSource bean
fileDataSource1.addDataChangeListener(polynomialRegression1.listenerForDataChange);

//make the table and plot beans listeners for changes in the calculation bean
polynomialRegression1.addDataChangeListener(simpleRegressionTable1.listenerForDataChange);
polynomialRegression1.addDataChangeListener(simpleRegressionPlot1.listenerForDataChange);

//instruct the fileDataSource bean to read the file
fileDataSource1.readData();