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

T. Florian Jaeger tiflo at csli.stanford.edu
Tue Jan 15 03:23:40 UTC 2008


On Jan 14, 2008 10:07 AM, Jonathan Berant <yonatansito at gmail.com> wrote:

>
>
>
>
>
>
>
>
> Dear list,
>
> I am trying to fit a model using lmer()
> I have the 2 usual random factors:
> 1. subjects
> 2. items
> However the items are divided into 3 groups and so I actually have -
> 15 items randomly sampled from group 1
> 15 items randomly sampled from group 2
> 15 items randomly sampled from group 3.
>
> 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)
>
> however when I run: ranef(lmerA)
>
> I see that lmer doesn't deal with that since there are only 15 numbers
> for the item random effect when in fact there are 45 items.
>
> So how do I specify that items is a random factor nested in a fixed
> factor?
> Thanks!


why don't you recode your item effect as

religData$realItemId <- as.factor(paste(as.character(religData$item),
as.character(religData$cond)))

and then run

lmerA = lmer(expScore~(relig+sex+cond) ^2+(1|subjId) + (1|realItemId)
data=religData)

not assuming any nesting? That should work, right?

Florian


>
>
>
> _______________________________________________
> R-lang mailing list
> R-lang at ling.ucsd.edu
> http://pidgin.ucsd.edu/mailman/listinfo/r-lang
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://pidgin.ucsd.edu/pipermail/r-lang/attachments/20080114/3e6de390/attachment.htm 


More information about the R-lang mailing list