Regression Assumptions, Heteroskedasticity, and Multicollinearity
Install and import#
npm install fintech-algorithmsimport { regressionAssumptionsHeteroskedasticityAndMulticollinearity } from "fintech-algorithms/foundations/dependence-regression-and-model-foundations/regression-assumptions-heteroskedasticity-and-multicollinearity";Signature#
regressionAssumptionsHeteroskedasticityAndMulticollinearity(input)Runs three diagnostics on the least squares fit of input.y on input.x: the mean residual, a correlation between fitted values and absolute residuals standing in for non-constant error variance, and the correlation with input.otherPredictor standing in for collinearity.
Parameters#
| Name | Type | Notes |
|---|---|---|
input | D00Input | One record holding the predictor series x, the outcome series y, and otherPredictor, a second candidate predictor aligned with x.x: non-empty list of finite numbers, at least two, not all identical · y: finite numbers, same length as x · otherPredictor: non-empty list of finite numbers, same length as x, not all identical |
Returns#
D00Output
An object with residualMean, heteroskedasticityProxy (correlation of fitted values with absolute residuals, or 0 when every absolute residual is identical), predictorCorrelation (between x and otherPredictor), vifProxy (one over one minus that correlation squared) and warnings, a list naming heteroskedasticity when its proxy exceeds 0.5 in absolute size and multicollinearity when the predictor correlation exceeds 0.8 in absolute size.
Errors#
- When x or y is missing, empty, or contains a non-finite number — throws RangeError
- When x and y have different lengths, or fewer than two observations — the least-squares fit is computed for every topic in the family before the topic branch is taken — throws RangeError
- When x is constant, which leaves the regression slope undefined — throws RangeError
- When otherPredictor is missing, empty, holds a non-finite number, does not align with x, or is constant — throws RangeError
- When the fitted values are constant, meaning a zero slope, while the absolute residuals still vary, which leaves the heteroskedasticity proxy undefined — throws RangeError
Complexity: time O(n),
space O(n).
Worked example#
verified This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.
Input#
{
"x": [1, 2, 3, 4, 5, 6],
"y": [2, 3, 5, 4, 6, 7],
"groups": ["A", "A", "A", "B", "B", "B"],
"predictX": 7,
"otherPredictor": [2, 4, 5, 8, 9, 13]
}Call#
regressionAssumptionsHeteroskedasticityAndMulticollinearity(input)Returns#
object with 2 fields: residualMean, heteroskedasticityProxy
{
"residualMean": -7.401486830834377e-17,
"heteroskedasticityProxy": -1.9874588747770088e-16
}Diagrams#
How it works#
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References#
- Linear Least Squares Regression — NIST/SEMATECH e-Handbook
- Correlation — NIST/SEMATECH e-Handbook
- Historical-example decision