Closed robertour closed 1 year ago
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:
subset
parameter of lm. In the example, I used unique() to make it clear, but subset parameter definitely does not work
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:
To be sure: model_m is fit using
lm
because the mediator is only measured once (note thatdata=unique(df)
), whereas model_dv is fitted usinglmer
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:
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 withlm
but the the standard errors are smaller***.Is it OK to still the
model_m
(fitted withlmer
) even though some of the statistics are wrong? In other words, which statistics of the lmerMod object are used inside themediate
function? (I can then check if they are all the same and it is just about the format of the data)