[R-sig-ME] Simulating Data from a Linear Mixed Model
Ben Bolker
bbolker at gmail.com
Thu Nov 5 16:16:00 CET 2015
lme4 has gotten much better at simulating since 2007; there's now a built-in
simulation mechanism.
----------
dd <- expand.grid(item=factor(1:10),subj=factor(1:30),condition=factor(1:2))
form <- log.rt ~ condition + (1+condition|item) + (1+condition|subj)
set.seed(101)
library("lme4")
dd$log.rt <- simulate(form[-2], newdata=dd,
newparams=list(beta=rep(0,2),
theta=rep(1,6), ## length = 2 * (2*(2+1)/2)
sigma=1),
family=gaussian)[[1]]
ff <- lFormula(form,data=dd)
names(ff$reTrms$Ztlist) ## subj comes before item ...
m <- lmer(form,data=dd)
The hardest part is figuring out the proper order/configuration
of the theta (Cholesky factor) parameters (column wise/lower triangular/
subject first, then item).
More information about the R-sig-mixed-models
mailing list