Question

I would like to use formulas to specify a "baseline" model for some models fitting using statsmodels For example, I'd like to be able to specify a formula to pass to a olm or Logit model that simply predicts the mean of the observed dependent variable for all observations. I know that I can get these numbers simply by calculating the mean of the observations for the dependent variable, but I would like to have a model that produces these results (e.g. so I can use its methods). Is there a patsy syntax for accomplishing this?

Was it helpful?

Solution

If you use a formula with only the intercept term, then you will get the mean/average of the dependent variable:

import statsmodels.formula.api as smf

data={'y': [1,5,9],                       # mean(y) == 5 
      'X': [[2013], [0.001], [19.99]]     # doesn't matter
      }
model = smf.ols('y ~ 1', data=data).fit()
model.predict(3.14)                       # ==> 5
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top