[R-sig-ME] Design Matrix for Random effects

Henrik Singmann henrik.singmann at psychologie.uni-freiburg.de
Wed May 29 12:12:11 CEST 2013


Hi Robert,

A further problem could be that R is somewhat reluctant to fit models with interactions but without main effects.
I asked this on SO quite some time ago (with nice answers from regulars on this list, Ben Bolker and Joshua Wiley): http://stackoverflow.com/q/11335923/289572

Even if you specify to exclude the main effects in presence of interaction, their parameters will be there. In your data:

require(lme4)
cutsim <- read.csv(file="cutsim.csv", header=T)
cutsim$Species <- as.factor(cutsim$Species)
cutsim$Farm <- as.factor(cutsim$Farm)

# model without main effect:
model2 <- lmer(Yield ~ Species + Species:Farm + (1|Animal), data=cutsim, doFit = FALSE, REML=TRUE)
length(model2$fr$fixef)
# 500 fixed effects parameters

# model with main effect
model3 <- lmer(Yield ~ Species*Farm + (1|Animal), data=cutsim, doFit = FALSE, REML=TRUE)
length(model3$fr$fixef)
# 500 fixed effects parameters

Cheers,
Henrik


Am 28/05/2013 19:55, schrieb W Robert Long:
> Hi Steve
>
> That's great. Thanks a lot :-)
>
> RL
>
> On 28/05/2013 18:29, Steve Walker wrote:
>> Hi Robert,
>>
>> In stable (i.e. cran) lme4, Zt can be obtained without fitting the model
>> using this command:
>>
>> lmer(Reaction ~ Days + (Days|Subject), data=sleepstudy, doFit =
>> FALSE)$FL$trms[[1]]$Zt
>>
>> In development (i.e. github) lme4, you can use this command:
>>
>> lFormula(Reaction ~ Days + (Days|Subject), data=sleepstudy)$reTrms$Zt
>>
>> or these two:
>>
>> dv <- lmer(Reaction ~ Days + (Days|Subject), data=sleepstudy, devFunOnly
>> = TRUE)
>> environment(dv)$pp$Zt
>>
>> Cheers,
>> Steve
>>
>>
>>
>>
>> On 2013-05-28 12:44 PM, W Robert Long wrote:
>>> Hi all
>>>
>>> I would like to obtain the design matrix for the random effects,
>>> without running (g)lmer first.
>>>
>>> Could anyone help me do that ? For example, working with the
>>> sleepstudy dataset
>>>
>>> sm1 <- lmer(Reaction ~ Days + (Days|Subject), data=sleepstudy)
>>>
>>> sm1 at Zt is the transpose of the matrix I require, but I would like to
>>> obtain it without running lmer.
>>>
>>> Thanks
>>> Robert Long
>>>
>>> _______________________________________________
>>> R-sig-mixed-models at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>>
>> _______________________________________________
>> R-sig-mixed-models at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>

-- 
Dipl. Psych. Henrik Singmann
PhD Student
Albert-Ludwigs-Universität Freiburg, Germany
http://www.psychologie.uni-freiburg.de/Members/singmann



More information about the R-sig-mixed-models mailing list