Created
May 3, 2013 14:10
-
-
Save jseabold/5509329 to your computer and use it in GitHub Desktop.
standardize each variable in a statsmodels regression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import statsmodels.api as sm | |
from statsmodels.formula.api import ols | |
# load some data | |
dta = sm.datasets.longley.load_pandas() | |
# make a standardized RHS formula | |
stand = "standardize(%s)" | |
std_rhs = ' + '.join([stand]*len(dta.exog_name)) % tuple(dta.exog_name) | |
print std_rhs | |
mod_std = ols('TOTEMP ~' + std_rhs, data=dta.data).fit() | |
# compare to regular formula | |
rhs = ' + '.join(dta.exog_name) | |
mod = ols('TOTEMP ~' + rhs, data=dta.data).fit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment