Results 1 to 7 of 7

Thread: Problem with LinearRegression.CaseStatistics (JMSL 5.0)

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    3

    Question 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[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));        
        }
    }

  2. #2
    Junior Member
    Join Date
    Aug 2005
    Location
    Paris, France
    Posts
    29
    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
    I know now how to add a signature

  3. #3
    Junior Member
    Join Date
    May 2009
    Posts
    3
    Just got a fresh version and the problem still exists. I think I was using JMSL 5.0.1 anyway.

  4. #4
    Senior Member ed's Avatar
    Join Date
    Aug 2005
    Posts
    312
    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?


    The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.

  5. #5
    Junior Member
    Join Date
    May 2009
    Posts
    3
    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.

  6. #6
    Senior Member ed's Avatar
    Join Date
    Aug 2005
    Posts
    312
    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.


    The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.

  7. #7
    Senior Member ed's Avatar
    Join Date
    Aug 2005
    Posts
    312
    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.


    The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.

Posting Permissions

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