Skip to content

Instantly share code, notes, and snippets.

@jseabold
Created May 3, 2013 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jseabold/5509329 to your computer and use it in GitHub Desktop.
Save jseabold/5509329 to your computer and use it in GitHub Desktop.
standardize each variable in a statsmodels regression
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