Includes option for showing Pseudo R2 Adjusted (used on Logit)
Currently, when you want to compare discrete models such as Logit and Probit, no values are shown for R² / R² Adjusted, because statsmodels for these models returns Pseudo-R² Adjusted. This PR includes the ability to display that coefficient.
OK, only problem: the (empty) row gets generated even when only OLS is used. This by the way is not just a problem of your PR - the same applies to standard R² being generated for Logit (although maybe it's less annoying).
You should verify that at least one of the models has a non-null md['p_r2'], and if none does, not print the line.
Two options:
- you do it for Pseudo-R² (either do the check directly inside
generate_p_r2, or relying on a newRenderermethod), we later generalize to other parameters - we first solve the fix for R² and adjusted R², you rebase this afterwards by reusing the same mechanism
I can do the general fix, just let me know how to prefer to proceed.
I prefer the second option. For example, this is a logit panel that I'm testing now, and I would like to remove those R2/Adjusted R2 in favor of Pseudo R2

I prefer the second option. For example, this is a logit panel that I'm testing now, and I would like to remove those R2/Adjusted R2 in favor of Pseudo R2
OK, commit https://github.com/mwburke/stargazer/commit/eb8b4fb48e9ba1e0f9e714d50c6cc23f2fb050bb should accomplish this - in addition to reducing code duplication.
You can use the same scheme as R2/Adjusted R2 for Pseudo R2.
@cnavarreteliz I actually did it today in https://github.com/StatsReporting/stargazer/commit/8bdc068cd6c2ffed6fa4692fbbcf5616108c2ed9
I would have rather pinged you here again... if I hadn't completely forgot about this PR, sorry.
How do I get Stargazer to actually show the PseudoR2 for a Statsmodels Logit model? By default (v.0.0.6) it does not include it in the table.
model = logit("dv ~ iv", data=data).fit()
(Stargazer([model]).render_html())
How do I get Stargazer to actually show the PseudoR2 for a Statsmodels Logit model? By default (v.0.0.6) it does not include it in the table.
The following code results in a table that correctly features the pseudo-R² for the logit model:
import pandas as pd
from sklearn import datasets
from statsmodels.api import OLS, Logit
from stargazer.stargazer import Stargazer
diabetes = datasets.load_diabetes()
df = pd.DataFrame(diabetes.data, columns=diabetes['feature_names'])
df['target'] = (diabetes.target > 100).astype(int)
ols = OLS.from_formula('target ~ age + sex + bmi', data=df).fit()
lg = Logit.from_formula('target ~ age + sex + bmi', data=df).fit()
table = Stargazer([ols, lg])
@phipz if it doesn't in your code, please provide a complete copypastable example and open a new issue, thanks.