# Thread: Problem with LinearRegression.CaseStatistics (JMSL 5.0)

1. ## Problem with LinearRegression.CaseStatistics (JMSL 5.0)

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.

Code:
```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;
double[][] results = new double;
double[] confint = new double;
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] = cs.getObservedResponse();
results[k] = cs.getPredictedResponse();
results[k] = cs.getResidual();
results[k] = cs.getJackknifeResidual();
results[k] = cs.getCooksDistance();
results[k] = cs.getDFFITS();
results[k] = confint;
results[k] = confint;
}
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));
}
}```  Reply With Quote

2. Hello mrhee,

There are some significant fixes for LinearRegression.CaseStatistics in JMSL 5.0.1. I think this should does the trick. So, I suggest you to contact your local sales representative at VNI to get a CD of this 5.0.1 release. SebGR  Reply With Quote

3. Just got a fresh version and the problem still exists. I think I was using JMSL 5.0.1 anyway.  Reply With Quote

4. As I started looking into this, I notice several warning messages are issued:

com.imsl.stat.LinearRegression: A deleted residual mean square (= -0.467) much less than zero has been computed. It is being set to zero.
com.imsl.stat.LinearRegression: A deleted residual mean square (= -1.754) much less than zero has been computed. It is being set to zero.
com.imsl.stat.LinearRegression: A deleted residual mean square (= -3.622) much less than zero has been computed. It is being set to zero.
com.imsl.stat.LinearRegression: A deleted residual mean square (= -10.129) much less than zero has been computed. It is being set to zero.
com.imsl.stat.LinearRegression: A deleted residual mean square (= -11.111) much less than zero has been computed. It is being set to zero.
com.imsl.stat.LinearRegression: A deleted residual mean square (= -46.584) much less than zero has been computed. It is being set to zero.

I'll leave it to one of our stat guys to comment on the importance of these warnings, but are you seeing these too?  Reply With Quote

5. I see those errors too. I don't think they're consequential. I've set up other regression problems without those errors and get the same predict/residual problems.  Reply With Quote

6. I've dropped this code into the IMSL C Library and am seeing the expected results. We'll need to get someone from the development team to dig into the CaseStatistics class. It's not obvious what's going on in this case since other tests look OK.  Reply With Quote

7. OK, we've uncovered the issue. There used to be a CaseStatistics.setEffects() method. However, the valid values were constrained, so they basically had to be set to specific values -- which means you really don't need a setter method. The problem is that when we deprecated it, its functionality wasn't completely implemented in the main body.

So, in short, the answer for JMSL 5.0 is to make a call to cs.setEffects() setting the value to negative the number of coefficients (here 2). The code change is:

Code:
```LinearRegression.CaseStatistics cs = r.getCaseStatistics(x[k], y[k]);
cs.setEffects(-2);
confint = cs.getConfidenceInterval();```
This will give you results that you're expecting (and that match our C library version). This will be fixed for JMSL 6.0 without the need to call a deprecated method.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•