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
TST: unit test for _init_keys recreating models #7569
I almost forgot about adding _init_keys to a new model (Beta regression)
We could use python inspect to check whether keywords in the model__init__ signature are also in _init_keys for a generic unit test helper function.
AFAIK, we currently only have unit tests for internal usage, e.g. fit_zeros, fit_constrained, some llnull, and cases where we need to recreate a model like (IIRC) imputation.
(I'm not familiar enough with inspect module to do it right away.)
However, formula and design_info would not be correct for recreating a model with a transformed exog or a null model.
My guess is that in the current use cases (at least my use cases), formula info is not used.
e.g.
llnull just computes llf for auxiliary model
fit_constrained uses the constrained model internally and only params and cov_params are used for the user facing model.
results methods, post-estimation that use formula info:
predict for transformations, creating exog
pairwise t-test, wald_test_terms, AFAIR those use design_info directly if available
anova_lm for linear model uses terms based on design_info
t_test, wald_test only use param_names, so I guess are independent of formula
other ???
for bootstrap: we might need design_info, but should not use missing_idx
cases I don't know
imputation, mediation (Kerby's)
If we want to support different use cases, then we might have to drop keywords before recreating a model
e.g. drop missing_idx, formula, and design_info in fit_constrained (if we want to make full use of the constrained model)
drop missing_idx for resampling observations from model.exog model.endog if they already have the missing obs dropped.
GenericZeroInflated model already has _null_drop_keys self._null_drop_keys = ['exog_infl'] (if exog_infl is None, then a constant, ones, is used)
which is used by DiscreteResults.llnull
for key in getattr(model, '_null_drop_keys', []):
del kwds[key]
Activity
josef-pkt commentedon Jul 10, 2021
I currently don't find where offset and exposure are added to init_keys
e.g. a GLM example
base.model.Model.__init__adds all keysself._init_keys = list(kwargs.keys())but
GenericLikelihoodModel.__init__does not transmit kwds/kwargs to superjosef-pkt commentedon Jul 10, 2021
check missing_idx, formula and design_info in
_init_keyse.g. #7543 (comment)
formula was added to
Model.__init__kwargs to support unpicklinghttps://github.com/statsmodels/statsmodels/blame/main/statsmodels/base/model.py#L191
However, formula and design_info would not be correct for recreating a model with a transformed exog or a null model.
My guess is that in the current use cases (at least my use cases), formula info is not used.
e.g.
results methods, post-estimation that use formula info:
cases I don't know
imputation, mediation (Kerby's)
If we want to support different use cases, then we might have to drop keywords before recreating a model
e.g. drop missing_idx, formula, and design_info in fit_constrained (if we want to make full use of the constrained model)
drop missing_idx for resampling observations from model.exog model.endog if they already have the missing obs dropped.
GenericZeroInflated model already has
_null_drop_keysself._null_drop_keys = ['exog_infl'](if exog_infl is None, then a constant,ones, is used)which is used by DiscreteResults.llnull