Stats Regression olsoptions - CyrilB1531/lodestar GitHub Wiki
Home โบ Stats-Regression โบ Ordinary least squares
OlsOptions
What an ordinary least-squares fit should estimate, and at what confidence.
public sealed record OlsOptions
Properties โ WithIntercept fits a constant term, as statsmodels.api.add_constant would;
true by default. ConfidenceLevel is the level of the reported intervals; 0.95 by default, and
it must lie strictly inside (0, 1). CovarianceType chooses how the
covariance of the estimates is estimated; Nonrobust by default, and anything else also moves the
coefficient tests from Student's t to the normal. HacLags is the lag count CovarianceType.Hac
reads, statsmodels' maxlags: required with it, refused with any other type, zero or more, and
accepted past the row count as the reference accepts it. SmallSampleCorrection switches the
correction of Hac (n / (n - k), off when null) or Cluster (G / (G - 1) ยท (n - 1) / (n - k),
on when null), statsmodels' use_correction; refused with any other type.
Exceptions โ ArgumentOutOfRangeException when ConfidenceLevel does not lie strictly inside
(0, 1), when HacLags is negative, or when CovarianceType is not a declared CovarianceType.
Each is thrown where the setting is set, not where the fit reads it: an undeclared covariance type
would otherwise be computed as Hc0 and echoed back as the undeclared value.
Example โ a wider level widens both ends without moving the estimate.
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 ninetyFive = OrdinaryLeastSquares.Fit(design, response, featureCount: 1);
OlsSummary ninetyNine = OrdinaryLeastSquares.Fit(
design, response, featureCount: 1, new OlsOptions { ConfidenceLevel = 0.99 });
double narrow = ninetyFive.ConfidenceLower[1]; // => 1.929593811075316
double wide = ninetyNine.ConfidenceLower[1]; // => 1.894550901538726
Remarks โ turning the intercept off does more than drop a coefficient.
OlsSummary.RSquared becomes the uncentred one, measured against zero rather than
against the response's mean, and the overall F test gains a degree of freedom. Both follow
statsmodels. On the data above, the centred R-squared is 0.9988 and the uncentred one 0.9998: the
second is larger not because the model is better but because it is being scored against a lower
bar.
Applies to โ net10.0, netstandard2.0.
See also โ OrdinaryLeastSquares.Fit,
OlsSummary, CovarianceType.