Example2: Linear Regression
Selected case statistics of a simple linear regression model, with an intercept, are computed.
import com.imsl.stat.*;
import com.imsl.math.*;
public class LinearRegressionEx2 {
public static void main(String args[]) {
//
LinearRegression r = new LinearRegression(2, true);
double y[] = {3, 4, 5, 7, 7, 8, 9};
double x[][] = {{1, 1},{1, 2},{1, 3},{1,4},{1,5},{0,6},{1,7}};
double [][] results = new double[7][5];
double [] confint = new double[2];
r.update(x, y);
for (int k=0; k<7; k++){
LinearRegression.CaseStatistics cs = r.getCaseStatistics(x[k],y[k]);
results[k][0] = cs.getJackknifeResidual();
results[k][1] = cs.getCooksDistance();
results[k][2] = cs.getDFFITS();
confint = cs.getConfidenceInterval();
results[k][3] = confint[0];
results[k][4] = confint[1];
}
PrintMatrix p = new PrintMatrix("Selected Case Statistics");
PrintMatrixFormat mf = new PrintMatrixFormat();
String labels[] = {
"Jackknife Residual.","Cook's D","DFFITS",
"[Conf. Interval", "on the Mean]"};
mf.setColumnLabels(labels);
p.print(mf, results);
}
}
Output
Selected Case Statistics
Jackknife Residual. Cook's D DFFITS [Conf. Interval on the Mean]
0 ? 3.201 ? 1.047 2.782
1 ? 3.92 ? 1.239 2.59
2 ? 4.292 ? 1.37 2.459
3 ? 10.393 ? 1.391 2.437
4 ? 17.632 ? 1.292 2.537
5 ? ? ? 0.651 3.178
6 ? 407.199 ? 0.901 2.927
Link to Java source.