Multilinear Regression
# multilinear function
packages/stats/src/regression/multilinear.ts:59multilinear(arg1: Partial<RegressionOptions>): (args_0: MultiDataPoint[]) => MultiRegressionResult
multilinear(suppliedOptions: Partial<RegressionOptions>, data: MultiDataPoint[]): MultiRegressionResultPerforms 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
| Name | Type | Description |
|---|---|---|
| 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
MultiRegressionResultDiscriminant union:
ok: true— includescoefficients([b₀, b₁, …, bₖ]),r2,rmse,n,numFeatures,equation,predict.ok: false— includeserrorTypeandmessage.
insight
- Model fit —
r2quantifies the proportion of variance explained across all features. - Prediction accuracy —
rmsein 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
NumericalStabilityerror often indicates that two or more features are highly correlated.
Examples
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);