# Regression Assumptions, Heteroskedasticity, and Multicollinearity

`D00-F09-A10` · Financial Mathematics, Statistics, and Data Foundations → Dependence, Regression, and Model Foundations · archetype `record-transform` · difficulty 1/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/foundations/dependence-regression-and-model-foundations/regression-assumptions-heteroskedasticity-and-multicollinearity/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

```ts
import { regressionAssumptionsHeteroskedasticityAndMulticollinearity } from "fintech-algorithms/foundations/dependence-regression-and-model-foundations/regression-assumptions-heteroskedasticity-and-multicollinearity";
```

## Signature

```ts
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 | Required | Notes |
| --- | --- | --- | --- |
| `input` | `D00Input` | yes | 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

This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.

### Input

`input`:

```json
{
  "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

```ts
regressionAssumptionsHeteroskedasticityAndMulticollinearity(input)
```

### Returns

object with 2 fields: residualMean, heteroskedasticityProxy

```json
{
  "residualMean": -7.401486830834377e-17,
  "heteroskedasticityProxy": -1.9874588747770088e-16
}
```

## Verification and provenance

Tier: **verified** (via input-expected).

The worked example below is the figure published in this algorithm's article, replayed and asserted by the test suite on every build. The arithmetic cannot drift without the build failing.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.0.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/foundations/dependence-regression-and-model-foundations/regression-assumptions-heteroskedasticity-and-multicollinearity/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/foundations/dependence-regression-and-model-foundations/regression-assumptions-heteroskedasticity-and-multicollinearity/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/foundations/llms.txt
