StatBean Name: NonlinearRegression

Purpose: Fits a non-linear regression model to describe the relationship between Y and one or more numeric predictor variables.

DataSource: any.



Read/Write Properties
NameTypeDescriptionPossible ValuesDefault Value
initialCoefficientdouble[numberOfCoefficients]The initial estimates of the unknown coefficients.Any.null
initialMarquardtParameterdoubleThe initial value of the Marquardt scaling parameter.>0.00.01
maximumFunctionCallsintThe maximum number of points at which the sum of squares function will be evaluated.1+2000
maximumIterationsintThe maximum number of iterations to be performed.1+200
maximumMarquardtParameterdoubleThe maximum value of the Marquardt scaling parameter.>0.0120.0
numberOfCoefficientsintNumber of unknown coefficients in the model.1+0
scalingFactordoubleThe multiple by which to multiply or divide the Marquardt scaling parameter.>0.020.0
stopCriterion1doubleIf successive residual sums of squares differ by less than this proportion, convergence is assumed.>0.00.00001
stopCriterion2doubleIf all successive coefficient estimates differ by less than this proportion, convergence is assumed.>0.00.0001
tablewiseExclusionbooleanWhether all rows of the data table containing a missing value in any column should be excluded from the calculations.true,falsefalse
tolerancedoubleConditioning tolerance for aborting matrix inversion.>0 and <=0.0000010.0000000001
userModelPredictionSTATBEANS.ModelPredictionA routine to return predicted values for given parameter estimates (see sample below).A valid instance.null
weightVariableNameStringThe name of the column (optional) with weights to be applied to the residuals.Any string.""
xVariableNamesString[]The names of the column with data values to be used for the independent (X) variables.Any string.""
yVariableNameStringThe name of the column with data values to be used for the dependent (Y) variable.Any string."Y"

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 getCoefficientPValues(double[numberOfCoefficients])Returns the P-values for the estimated coefficients.Double output array.None.
void getCoefficients(double[numberOfCoefficients])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[3])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.
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.Values 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.Values 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.
int getNumberOfIterations()Returns the number of main iterations.None.Count.
int getNumberOfFunctionCalls()Returns the number of times the residual sum of squares was computed.None.Count.
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's 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.
double getStandardErrorCoefficient(int k)Returns the standard errors of the k-th coefficient.Index.Standard error.
void getStandardErrors(double[numberOfCoefficients])Returns the coefficient standard errors.Double output array.None.
int getSuccessCode()Returns a code indicating why computation ceased.None.0 for successful convergence, 1 if noninvertibility encountered, 4 if maximum value of Marquardt parameter exceeded, 7 if maximum iterations exceeded, 8 if maximum function calls exceeded.
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[3])Returns the following sums of squares: total, model, residual.Double output array.None.
double getUpperConfidenceLimit(double x[],double conflevel)Returns the upper confidence limit for the mean value of Y.Values 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.Values 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\\chlorine.txt");

//create a calculation bean
NonlinearRegression nonlinearRegression1 = new STATBEANS.NonlinearRegression();

//create a table bean
MultipleRegressionTable multipleRegressionTable1 = new STATBEANS.MultipleRegressionTable();
multipleRegressionTable1.setBackground(Color.yellow);
multipleRegressionTable1.setBounds(10,30,520,200);
multipleRegressionTable1.setNumberOfRowsInDisplay(14);
multipleRegressionTable1.setScaleRowsToFit(false);

//create a scatter plot bean
XYPlot plot1 = new STATBEANS.XYPlot();
plot1.setBounds(10,230,520,250);
plot1.setBackground(Color.yellow);
plot1.setXVariableName("weeks");
plot1.setYVariableName("chlorine");

//set the column names
nonlinearRegression1.setYVariableName("chlorine");
String[] tempString = new String[1];
tempString[0] = "weeks";
nonlinearRegression1.setXVariableNames(tempString);

//set the initial coefficient estimates
nonlinearRegression1.setNumberOfCoefficients(2);
double initial[]=new double[2];
initial[0]=0.1;
initial[1]=0.1;
nonlinearRegression1.setInitialCoefficient(initial);

//set function to return predictions
UserModelPrediction m_p=new UserModelPrediction();
nonlinearRegression1.setUserModelPrediction(m_p);

//add the table and plots to the application frame
add(multipleRegressionTable1);
add(plot1);

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

//make the table and plot beans listeners for changes in the calculation bean
nonlinearRegression1.addDataChangeListener(multipleRegressionTable1.listenerForDataChange);
nonlinearRegression1.addDataChangeListener(plot1.listenerForDataChange);

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

//generate predictions for each row of the file
int n=fileDataSource1.getNumberOfRows();
double x[]=new double[1];
double pred[]=new double[n];
double coeff[]=new double[2];
nonlinearRegression1.getCoefficients(coeff);
for(int i=0; i<n; i++)
{
x[0]=fileDataSource1.getDoubleValue(i,0);
pred[i]=m_p.getModelPrediction(x,coeff,0);
}

//save the predicted values in a temporary variable
fileDataSource1.setTempVariable(0,"Predicted",pred,n,'N');

//add the temporary variable to the plot
plot1.setY2VariableName("Predicted");
plot1.repaint();



You must also supply a class file which extends STATBEANS.ModelPrediction such as that shown below. The function must return the value of Y for the model to be fit, where x is an array containing the values of the independent variables for any selected case, coeff is an array with values of the unknown coefficients, and opt is a flag which you can use for any purpose (will be called with opt=0).

public class UserModelPrediction extends STATBEANS.ModelPrediction
{
public double getModelPrediction(double x[],double coeff[],int opt)
{
//for fitting y=a+(0.49-a)exp(-b(x-8))

//return the predicted value at x
return coeff[0]+(0.49-coeff[0])*Math.exp(-coeff[1]*(x[0]-8));
}
}