[R-lang] random factor nested in a fixed factor with lmer

Austin Frank austin.frank at gmail.com
Tue Jan 15 20:35:13 UTC 2008


On Mon, Jan 14 2008, Jonathan Berant wrote:

> So the items are nested in a fixed factor called 'cond' (with 3
> ordered levels).  I am not sure what is the syntax for fitting such a
> model
>
> the dependent variable is 'expScore' and the predictors are 'sex'
> (between subject factor with 2 levels), 'relig' (between subject
> factor with 2 levels) and 'cond' (within subject factor with 3 levels
> within which the items are nested)
>
> I tried doing:
> lmerA = lmer(expScore~(relig+sex+cond)^2+(1|subjId) + (1|itemId),
> data=religData)
>
> So how do I specify that items is a random factor nested in a fixed
> factor?

Jonathan--

The correct answer partly depends on what variance structure you want to
fit for the random effects.  You can try the following variations to get
an idea of the different ways of dealing with nested effects within
lmer:

--8<---------------cut here---------------start------------->8---
lmerB = lmer(expScore ~ (relig+sex+cond)^2 +
                        (1 | subjId) +
                        (1 | cond / itemId),
             data=religData)

lmerC = lmer(expScore ~ (relig+sex+cond)^2 +
                        (1 | subjId) +
                        (1 | cond : itemId),
             data=religData)

lmerD = lmer(expScore ~ (relig+sex+cond)^2 +
                        (1 | subjId) +
                        (1 | cond) + 
                        (1 | cond : itemId),
             data=religData)             
--8<---------------cut here---------------end--------------->8---

HTH,
/au

-- 
Austin Frank
http://aufrank.net
GPG Public Key (D7398C2F): http://aufrank.net/personal.asc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 185 bytes
Desc: not available
Url : http://pidgin.ucsd.edu/pipermail/r-lang/attachments/20080115/91f465d5/attachment.pgp 


More information about the R-lang mailing list