als-statistics
Version:
A powerful and lightweight JavaScript library for descriptive statistics, regression, clustering, outlier detection, and noise analysis using a flexible table/column architecture.
64 lines (47 loc) • 1.05 kB
Markdown
`LinearRegression` performs multiple linear regression on `Table` data.
- Multiple predictors
- Intercept term
- Mediator and moderator support
- Coefficients, p-values, R²
- Interaction terms (X*Z)
### 🔹 Example
```js
const table = Statistics.newTable({
X: [1, 2, 3, 4, 5],
Y: [2, 4, 6, 8, 10]
});
const model = table.linearRegression("Y", ["X"]).calculate();
console.table(model.result);
// Expect Intercept ≈ 0, X Coefficient ≈ 2
```
```js
table.linearRegression("Y", ["X"])
.mediator("M")
.calculate();
```
```js
table.linearRegression("Y", ["X"])
.moderator("Z")
.calculate();
```
```js
model.result
// {
// Variable: ['Intercept', 'X', ...],
// Coefficient: [...],
// StdError: [...],
// pValue: [...]
// }
```
```js
table.linearRegression("Y", ["X"]).htmlTable
```
- Internally uses matrix algebra
- Throws if predictors are constant or if matrix is singular