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
writing unit tests for GLM aic and bic compared to Stata
our aic agrees with estat ic but not with the one in ereturn list
our bic agrees with ereturn list but not with estat ic
???
GLMResults aic uses the usual llf based definition GLMResults bic uses the deviance based definition.
Proposal
make both llf based, for comparability and consistency across MLE models (e.g. discrete)
add aic_dev and bic_dev for users that want the deviance based ic
AFAIK: they should only differ by a constant within same model (llf of saturated model), and it won't affect comparison within the same model for different df_model.
bump for 0.10: the inconsistency in definition of bic is just ugly (comparing GLM gaussian to ols/wls)
changing this will not be backwards compatible, but usage for within model specification search will not be affected (ranking stays the same). Across model comparison is currently not possible because bic definition doesn't match the llf version in other models.
So, change without deprecation.
"""
We are comparing statistical analysis with R · Python. When logistic regression was executed with glm of Python 's statsmodels, when we output the result of bic, it was different from R.
Since aic matched, is it a bug? All the results of the summary of the logistic regression also match.
"""
quote translated by Google from a Japanese web site
So it seems that this issue hasn't been resolved. I looked at the definition of llf and deviance in the GLM api and it seems that either works fine. The problem is actually about the usage of df_resid instead of (df_model+1) that should have been used in that place -- that is the source of discrepancies between the R version of BIC and the statsmodels' one. For consistency, however, it would be better to just use llf in the definition of BIC.
BIC in Stata and statsmodels is not wrong in terms of ranking models.
Because of the linearity in k, using df_resid just adds a constant that is not model (selection of exogs) dependent for a given sample (of given size nobs=N).
BIC = D**2 - (N - k) ln(N) = D**2 + k ln(N) - N ln(N)
(I might have seen this version before in some references with the N log N term)
The problem is "only" the inconsistency in the definition with other information criteria and that we cannot compare bic across models (i.e. across model classes).
Yes, that is true; ranking of the models would not change under the Stata-style BIC. (This is what I meant when I said "Although the current implementation of BIC in genmod serves the purpose" in #6568). I only raised this issue because the R-style definition is a more common one (at least what I have seen from the literature) and I thought it would be better to adopt such a thing. Personally, I think the Stata-style definition is a bit weird because it does not make it clear that BIC penalizes models based on the complexity (i.e., number of model parameters), although the penalty is hidden in the definition. Either way, however, BIC will do its job.
One possible difference between likelihood based and divergence based aic is likely in dispersion for models like Poisson and Binomial.
The likelihood version does not include excess dispersion, scale is assumed to be 1.
I guess that the divergence based aic does not use the scale=1 assumption.
The main way forward is to add a method where we can add several options for different definitions of the information criteria. Then we don't have to rely so much at the attributes that cannot have options, and we could deprecate the cases that we don't like.
Activity
josef-pkt commentedon Jun 4, 2014
to make it more complicated
Stata with
irlsonly reports bic, andestat icfails withlikelihood information not found in last estimation resultslist of attributes in
ereturn listdiffers whether the estimator is irls or mle (mle is default)Is there even a
aic_dev?ledmonster commentedon Mar 27, 2015
+1
josef-pkt commentedon Jan 6, 2018
bump for 0.10: the inconsistency in definition of bic is just ugly (comparing GLM gaussian to ols/wls)
changing this will not be backwards compatible, but usage for within model specification search will not be affected (ranking stays the same). Across model comparison is currently not possible because bic definition doesn't match the llf version in other models.
So, change without deprecation.
josef-pkt commentedon Aug 27, 2018
"""
We are comparing statistical analysis with R · Python. When logistic regression was executed with glm of Python 's statsmodels, when we output the result of bic, it was different from R.
Since aic matched, is it a bug? All the results of the summary of the logistic regression also match.
"""
quote translated by Google from a Japanese web site
JoonsukPark commentedon Mar 7, 2020
So it seems that this issue hasn't been resolved. I looked at the definition of llf and deviance in the GLM api and it seems that either works fine. The problem is actually about the usage of df_resid instead of (df_model+1) that should have been used in that place -- that is the source of discrepancies between the R version of BIC and the statsmodels' one. For consistency, however, it would be better to just use llf in the definition of BIC.
josef-pkt commentedon Mar 7, 2020
The problem is that we have unit tests against Stata that fail in PR #6568
I never looked at the formula specifically for the deviance case, but the use of
df_residlooks now strange/wrong to me.We need to check whether there was a problem in Stata or if the unit tests hide some problems, some
decimalin the asserts are very low.josef-pkt commentedon Mar 7, 2020
Stata docs matches our computation with df_resid = N - k
BIC = D**2 - (N - k) ln(N)
But this still looks wrong.
e.g AFAIK, deviance is supposed to be the analogue of RSS in the linear model, but there we use
kand not df_resid,e.g. https://en.wikipedia.org/wiki/Bayesian_information_criterion
and
tools.eval_measures.bic_sigmaI don't find a reference for the deviance based bic.
correction BIC uses
log(RSS), so deviance D^2 cannot be directly the analogue of RSS.josef-pkt commentedon Mar 7, 2020
BIC in Stata and statsmodels is not wrong in terms of ranking models.
Because of the linearity in
k, using df_resid just adds a constant that is not model (selection of exogs) dependent for a given sample (of given size nobs=N).BIC = D**2 - (N - k) ln(N) = D**2 + k ln(N) - N ln(N)(I might have seen this version before in some references with the N log N term)
The problem is "only" the inconsistency in the definition with other information criteria and that we cannot compare bic across models (i.e. across model classes).
JoonsukPark commentedon Mar 7, 2020
Yes, that is true; ranking of the models would not change under the Stata-style BIC. (This is what I meant when I said "Although the current implementation of BIC in genmod serves the purpose" in #6568). I only raised this issue because the R-style definition is a more common one (at least what I have seen from the literature) and I thought it would be better to adopt such a thing. Personally, I think the Stata-style definition is a bit weird because it does not make it clear that BIC penalizes models based on the complexity (i.e., number of model parameters), although the penalty is hidden in the definition. Either way, however, BIC will do its job.
josef-pkt commentedon Mar 7, 2020
One possible difference between likelihood based and divergence based aic is likely in dispersion for models like Poisson and Binomial.
The likelihood version does not include excess dispersion, scale is assumed to be 1.
I guess that the divergence based aic does not use the scale=1 assumption.
see also #1802 #1802 (comment)
#6516 for TIC (similar to robust cov_type)
The main way forward is to add a method where we can add several options for different definitions of the information criteria. Then we don't have to rely so much at the attributes that cannot have options, and we could deprecate the cases that we don't like.
JoonsukPark commentedon Mar 10, 2020
OK, I will try to commit something like that sooner or later.