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
How to compute pseudo R^2 for GLM estimators #5861
Hi, How can I compute the psquared for GLM estimators? I don't find the result in the summary as opposed to Logit and other estimators.
Thank you for giving me what values to use in the result to manually compute psquared.
Do you mean R^2? I don't know what "psquared" would mean here. There is no R^2 outside of linear regression, but there are many "pseudo R^2" values that people commonly use to compare GLM's. Many of these can be easily computed from the log-likelihood function, which statsmodels provides as llf. A lot of discussion about this can be found on-line, below is one good reference:
about the definition with respect to constant in the model
In the linear regression model the rsquared takes into account whether a constant is included or not among the regressors.
In discrete models and GLM we don't make the results statistic depend on the presence of a constant. llnull is always the model with only a constant as explanatory variable.
The analogue to regression through zero (no constant) would be to assume that the linear prediction is zero (*), but we don't use this in GLM and discrete models. (at least not yet)
(*) which would mean in the Logit case that the predicted probability is 0.5.
I think summary2 adds pseudo-rsquared by default if the attribute is available in the results instance
in iolib.summary2.summary_model a dict defines the optional attributes, AFAIR/AFAIU info['Pseudo R-squared:'] = lambda x: "%#8.3f" % x.prsquared
background: We have both summary and summary2 because we couldn't agree on a design. summary is rigid with fine-tuned text formatting summary2 is more flexible but has a different default formatting
Pseudo R-squared is available for smf.logit but not for smf.glm. Are there plans to add this? The attributes are already there to calculate the measure. Thanks
Activity
kshedden commentedon Jun 10, 2019
Do you mean R^2? I don't know what "psquared" would mean here. There is no R^2 outside of linear regression, but there are many "pseudo R^2" values that people commonly use to compare GLM's. Many of these can be easily computed from the log-likelihood function, which statsmodels provides as
llf. A lot of discussion about this can be found on-line, below is one good reference:https://statisticalhorizons.com/r2logistic
jpainam commentedon Jun 10, 2019
Thank you. by psquared, i mean pseudo R^2. . I'll look at the given link.
josef-pkt commentedon Jun 10, 2019
I thought we had it but it's missing in GLM
DiscreteResults has McFadden's pseudo-rsquared (attribute and in summary). It should be added to GLMResults also
other pseudo-rsquared versions could be made available as additional method
jpainam commentedon Jun 10, 2019
Thank you, where should I add this function? Here the result of summary
josef-pkt commentedon Jun 10, 2019
compare with a discrete model
AFAICS it is before log-likelihood
or better: put it in the right column before AIC, i.e. on top
(AIC and BIC would be better at the bottom, but we don't change this for now.)
jpainam commentedon Jun 10, 2019
@josef-pkt please, I don't understand. Where should I put the top_right dict? Thank you. Here is my code
josef-pkt commentedon Jun 10, 2019
about the definition with respect to constant in the model
In the linear regression model the rsquared takes into account whether a constant is included or not among the regressors.
In discrete models and GLM we don't make the results statistic depend on the presence of a constant.
llnullis always the model with only a constant as explanatory variable.The analogue to regression through zero (no constant) would be to assume that the linear prediction is zero (*), but we don't use this in GLM and discrete models. (at least not yet)
(*) which would mean in the Logit case that the predicted probability is 0.5.
josef-pkt commentedon Jun 10, 2019
you are using
summary2notsummary. I need to check, I don't know that code very well.does logit.summary2() show the pseudo-rsquared?
josef-pkt commentedon Jun 10, 2019
I think summary2 adds pseudo-rsquared by default if the attribute is available in the results instance
in
iolib.summary2.summary_modela dict defines the optional attributes, AFAIR/AFAIUinfo['Pseudo R-squared:'] = lambda x: "%#8.3f" % x.prsquaredjosef-pkt commentedon Jun 10, 2019
background: We have both
summaryandsummary2because we couldn't agree on a design.summaryis rigid with fine-tuned text formattingsummary2is more flexible but has a different default formattingjpainam commentedon Jun 10, 2019
Here the result for
result.summary()It's same output
jpainam commentedon Jun 10, 2019
But using
logit = sm.Logit(data["mij"], data[train_cols])prints thepseudo-squared[-]How to compute psquared for GLM estimators[/-][+]How to compute pseudo R^2 for GLM estimators[/+]josef-pkt commentedon Oct 14, 2019
AFAICS, this is still open, we don't have pseudo R-squared outside discrete models yet
vnijs commentedon Jan 26, 2021
Pseudo R-squared is available for smf.logit but not for smf.glm. Are there plans to add this? The attributes are already there to calculate the measure. Thanks
anuragwatane commentedon Feb 25, 2021
We would like to work on this issue.
statsmodels#5861 ENH: McFadden and Cox&Snell Pseudo R squared added i…
ENH: Added test cases for McFadden and Cox-Snell Pseudo R-square to r…
ENH: Using assert_allclose() instead of assert_almost_equal() for tes…
ENH: Updated the formula for Cox-Snell Pseudo R-square to maintain co…
nikkopante commentedon Apr 11, 2021
Hi what about Adj. R^2 and AIC?
josef-pkt commentedon Nov 16, 2024
closing
pseudo-rsquared has been added in #7682