1
$\begingroup$

I often hear that mixed effect models allow to take into account within subject designs (i.e. repeated measures). Yet, I don't see why it couldn't be done just with fixed effects.

Here I generate some data for 100 subjects responding to two different categories of stimuli.

x = runif(100)
y = 0.2*x + runif(100)
df = data.frame( rep(c('A','B') , each=100) , c(x,y))
colnames(df) = c('cat' , 'resp')
df$subj = rep(1:100 , times=2)

The three following techniques (paired t-test, lm and lmer) give me the same estimate for the effect of cat, the same standard deviation and thus the same t-value:

t.test(resp ~ cat,paired = T,df)
mdl = lm(resp ~ cat + factor(subj) ,df)
mdler = lmer(resp ~ cat + (1|subj) ,df)

So, why is it that I often hear that random effects allow me to analyze within subject experiments?

$\endgroup$
3
  • $\begingroup$ Check with an unbalanced design. $\endgroup$
    – Michael M
    Jul 29, 2020 at 17:13
  • $\begingroup$ I changed 10 values of resp to NaNs in the first category. Now the paired t-test restricted to the 90 complete subjects and the lm give me the same result. The lmer result is different and is affected by the values in the second category of the incomplete subjects. So while it's interesting as it shows that mixed effect models deal better with missing data, I feel it doesn't answer my question at a conceptual level. $\endgroup$
    – larmor
    Jul 29, 2020 at 17:34
  • $\begingroup$ Related: stats.stackexchange.com/questions/17378/… stats.stackexchange.com/questions/140690/… $\endgroup$
    – Michael M
    Jul 29, 2020 at 17:39

0

Your Answer

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