Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include an example of a random slope model as a way to demonstrate how to use this aspect of statsmodels #72

Open
aezarebski opened this issue Dec 17, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@aezarebski
Copy link
Owner

If we were to add `years_post_phd` as a covariate, what sort of model would this

There is an example on the following page of the the statsmodels documentation:

https://www.statsmodels.org/dev/examples/notebooks/generated/mixed_lm_example.html

Basically, you use the re_formula in addition to the existing formula (which specifies fixed effects) and group to specify a random slope (and intercept) model.

Here is an example of fitting a random intercept model

data = sm.datasets.get_rdataset("dietox", "geepack").data
md = smf.mixedlm("Weight ~ Time", data, groups=data["Pig"])
mdf = md.fit(method=["lbfgs"])
print(mdf.summary())

and here it is with the random slope for each pig through time as well as the random intercept:

md = smf.mixedlm("Weight ~ Time", data, groups=data["Pig"], re_formula="~Time")
mdf = md.fit(method=["lbfgs"])
print(mdf.summary())
@aezarebski aezarebski added the enhancement New feature or request label Dec 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant