public class OLSRegression extends Object implements LinearModel
Construction fits the model immediately. Obtain coefficient estimates
using beta().betaHat(); predictor coefficients come first and the
optional intercept comes last. Ey(x) takes just the predictor
values in training-column order, without the appended intercept.
import dev.nm.algebra.linear.matrix.doubles.matrixtype.dense.DenseMatrix;
import dev.nm.algebra.linear.vector.doubles.Vector;
import dev.nm.algebra.linear.vector.doubles.dense.DenseVector;
import dev.nm.stat.regression.linear.LMProblem;
import dev.nm.stat.regression.linear.ols.OLSRegression;
DenseMatrix x = new DenseMatrix(new double[][]{{0}, {1}, {2}, {3}});
DenseVector y = new DenseVector(1.0, 3.0, 5.0, 7.0);
OLSRegression fit = new OLSRegression(new LMProblem(y, x, true));
Vector beta = fit.beta().betaHat(); // slope first, intercept last
assert Math.abs(beta.get(1) - 2.0) < 1e-10;
assert Math.abs(beta.get(2) - 1.0) < 1e-10;
double prediction = fit.Ey(new DenseVector(new double[]{4.0}));
assert Math.abs(prediction - 9.0) < 1e-10;
| Constructor and Description |
|---|
OLSRegression(LMProblem problem)
Constructs an OLSRegression instance.
|
OLSRegression(LMProblem problem,
double epsilon)
Constructs an OLSRegression instance.
|
| Modifier and Type | Method and Description |
|---|---|
OLSBeta |
beta()
Gets \(\hat{\beta}\) and statistics.
|
LMDiagnostics |
diagnostics()
Gets the diagnostic measures of an OLS regression.
|
double |
Ey(Vector x)
Predicts the conditional response for one observation.
|
static double |
Ey(Vector beta,
Vector x,
boolean intercept)
Predicts a response using explicitly supplied coefficients.
|
LMInformationCriteria |
informationCriteria()
Gets the model selection criteria.
|
OLSResiduals |
residuals()
Gets the residual analysis of an OLS regression.
|
public OLSRegression(LMProblem problem, double epsilon)
problem - the linear regression problem to be solvedepsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0public OLSRegression(LMProblem problem)
problem - the linear regression problem to be solvedpublic double Ey(Vector x)
Ey in interface LinearModelx - predictor values in training-column order, excluding the interceptpublic static double Ey(Vector beta, Vector x, boolean intercept)
beta - predictor coefficients, followed by the intercept if enabledx - predictor values, without an intercept entryintercept - whether to append a constant one to xpublic OLSBeta beta()
LinearModelbeta in interface LinearModelpublic OLSResiduals residuals()
LinearModelresiduals in interface LinearModelpublic LMDiagnostics diagnostics()
public LMInformationCriteria informationCriteria()
Copyright © 2010-2026 NM Group. All Rights Reserved.