Repository navigation
BUG: Estimate regressions with a constant on centered variables - #1033
Merged
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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) * epstimes 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 raisedInfeasibleTestException, andPhillipsPerron.regressionreturned 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_olsestimates OLS with the centering and returns the statsmodels results for the original variables. It sets the attributes thatOLS.fitsets 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 plainOLS(...).fit()._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 inPhillipsPerron.regression, the trend regression of KPSS, and the auxiliary regression ofarch_lm_test.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
regressionestimates 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.regressionandarch_lm_testsay what is centered, and there is a 9.1 bug fix note.Tests.
arch/tests/utility/test_regression.pycomparescentered_olswithOLSfor 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.pychecks that ADF and Phillips-Perron give full-rank regressions for 5.3 plus noise of 1e-12, and thatregressionequalsOLSon the same regressors for ordinary data.🤖 Generated with Claude Code