Skip to content

BUG: Estimate regressions with a constant on centered variables - #1033

Merged
bashtage merged 2 commits into
mainfrom
wip-centre-ols
Nov 18, 2026
Merged

bashtage merged 2 commits into
mainfrom
wip-centre-ols

Conversation

@bashtage

Copy link
Copy Markdown
Owner

Follow-up to #1032.

When a regression has a constant, arch now estimates it with the dependent variable and the other regressors centered on their means, and reports the results for the original variables. Centering only changes the parametrization: the residuals and the coefficients of the non-constant regressors, and their covariance, are unchanged, and only the constant becomes the intercept at the means. It is transformed back before the results are returned, so the constant and its covariance are those of the original regression too.

Why. statsmodels main (#10714) treats a singular value of the design as zero when it is at most max(nobs, ncols) * eps times the largest. The lagged level of a series that varies little around its level is nearly a multiple of the constant, so this collinearity comes from the parametrization and not from the data. For 5.3 plus noise of 1e-12, ADF raised InfeasibleTestException, and PhillipsPerron.regression returned minimum-norm estimates (slope 0.966 and constant 0.18, instead of -0.0328 and 5.47). At 25,000 observations even noise of 1e-10 made ADF raise.

What changes.

  • arch.utility._regression.centered_ols estimates OLS with the centering and returns the statsmodels results for the original variables. It sets the attributes that OLS.fit sets on the model (rank, pinv_wexog, normalized_cov_params, wexog_singular_values), so robust covariances, the summary and the condition number are those of the original regression. Without a constant, with more than one, or with nothing else, it is plain OLS(...).fit().
  • It is used in _fit_ols, which estimates the regressions of ADF, the statistic of Phillips-Perron, the cointegrating regressions of Engle-Granger, Phillips-Ouliaris, FM-OLS and CCR (first stage), and Dynamic OLS. It is also used in PhillipsPerron.regression, the trend regression of KPSS, and the auxiliary regression of arch_lm_test.
  • Unchanged: the Dickey-Fuller regression of DF-GLS has no constant, so it is estimated as before. Zivot-Andrews solves its own normal equations and does not call statsmodels OLS. The lag selection of ADF and DF-GLS uses its own QR factorization.

Results users see do not change. On ordinary data, main and this branch agree to a relative 2.8e-10 at most over 30 result sets: the statistics and p-values of ADF, Phillips-Perron and KPSS, their regression estimates and standard errors, the cointegrating vectors of Engle-Granger and Phillips-Ouliaris, the estimates and covariances of Dynamic OLS, FM-OLS and CCR, and the ARCH-LM test. The largest difference is Dynamic OLS with a quadratic trend. The same holds with statsmodels main.

Docs. A new section of the unit root introduction, "Regressions with a Constant", explains the centering and why it is done. The cointegration page refers to it. ADF.regression, PhillipsPerron.regression and arch_lm_test say what is centered, and there is a 9.1 bug fix note.

Tests.

  • arch/tests/utility/test_regression.py compares centered_ols with OLS for trends n, c, ct and ctt and for nonrobust, HC0 and HAC covariances: coefficients, standard errors, covariance, residuals, R-squared, F, the log-likelihood, the condition number and the degrees of freedom. It also tests the near-collinear case.
  • test_degenerate_data.py checks that ADF and Phillips-Perron give full-rank regressions for 5.3 plus noise of 1e-12, and that regression equals OLS on the same regressors for ordinary data.
  • The whole suite passes with statsmodels before #10714 and with the Python files of statsmodels main. ruff, black and mypy (same 9 errors as main) are clean, and the docs build.

🤖 Generated with Claude Code

statsmodels main treats a singular value of the design as zero when it is at
most max(nobs, ncols) * eps times the largest. The lagged level of a series
that varies little around its level is nearly a multiple of the constant, so
for 5.3 plus noise of 1e-12 ADF raised InfeasibleTestException and the
regression of PhillipsPerron returned minimum-norm estimates.

centered_ols in arch.utility._regression estimates OLS with the dependent
variable and the regressors other than the constant centered on their means,
when there is one constant column and other columns, and returns the results
for the original variables: the coefficients and their covariance are
transformed back, and the attributes that OLS.fit sets on the model are set
for the original regressors. The test statistics, the estimates, including the
constant, and their covariance only change by rounding error. It is used by
_fit_ols (ADF, Phillips-Perron, the cointegrating regressions and Dynamic
OLS), by PhillipsPerron.regression, by the trend regression of KPSS and by the
auxiliary regression of arch_lm_test.

The unit root introduction explains the centering in a new section, the
cointegration page, the regression properties and arch_lm_test refer to it,
and the 9.1 notes have an entry.
@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.50%. Comparing base (3717e14) to head (acd469d).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #1033    +/-   ##
========================================
  Coverage   99.49%   99.50%            
========================================
  Files         152      154     +2     
  Lines       34682    34802   +120     
  Branches     2629     2635     +6     
========================================
+ Hits        34508    34628   +120     
  Misses         98       98            
  Partials       76       76            
Flag Coverage Δ
adder 99.44% <100.00%> (+<0.01%) ⬆️
subtractor 99.44% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bashtage
bashtage merged commit 3a7611a into main Nov 18, 2026
28 checks passed
@bashtage
bashtage deleted the wip-centre-ols branch November 18, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant