[R-sig-ME] For list review: an update to the ezPredict() function

Mike Lawrence Mike.Lawrence at dal.ca
Tue Dec 28 17:12:10 CET 2010


Hi folks,

As I've mentioned in previous posts, I maintain the "ez" package and
of late I've been coding a number of functions that aim to provide
shortcuts for very simple mixed effects modelling. I'm working on an
update to the ezPredict() function. The version on CRAN simply
provides fixed-effects predictions from an lmer object as proscribed
by the "Predictions and/or confidence (or prediction) intervals on
predictions" section at http://glmm.wikidot.com/faq. I coded an update
(https://gist.github.com/757342) that *I think* allows the user to ask
for predictions from the model for designs that do not constitute the
full model; that is, if the full model is "y ~ x*z", the new code
allows the user to request predictions from the simpler model "y ~ x",
or if the full model is "y ~ x*z*q", the user can request predictions
from the simpler model "y ~ x*q", etc. I think this will be useful for
visualizing lower order effects in designs with multiple interacting
fixed effects.

As I've also mentioned in previous posts, I'm still very much a mixed
effects beginner so I'd appreciate the list's feedback on whether I've
coded this appropriately. Specifically, I don't think that the
approach I take in the code would return the appropriate predicted
values and variances if the model provided to ezPredict was fit with
treatment contrasts. This is why line 27, if uncommented, halts
variables with treatment contrasts are detected. However, this notion
that models fitted with treatment contrasts would yield inaccurate
prediction values and variances is based on simply the rather informal
observation that when I let it attempt prediction in such cases
(leaving line 27 commented), the resulting predictions seem not to
vary from those of the intercept level of the corresponding full
model, which doesn't seem right. That is, using the ANT data set from
the ez package, I can run:

library(ez)
data(ANT)

options(contrasts=c('contr.treatment','contr.poly'))
this_fit = lmer(
    formula = rt ~ (1|subnum) + cue*flank
    , data = ANT[ANT$error==0,]
)
ezPredict(this_fit) #request the default full design predictions

#which yields:
       cue       flank    value      var
1     None     Neutral 428.1463 6.635549
2   Center     Neutral 380.6527 6.462319
3   Double     Neutral 374.7787 6.462646
4  Spatial     Neutral 340.0514 6.476256
5     None   Congruent 427.8102 6.519188
6   Center   Congruent 378.6538 6.547445
7   Double   Congruent 375.4768 6.448728
8  Spatial   Congruent 340.6319 6.634970
9     None Incongruent 497.3793 6.490352
10  Center Incongruent 467.9080 6.393626
11  Double Incongruent 459.9358 6.448578
12 Spatial Incongruent 412.9730 6.286458

#attempt to get predictions for the main effect of flank
ezPredict(
    fit = this_fit
    , to_predict = .(flank)
)

#which yields:
        flank    value      var
1     Neutral 428.1463 6.635549
2   Congruent 427.8102 6.519188
3 Incongruent 497.3793 6.490352

#which is identical to the predictions for the levels of flank when cue=='None'.

#compare to contr.sum:
options(contrasts=c('contr.sum','contr.poly'))
this_fit = lmer(
    formula = rt ~ (1|subnum) + cue*flank
    , data = ANT[ANT$error==0,]
)
ezPredict(this_fit) #request the default full design predictions

#same as before:
       cue       flank    value      var
1     None     Neutral 428.1463 6.635549
2   Center     Neutral 380.6527 6.462319
3   Double     Neutral 374.7787 6.462646
4  Spatial     Neutral 340.0514 6.476256
5     None   Congruent 427.8102 6.519188
6   Center   Congruent 378.6538 6.547445
7   Double   Congruent 375.4768 6.448728
8  Spatial   Congruent 340.6319 6.634970
9     None Incongruent 497.3793 6.490352
10  Center Incongruent 467.9080 6.393626
11  Double Incongruent 459.9358 6.448578
12 Spatial Incongruent 412.9730 6.286458

#but now
ezPredict(
    fit = this_fit
    , to_predict = .(flank)
)

#yields different and frankly more reasonable looking
#values for the main effect of flank
        flank    value      var
1     Neutral 380.9073 1.934647
2   Congruent 380.6432 1.942136
3 Incongruent 459.5490 1.908503


Thoughts?

Mike

--
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University

Looking to arrange a meeting? Check my public calendar:
http://tr.im/mikes_public_calendar

~ Certainty is folly... I think. ~




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