# Fit a regression

Model / stats

linear, logistic or generalised linear regression as statistics

Page: <https://meridian.online/operations/fit-a-regression>

## Status

Runs as a SQL step.

arcform carries it as a `sql:` step today.

## The DuckDB step

simple linear regression as aggregates

```sql
CREATE TEMP TABLE result AS
WITH pts(x, y) AS (SELECT i, 3.0 * i + 2 FROM range(1, 11) t(i))
SELECT regr_slope(y, x) AS slope, regr_intercept(y, x) AS intercept, regr_r2(y, x) AS r2, regr_count(y, x) AS n FROM pts;
SELECT * FROM result;
SELECT CASE WHEN ((SELECT abs(slope - 3) < 1e-9 AND abs(intercept - 2) < 1e-9 AND abs(r2 - 1) < 1e-9 AND n = 10 FROM result)) THEN 'as expected' ELSE error('a line of slope 3 and intercept 2 was not recovered') END AS verdict;
```

The statement builds its own data.

It needs nothing installed beyond DuckDB itself.

## Variants

- Fit a curve: Fit a polynomial or a user-given function to the data points.
- [Fit a logistic or generalised linear regression](https://meridian.online/operations/fit-a-regression/fit-a-logistic-or-generalised-linear-regression): Fit a regression for a binary, count or skewed target through a link function, such as logistic or Poisson regression.
- Fit a linear regression: Fit a straight-line relationship between a numeric target and one or more predictors.

## What other tools call it

Meridian's classification; an independent blind rating agreed on 86.2% of 312 rows (exact class, version 2).

- Alteryx Designer: [`Count Regression`](https://help.alteryx.com/current/en/designer/tools/predictive/count-regression-tool.html) (read 2026-09-27)
- Alteryx Designer: [`Gamma Regression`](https://help.alteryx.com/current/en/designer/tools/predictive/gamma-regression-tool.html) (read 2026-09-27)
- Alteryx Designer: [`Linear Regression`](https://help.alteryx.com/current/en/designer/tools/predictive/linear-regression-tool.html) (read 2026-09-27)
- Alteryx Designer: [`Logistic Regression`](https://help.alteryx.com/current/en/designer/tools/predictive/logistic-regression-tool.html) (read 2026-09-27)
- Apache DataFusion: [`regr_avgx`](https://datafusion.apache.org/user-guide/sql/aggregate_functions.html) (read 2026-09-27)
- Apache DataFusion: [`regr_avgy`](https://datafusion.apache.org/user-guide/sql/aggregate_functions.html) (read 2026-09-27)
- Apache DataFusion: [`regr_count`](https://datafusion.apache.org/user-guide/sql/aggregate_functions.html) (read 2026-09-27)
- Apache DataFusion: [`regr_intercept`](https://datafusion.apache.org/user-guide/sql/aggregate_functions.html) (read 2026-09-27)
- Apache DataFusion: [`regr_r2`](https://datafusion.apache.org/user-guide/sql/aggregate_functions.html) (read 2026-09-27)
- Apache DataFusion: [`regr_slope`](https://datafusion.apache.org/user-guide/sql/aggregate_functions.html) (read 2026-09-27)
- Apache DataFusion: [`regr_sxx`](https://datafusion.apache.org/user-guide/sql/aggregate_functions.html) (read 2026-09-27)
- Apache DataFusion: [`regr_sxy`](https://datafusion.apache.org/user-guide/sql/aggregate_functions.html) (read 2026-09-27)
- Apache DataFusion: [`regr_syy`](https://datafusion.apache.org/user-guide/sql/aggregate_functions.html) (read 2026-09-27)
- DuckDB: [`regr_avgx`](https://duckdb.org/docs/current/sql/functions/aggregates) (read 2026-09-27)
- DuckDB: [`regr_avgy`](https://duckdb.org/docs/current/sql/functions/aggregates) (read 2026-09-27)
- DuckDB: [`regr_count`](https://duckdb.org/docs/current/sql/functions/aggregates) (read 2026-09-27)
- DuckDB: [`regr_intercept`](https://duckdb.org/docs/current/sql/functions/aggregates) (read 2026-09-27)
- DuckDB: [`regr_r2`](https://duckdb.org/docs/current/sql/functions/aggregates) (read 2026-09-27)
- DuckDB: [`regr_slope`](https://duckdb.org/docs/current/sql/functions/aggregates) (read 2026-09-27)
- DuckDB: [`regr_sxx`](https://duckdb.org/docs/current/sql/functions/aggregates) (read 2026-09-27)
- DuckDB: [`regr_sxy`](https://duckdb.org/docs/current/sql/functions/aggregates) (read 2026-09-27)
- DuckDB: [`regr_syy`](https://duckdb.org/docs/current/sql/functions/aggregates) (read 2026-09-27)
- EasyMorph: [`Linear regression`](https://help.easymorph.com/doku.php?id=transformations:linearregression) (read 2026-09-27)
- KNIME Analytics Platform: [`Linear Regression Learner`](https://api.hub.knime.com/nodes/*eAyyc-wmeLvvI3j1?details=full) (read 2026-09-27)
- KNIME Analytics Platform: [`Logistic Regression Learner`](https://api.hub.knime.com/nodes/*czTL7CtWUSI10JzJ?details=full) (read 2026-09-27)
- KNIME Analytics Platform: [`Polynomial Regression Learner`](https://api.hub.knime.com/nodes/*uD7nYRKs3yCIXp3p?details=full) (read 2026-09-27)
- RapidMiner Studio: [`Function Fitting`](https://docs.rapidminer.com/latest/studio/operators/modeling/predictive/functions/function_fitting.html) (read 2026-09-27)
