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?