import javastat.regression.lm.LinearRegression;
/**
*
* <p>Example: class LinearRegression.</p>
* <p>Data Source: Anderson, D. R.,
Sweeney, D. J. and Williams, T. A. (2001).
* Contemporary Business
Statistics with Microsoft Excel.
* South-Western, p. 468,
p.530.
</p>
*/
double[] pizzaResponse = {58, 105, 88, 118, 117,
137, 157, 169, 149,
202};
double[][] pizzaCovariate = { {2, 6, 8, 8, 12,
16, 20, 20, 22, 26} };
double[] hellerResponse = {102, 100, 120, 77, 46,
93, 26, 69, 65, 85};
double[][] hellerCovariate = { {120, 140, 190,
130, 155, 175, 125, 145, 180,
150},
{100, 110, 90, 150, 210, 150, 250, 270, 300,
250} };
myClass1
= new LinearRegression(pizzaResponse, pizzaCovariate);
coefficients = myClass1.coefficients;
fittedValues = myClass1.fittedValues;
residuals = myClass1.residuals;
testStatistic = myClass1.testStatistic;
pValue = myClass1.pValue;
confidenceInterval =
myClass1.confidenceInterval;
rSquare = myClass1.rSquare;
testFStatistic =
myClass1.testFStatistic;
fPValue = myClass1.fPValue;
print("The estimated coefficients (non-null constructor)
= [" +
coefficients[0]
+ " , " + coefficients[1] + "]");
print("The t statistics (non-null constructor)
= [" +
testStatistic[0] + " ,
" + testStatistic[1] + "]");
myClass2
= new LinearRegression();
coefficients = myClass2.coefficients(hellerResponse, hellerCovariate);
confidenceInterval = myClass2.confidenceInterval(0.05,
hellerResponse,
hellerCovariate);
testStatistic = myClass2.testStatistic(hellerResponse, hellerCovariate);
pValue = myClass2.pValue(hellerResponse,
hellerCovariate);
testFStatistic = myClass2.testFStatistic(hellerResponse, hellerCovariate);
fPValue = myClass2.fPValue(hellerResponse,
hellerCovariate);
print("The f statistic (null constructor)
= " +
testFStatistic);
print("The p-value for the f statistic (null constructor)
= " +
fPValue);
Results:
The estimated
coefficients based on non-null constructor = [60.0 , 5.0]
The t statistics
based on non-null constructor
= [6.503 ,
8.617]
The f statistic
based on null constructor
= 6.579
The p-value for
the f statistic based on null constructor
= 0.025