Skip to content

Simulating Data from a Linear Mixed Model

3 messages · Hintz, F. (Florian), Ben Bolker, Douglas Bates

#
Hi,

I have a question that is very much related to an already existing post (https://stat.ethz.ch/pipermail/r-sig-mixed-models/2007q3/000293.html), however, I don?t seem to be able to get it to run for my purposes.

I would like to simulate additional data based on a linear mixed effect model that has the following structure:

model.full = lmer(rt_log ~ condition + (1+condition|item) + (1+condition|subj), data = data)

The dependent variable is continuous. The fixed factor ?condition? has two levels. Both random factors have random intercepts and random slopes by ?condition?.

Best,
Florian.

--
Florian Hintz
Centre for Language Studies
Radboud University
Nijmegen (The Netherlands)
#
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).
1 day later
#
On Thu, Nov 5, 2015 at 8:56 AM Hintz, F. (Florian) <F.Hintz at let.ru.nl>
wrote:
It happens that http://arxiv.org/abs/1511.01864, which was uploaded
yesterday, happens to deal with exactly that same model.