Documentation

Multilinear Regression

@statili/stats ·v0.0.2-beta.0 ·1 export

signatures
multilinear(arg1: Partial<RegressionOptions>): (args_0: MultiDataPoint[]) => MultiRegressionResult
multilinear(suppliedOptions: Partial<RegressionOptions>, data: MultiDataPoint[]): MultiRegressionResult
Performs Multiple Linear Regression (MLR) to model the relationship: y = b₀ + b₁x₁ + b₂x₂ + … + bₖxₖ
Coefficients are found by solving the normal equations: (Xᵀ X) β = Xᵀ y via Gaussian elimination with partial pivoting.

Parameters

NameTypeDescription
suppliedOptions Partial<RegressionOptions> Optional { precision } overrides.
data MultiDataPoint[] Array of { x: number[], y: number | null } observations. All observations must share the same feature dimension (x.length). Observations with y === null are excluded from the fit.

Returns

MultiRegressionResult

Discriminant union:

  • ok: true — includes coefficients ([b₀, b₁, …, bₖ]), r2, rmse, n, numFeatures, equation, predict.
  • ok: false — includes errorType and message.
insight
  • Model fitr2 quantifies the proportion of variance explained across all features.
  • Prediction accuracyrmse in Y-axis units.
  • Feature direction — positive bᵢ means feature i increases Y; negative decreases Y.
  • Relative importance — larger absolute coefficient → greater marginal effect on Y (only comparable when features are on the same scale).
  • Multicollinearity warning — a NumericalStability error often indicates that two or more features are highly correlated.

Examples

Predict house price from square footage and bedrooms
const data: MultiDataPoint[] = [
  { x: [850,  2], y: 210000 },
  { x: [1200, 3], y: 290000 },
  { x: [1500, 3], y: 340000 },
  { x: [1800, 4], y: 420000 },
  { x: [2100, 4], y: 480000 },
];
const result = multilinear({}, data);
if (result.ok) {
  console.log(result.equation);
  // "y = -12500 + 220x₁ + 15000x₂"
  console.log(result.predict([1600, 3]).y);
  // predicted price for 1600 sqft, 3 bedrooms
}
// Curried / partial application (data-last)
const fitMLR = multilinear({ precision: 4 });
const result = fitMLR(data);