You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
get_prediction intervals ignore df_resid_inference with cluster-robust use_t=True #10743
With cov_type="cluster" and use_t=True, conf_int, t_test and pvalues use the t distribution with n_groups - 1 degrees of freedom (df_resid_inference), but get_prediction uses df_resid. The confidence and prediction intervals from summary_frame() / conf_int() are therefore too narrow. This affects OLS/WLS/GLS, GLM (which=None, "mean", "linear") and discrete models.
Expected: both give [0.8449, 3.4477], i.e. x0 @ params ± t(0.975, G - 1) * se. The standard error is the same in both (0.5753), only the quantile differs (t with 198 vs 9 df). I checked the expected interval with a hand-coded cluster sandwich and scipy.stats.t.ppf(0.975, 9).
In a small simulation (G = 10 clusters of 20, 2000 replications) the nominal 95% interval for E[y | x = 1] covered the true value 89.0% of the time with the current code and 93.4% with n_groups - 1 degrees of freedom.
Cause: regression/_prediction.get_prediction and get_prediction_glm, get_prediction_linear and get_prediction_monotonic in base/_prediction_inference.py pass df=self.df_resid. The results classes use getattr(self, "df_resid_inference", self.df_resid) for pvalues, conf_int and t_test (#1903 fixed this for pvalues).
Versions: statsmodels 0.15.0 (PyPI) and main 27e7475, numpy 2.4.6, scipy 1.17.1, pandas 3.1.1, Python 3.11.
Activity