Repository navigation
BUG: Require residual degrees of freedom in FamaMacBethCovariance - #883
Cyber-Marty wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #883 +/- ##
=======================================
Coverage 99.69% 99.69%
=======================================
Files 202 202
Lines 38871 38921 +50
Branches 2501 2502 +1
=======================================
+ Hits 38752 38802 +50
Misses 51 51
Partials 68 68
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:
|
bashtage
left a comment
There was a problem hiding this comment.
Thanks. This gives Fama-MacBeth the same no-residual-df error that the other panel covariances got in 7.1, and it covers both behaviors asked for in #882.
-
It now conflicts with main: #887 rewrote the same
Raisesparagraph. Only the docstring conflicts; this text keeps both changes:If there are no residual degrees of freedom, which occurs when at most one cross-sectional estimate is available and ``debiased`` is True, or if no finite cross-sectional estimates are available. It is also raised if the bandwidth is negative or is not below the number of time periods that are used, if the bandwidth is not provided and there are fewer time periods than the kernel needs to compute it, or if the bandwidth that is computed is not finite. -
7.1 returned estimates with NaN standard errors here, so this is a backward-incompatible change. Please add a
.. versionchanged:: 7.2toFamaMacBethCovarianceand a 7.2 note under "Backward-incompatible changes":- ``FamaMacBeth.fit`` raises a ``ValueError`` when only one cross-sectional regression can be estimated and ``debiased`` is True, since the covariance then has no residual degrees of freedom. 7.1 returned NaN standard errors with a ``RuntimeWarning``. Pass ``debiased=False`` to get the estimates (:issue:`882`, :issue:`883`).
Nit: assert str(res.summary) is always true; calling str(res.summary) on its own line checks the same thing.
CodingSelim
left a comment
There was a problem hiding this comment.
one small wording tweak for the 7.2 note: i'd say debiased=False gets you the coefficient estimates, and inference is unavailable with one estimable period. i tried the example in #882 on main and on this branch. the workaround gives zero standard errors and p-values of 0 for both coefficients, and conf_int() puts both ends exactly on the estimate. that predates this PR, so a line in the release note would be enough here.
Summary
Fixes
FamaMacBeth.fit()dividing by zero and returning an all-NaNcovariance matrix (withRuntimeWarning: invalid value encountered in divide) when only a single cross-sectional period is estimable (nperiods == 1) anddebiased=True.Closes #882
deviationsand the count of finite cross-sectional period estimates (nperiods) inFamaMacBethCovariance.__init__, raisingValueErrorwith"no residual degrees of freedom"whennperiods - int(bool(debiased)) <= 0.nperiodsfor the subsequentbandwidth >= nperiodscheck and updates theFamaMacBethCovarianceRaisesdocstring.fit(debiased=False)on single-period panels (returning finite zero covariance andInvalidTestStatisticforf_statistic_robust, consistent withtest_saturated_model_that_is_not_debiasedinlinearmodels/tests/panel/test_no_residual_df.py).linearmodels/tests/panel/test_no_residual_df.pycoveringunadjusted,robust,kernel(bandwidth=Noneandbandwidth=0), multi-period panels reduced to one estimable period,debiased=False, andFamaMacBethCovariancedirectly.Verification
00528bdb) RED:pytest -W always linearmodels/tests/panel/test_no_residual_df.py->6 failed, 29 passed in 5.28s(all 6 new tests failed on the unpatched covariance check).pytest -n 2 -q -m "not slow" --ignore=linearmodels/tests/test_examples.py->23397 passed, 2473 skipped, 47 xfailed, 1 warning in 1846.99s(final revision afterblackformatting; slow tests and example notebook tests excluded, optional-dependency/Cython tests skipped).pytest -W always linearmodels/tests/panel/test_no_residual_df.py linearmodels/tests/panel/test_fama_macbeth_bandwidth.py linearmodels/tests/panel/test_fama_macbeth.py linearmodels/tests/test_kernel_bandwidth_few_observations.py->812 passed, 45 warnings in 173.70s.black --check linearmodels/panel/covariance.py linearmodels/tests/panel/test_no_residual_df.py->2 files would be left unchangedruff check linearmodels/panel/covariance.py linearmodels/tests/panel/test_no_residual_df.py->All checks passed!AI assistance disclosure: AI tools were used to locate the degrees-of-freedom mismatch in
FamaMacBethCovariance.__init__, draft the patch and tests, and format notes; all reproductions, tests, and linters were executed and verified locally.