Example: Linear Regression Case Statistics

Selected case statistics of a simple linear regression model, with an intercept, are computed.
using System;
using Imsl.Stat;
using 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);
        double[] xTmp = new double[2];
        for (int k=0; k<7; k++){
            xTmp[0] = x[k,0];
            xTmp[1] = x[k,1];
            LinearRegression.CaseStatistics cs = r.GetCaseStatistics(xTmp,y[k]);
            results[k,0] = cs.JackknifeResidual;
            results[k,1] = cs.CooksDistance;
            results[k,2] = cs.DFFITS;
            confint = cs.ConfidenceInterval;
            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);
      mf.NumberFormat = "0.#########";
        p.Print(mf, results);
    }
}

Output

                             Selected Case Statistics
   Jackknife Residual.   Cook's D       DFFITS     [Conf. Interval  on the Mean]  
0     -0.343038693      0.044885519  -0.323965838    2.260946521    3.996196336   
1     -0.327326835      0.018390805  -0.207019668    3.467412069    4.818302217   
2     -0.337597012      0.011129861  -0.16122517     4.612581629    5.701704085   
3      Infinity         0.275862069   Infinity       5.648231067    6.694626076   
4     -0.417763902      0.023512274  -0.236601469    6.562984697    7.808443875   
5      NaN              NaN           NaN            6.736357974    9.263642026   
6     -0.742307489      0.372413793  -0.995910003    8.201118103    10.227453326  


Link to C# source.