mrhee

05-25-2009, 03:57 PM

I'm having problems with the LinearRegression.CaseStatistics class. If I try to call getPredictedResponse() or getResidual(), the returned values don't make sense. As far as I can tell, it just seems to return the intercept term and ignore the explanatory variables.

Here's a slightly modified example that demonstates.

import com.imsl.math.PrintMatrix;

import com.imsl.math.PrintMatrixFormat;

import com.imsl.stat.LinearRegression;

import java.util.Arrays;

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[] coefs = new double[3];

double[][] results = new double[7][8];

double[] confint = new double[2];

r.update(x, y);

coefs = r.getCoefficients();

for (int k = 0; k < 7; k++) {

LinearRegression.CaseStatistics cs = r.getCaseStatistics(x[k], y[k]);

confint = cs.getConfidenceInterval();

results[k][0] = cs.getObservedResponse();

results[k][1] = cs.getPredictedResponse();

results[k][2] = cs.getResidual();

results[k][3] = cs.getJackknifeResidual();

results[k][4] = cs.getCooksDistance();

results[k][5] = cs.getDFFITS();

results[k][6] = confint[0];

results[k][7] = confint[1];

}

PrintMatrix p = new PrintMatrix("Selected Case Statistics");

PrintMatrixFormat mf = new PrintMatrixFormat();

String labels[] = {

"Observed", "Predicted", "Residual", "Jackknife Residual.", "Cook's D", "DFFITS",

"[Conf. Interval", "on the Mean]"};

mf.setColumnLabels(labels);

p.print(mf, results);

System.out.println("Coefficient estimates: " + Arrays.toString(coefs));

}

}

Here's a slightly modified example that demonstates.

import com.imsl.math.PrintMatrix;

import com.imsl.math.PrintMatrixFormat;

import com.imsl.stat.LinearRegression;

import java.util.Arrays;

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[] coefs = new double[3];

double[][] results = new double[7][8];

double[] confint = new double[2];

r.update(x, y);

coefs = r.getCoefficients();

for (int k = 0; k < 7; k++) {

LinearRegression.CaseStatistics cs = r.getCaseStatistics(x[k], y[k]);

confint = cs.getConfidenceInterval();

results[k][0] = cs.getObservedResponse();

results[k][1] = cs.getPredictedResponse();

results[k][2] = cs.getResidual();

results[k][3] = cs.getJackknifeResidual();

results[k][4] = cs.getCooksDistance();

results[k][5] = cs.getDFFITS();

results[k][6] = confint[0];

results[k][7] = confint[1];

}

PrintMatrix p = new PrintMatrix("Selected Case Statistics");

PrintMatrixFormat mf = new PrintMatrixFormat();

String labels[] = {

"Observed", "Predicted", "Residual", "Jackknife Residual.", "Cook's D", "DFFITS",

"[Conf. Interval", "on the Mean]"};

mf.setColumnLabels(labels);

p.print(mf, results);

System.out.println("Coefficient estimates: " + Arrays.toString(coefs));

}

}