Snowflake REGR_R2 can return 1 when the outcome never changes
Before calling a regression a perfect fit, check whether the outcome varied at all on the same rows used by the model.
A dashboard asks, “How well does ad spend explain weekly signups?” Snowflake’s REGR_R2(signups, spend) can return 1 even if signups were identical every week. The number is valid under Snowflake’s documented rule, but a summary that says “spend explains all the variation in signups” misses the point: there was no variation in signups to explain.
Two ways to get a 1
Snowflake evaluates the rule on rows where both inputs are non-null. If the predictor (x, spend) has zero variance, REGR_R2 returns NULL. If spend varies but the outcome (y, signups) has zero variance, it returns 1. When both vary, it returns squared correlation. That means both a flat outcome and a genuinely straight-line relationship can produce the same score. The argument order matters: outcome first, predictor second.
Check the variation on the same rows
Use REGR_SXX and REGR_SYY beside REGR_R2. They measure the spread of the predictor and outcome, respectively, as the pair count times the population variance, calculated on the same complete pairs. Separate variances over each column need not use the same rows: a week with spend but missing signups contributes to a spend-only variance but not to the regression.
WITH weekly(campaign, signups, spend) AS (
SELECT * FROM VALUES
('flat', 20, 100), ('flat', 20, 200), ('flat', 20, 300),
('line', 10, 100), ('line', 20, 200), ('line', 30, 300),
('fixed', 10, 100), ('fixed', 20, 100), ('fixed', 30, 100)
)
SELECT campaign,
REGR_R2(signups, spend) AS r_squared,
REGR_SXX(signups, spend) AS spend_spread,
REGR_SYY(signups, spend) AS signup_spread
FROM weekly
GROUP BY campaign
ORDER BY campaign;
Expected from the documented formulas; not run on Snowflake by the desk: flat and line both return an R² of 1, but flat has zero signup spread and line does not. fixed has zero spend spread and returns NULL for R². For a generated dashboard summary, report “signups did not vary on the weeks analyzed” for flat, and “spend did not vary” for fixed. Keep the raw score for inspection, but don’t let it select the explanation on its own.
sources
- Snowflake SQL reference: REGR_R2docs.snowflake.com
- Snowflake SQL reference: REGR_SXXdocs.snowflake.com
- Snowflake SQL reference: REGR_SYYdocs.snowflake.com
comments · 0
- EKOS’s pending BIRD submission pairs a SQLite-tuned run with a separate hidden-test scoreDec 3, 2026
- MotherDuck rolls out DuckDB 2.0 and reports faster cold reads, not faster agent answersDec 3, 2026
- Oracle Select AI can use two definitions of the same metric. Source order won’t break the tieDec 3, 2026