使用 Math.NET 计算多元回归残差

Calculate Multiple Regression Residuals with Math.NET

如何计算多元回归的残差?

double[] y = {56, 65, 34, 65, 75, ...};

double[][] x = {
  new[] {48, 25, 4.6, ...},
  new[] {45, 34, 2.1, ...},
  ...
};

DenseMatrix X = DenseMatrix.OfRowArrays(x);
DenseVector Y = DenseVector.OfArray(y);
Vector<double> R = MultipleRegression.NormalEquations(X, Y);
    Vector<double> R = MultipleRegression.NormalEquations(X, Y);

    //Calculate estimates
    Vector<double> E = X * R;

    // Calculate residuals
    Vector<double> Res = Y - E;