Stats Regression ordinaryleastsquares - CyrilB1531/lodestar GitHub Wiki

Home โ€บ Stats-Regression โ€บ Ordinary least squares

OrdinaryLeastSquares

Ordinary least squares with the inference table on top of it, at statsmodels.api.OLS parity.

public static class OrdinaryLeastSquares

Example โ€” fit a line, and read how sure the fit is of its slope.

using Lodestar.Stats.Regression;

double[] design = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0];
double[] response = [2.1, 3.9, 6.2, 7.8, 10.1, 12.2, 13.8, 16.1];

OlsSummary summary = OrdinaryLeastSquares.Fit(design, response, featureCount: 1);

double slope = summary.Coefficients[1];        // => 1.9976190476190496
double error = summary.StandardErrors[1];      // => 0.027800444266884012
double significance = summary.PValues[1];      // => 4.888933612554946E-10

Remarks โ€” the estimate is the cheap half. 1.9976 on its own says nothing about whether the slope is real; the standard error beside it, and the p-value read from it, are what the word inference means and what no maintained .NET library publishes โ€” see the namespace page for the reading that establishes that.

Solved through the normal equations when an upper bound on the condition number of the design, its columns scaled to unit norm, stays within 200 โ€” the cheap route, one pass over the rows โ€” and through Householder reflections of the design otherwise. Forming Xแต€X squares its condition number, which the near-collinear designs a VIF exists to report cannot afford. statsmodels solves through a pseudo-inverse; the two agree inside the corpus's 1e-9.

Applies to โ€” net10.0, netstandard2.0.

See also โ€” OlsSummary, OlsOptions, the ordinary least squares index.

Members

Member What it does
OrdinaryLeastSquares.Fit Fits a linear model and reports what a summary table holds.
OrdinaryLeastSquares.Estimate Fits a linear model and reports the estimates and their standard errors, without the inference table.