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       Infinity        3.200725423    Infinity    1.046660807    2.781910622   
1       Infinity        3.920183908    Infinity    1.23884064     2.589730789   
2       Infinity        4.291527367    Infinity    1.369724486    2.458846943   
3       Infinity        10.392882037   Infinity    1.39108821     2.437483219   
4       Infinity        17.632257563   Infinity    1.291556125    2.537015303   
5       NaN             NaN            NaN         0.650643689    3.17792774    
6       Infinity        407.198896552  Infinity    0.901118103    2.927453326   

Imsl.Stat.LinearRegression: A deleted residual mean square (= -0.467181467181471) much less than zero has been computed. It is being set to zero.
Imsl.Stat.LinearRegression: A deleted residual mean square (= -1.75390476190477) much less than zero has been computed. It is being set to zero.
Imsl.Stat.LinearRegression: A deleted residual mean square (= -3.62155388471179) much less than zero has been computed. It is being set to zero.
Imsl.Stat.LinearRegression: A deleted residual mean square (= -10.1290640394089) much less than zero has been computed. It is being set to zero.
Imsl.Stat.LinearRegression: A deleted residual mean square (= -11.1106918238994) much less than zero has been computed. It is being set to zero.
Imsl.Stat.LinearRegression: A deleted residual mean square (= -46.584) much less than zero has been computed. It is being set to zero.

Link to C# source.