4
$\begingroup$

I try to use linear mixed effect model in Python statsmodels package. However, I have no idea how to conduct and interpret the result.

Group 1 (20 people) : base line & follow up

Group 2 (20 people) : base line & follow up

Two groups went through an experiment and neuroimaging was done before(baseline) & after(follow up) the experiment. Each group consists of about 20 people.

  • If I want to regress out the effects of covariates (3 distinct covariates are expected to be used as fixed factors) from the neuroimaging data, then linear mixed effects model is appropriate approach? If it is not, then how can I use linear mixed effects model in my dataset? (I am confused with the purpose of it)
  • Then, what would be the example code?
  • And how should I interpret the result to get values that I want?
$\endgroup$

1 Answer 1

3
$\begingroup$

The purpose of a mixed effects model is to incorporate fixed effects, which are typically variables that are predictors that you have interest in, variables that you control in an experiment, and confounders; and random effects which are variables such as grouping factors for which there are repeated measures.

In your case you have participants that are measured twice and you are interested in the change from baseline and whether this differs by treatment group. This is a common use case for mixed effects models, because it avoids the pitfalls of regressing change on baseline which causes bias due to mathematical coupling, and ANCOVA which can be biased when participants are not randomised into groups (or where the randomisation fails).

The statsmodels package in python can fit such a model

import statsmodels.api as sm
import statsmodels.formula.api as smf
data = sm.datasets.get_rdataset("dietox", "geepack").data
md = smf.mixedlm("Weight ~ Time", data, groups=data["Pig"])
mdf = md.fit()
$\endgroup$
3
  • $\begingroup$ Does this answer your question ? If so, please consider marking it as the accepted answer, and if not please let us know why. $\endgroup$ Commented Aug 21, 2020 at 12:09
  • $\begingroup$ Hi Robert thanks for the answer do you happen to know how to give a similar code example in R? $\endgroup$
    – hachiko
    Commented Apr 6, 2022 at 13:17
  • 2
    $\begingroup$ @hachiko it depends which package you use, but for example lme4::lmer(Weight ~ Time + (1 | Pig)) $\endgroup$ Commented Apr 17, 2022 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.