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

Fitting an outcome model that is within subject (model.y, using lmer) and a simple model for the mediator (model.m, using lm)? #50

Closed
robertour opened this issue Dec 27, 2022 · 1 comment

Comments

@robertour
Copy link

I have what seems a simple case that cannot properly fit.

I have a dependent variable that is measured 10 times per subject. However, the mediator is only once after the intervention (there are two groups: Control and Interventions)

I thought that the following would work:

model_m <- lm(mediator ~ group, data=unique (df) )
model_dv <- lmer(dv ~ group + mediator  + (1 | subj), data = df)
mediate(model_m, model_dv, treat='group', mediator='mediator', boot=F)

To be sure: model_m is fit using lm because the mediator is only measured once (note that data=unique(df)), whereas model_dv is fitted using lmer because it is measured 10 times (within subject).

It triggers this error, which makes sense: one group has 10 times more rows.

Instead, I tried the following:

model_m <- lmer(mediator ~ group + (1|subj), data=df )
model_dv <- lmer(dv ~ group + mediator  + (1 | subj), data = df)
mediate(model_m, model_dv, treat='group', mediator='mediator', boot=F)

This works except that model.m is incorrect because it is fitted in 10 times the measurements that actually were taken. As a consequence, there are several warnings displayed (e.g., model failed to converge which makes sense), *the estimates are the same as the ones obtained with lm but the the standard errors are smaller.

Is it OK to still the model_m (fitted with lmer) even though some of the statistics are wrong? In other words, which statistics of the lmerMod object are used inside the mediate function? (I can then check if they are all the same and it is just about the format of the data)

@robertour
Copy link
Author

I found that there is an example in the mediate pagacke:

library(lme4)
library(mediation)

data("school", package = "mediation")
data("student", package = "mediation")

med.fit <- lm(smorale ~ free , data = school)
out.fit <- lmer(late ~ free + smorale + (1 | SCH_ID), data = student)

med.out <- mediate(med.fit, out.fit, treat = "free", mediator = "smorale", control.value = 3, treat.value = 4, sims = 100)
summary(med.out)

I just made sure that my data looked as similar as possible to the example. It is difficult to say what change did the trick, but here are a few things that I noticed:

  • my group was not properly converted to an integer. I made sure that the values were 0 for the control and 1 for the intervention group
  • I was using the subset parameter of lm. In the example, I used unique() to make it clear, but subset parameter definitely does not work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant