PlotLMER in LanguageR package

398 views
Skip to first unread message

mishery

unread,
Aug 15, 2008, 6:52:20 AM8/15/08
to CorpLing with R
Has anyone used this?

I can understand about 80% of what is in the LanguageR v0.95
documentation and the examples given there, but I am clearly missing
some critical aspects.

I want to plot the interaction of two continuous corpus frequency
variables, surface and morph, in the following model of lexical
decision response times.

mfreqIA.lmer=lmer(RT ~ PrevRT + PrevLex + PrevErr + PCA1 + PCA2 +
surface*morph + (1|AllSubj) + (1|ItemNum), data=rtdat)

I have tried to adapt the example Harald Baayen gives, but keep
getting the error message "number of colours and number of
conditioning values mismatch"

Any help gratefully received!

Stefan Th. Gries

unread,
Aug 15, 2008, 6:34:12 PM8/15/08
to corplin...@googlegroups.com
Can you give a replicable example with its code, plz? (For example,
using Harald's lexdec data.)

library(languageR)
m<-lmer(RT ~ Frequency + Length +(1|Subject) + (1|Word), data=lexdec)
summary(m)

Now, with this model, what is the code that you use for plotting etc.
and that creates the error?

STG
--
Stefan Th. Gries
-----------------------------------------------
University of California, Santa Barbara
http://www.linguistics.ucsb.edu/faculty/stgries
-----------------------------------------------

mishery

unread,
Aug 18, 2008, 3:44:41 AM8/18/08
to CorpLing with R
The newer LanguageR package contains a function written by Harald for
plotting mixed models.

Below are bits copied from the documentation. It is is the interaction
bit that I am messing up as I can plot a version of the model without
the interaction.

******************

Usage
plotLMER.fnc(model, xlabel = NA, ylabel = NA, ylimit = NA, fun = NA,
pred = NA, n = 100, intr = NA, mcmcMat = NA, lockYlim = TRUE,
addlines = FALSE, withList = FALSE, cexsize = 0.5, ...)

********************

intr
a list specifying an interaction to be graphed; obligatory arguments
are (1) the
name of the interaction variable, followed by (2) a vector of values
for that
variable, followed by (3) the position for interaction labels
(’"beg"’, ’"mid"’, or
’"end"’, or ’NA’ if no labels are desired), optionally followed by (4)
a list with as
first element a vector of colors and as second element a vector of
line types. The
number of elements in both vectors should match the number of values
specified
under (2) for the interaction predictor.

********************************

This the code given that I am trying to adapt. Here a three-way
interaction LogWordFreq*LogAffixFreq*Sex in an initial model is being
examined by splitting the data by sex and running separate models.

********************************

males.lmer = lmer(LogRT ~ PC1 + PC2 + PrevError + Rank +
ResidSemRating + ResidFamSize + LogWordFreq*LogAffixFreq +
poly(LogCUP, 2, raw=TRUE) + LogUP + LogCUPtoEnd +
plotLMER.fnc 89
(1|Subject) + (1|Word) + (1|Affix), data = males)
females.lmer = lmer(LogRT ~ PC1 + PC2 + PrevError + Rank +
ResidSemRating + ResidFamSize + LogWordFreq*LogAffixFreq +
poly(LogCUP, 2, raw=TRUE) + LogUP + LogCUPtoEnd +
(1|Subject) + (1|Word) + (1|Affix), data = females)
femMCMC = pvals.fnc(females.lmer, nsim=500, withMCMC=TRUE,
addPlot=FALSE)
# for which we then plot the interaction
# of word frequency by affix frequency
par(mfrow=c(2,2),mar=c(5,5,2,2))
plotLMER.fnc(females.lmer, pred = "LogAffixFreq",
intr=list("LogWordFreq", round(quantile(females$LogWordFreq),3),
"beg",
list(c("red", "green", "blue", "yellow", "purple"), rep(1,5))),
ylimit=c(6.5,7.0),
mcmcMat=femMCMC$mcmc, xlabel = "log affix frequency", ylabel = "log RT
auditory lexical decision")
mtext("females", line=0.5, cex=0.8)
plotLMER.fnc(males.lmer, pred = "LogAffixFreq",
intr=list("LogWordFreq", round(quantile(males$LogWordFreq),3), "beg",
list(c("red", "green", "blue", "yellow", "purple"), 1:5)),
ylimit=c(6.5,7.0))
mtext("males", line=0.5, cex=0.8)
plotLMER.fnc(females.lmer, pred = "LogWordFreq",
intr=list("LogAffixFreq", round(quantile(females$LogAffixFreq),3),
"beg"),
ylimit=c(6.5,7.0), cexsize=1.2)
mtext("females", line=0.5, cex=0.8)
plotLMER.fnc(males.lmer, pred = "LogWordFreq",
intr=list("LogAffixFreq", round(quantile(males$LogAffixFreq),3),
"end"),
ylimit=c(6.5,7.0), cexsize=1.0)
mtext("males", line=0.5, cex=0.8)
par(mfrow=c(1,1))

Will post my attempt at code soon

mishery

unread,
Aug 18, 2008, 3:55:08 AM8/18/08
to CorpLing with R
mfreqIA.lmer=lmer(RT ~ PrevRT + PrevLex + PrevErr + PCA1 + PCA2 +
surface*morph + (1|AllSubj) + (1|ItemNum), data=rtdat)

plotLMER.fnc(mfreqIA.lmer, pred = "morph", intr=list("surface",
round(quantile(rtdat$surface),3), "beg",
list(c("red", "green", "blue", "yellow", "purple"), rep(1,5))),
ylimit=c(4.0,8.0), xlabel = "Morph freq", ylabel = "RT")

I don't really understand what the code for the interaction is doing,
what the rep() statement is for. And not sure about how many colours I
need. I will try running Harald's example, it might illuminate things.
Previously I plotted interactions in mixed models by plotting the
effect of a variable adjusted for the median, minimum and maximum of
the other variable, so three lines. I think this is Harald's book. I
assumed the new function does something similar but with quantiles. I
will post again once I have run Harald's example to say whether this
has made things clear.

Thank you

- Mike

mishery

unread,
Aug 18, 2008, 8:48:51 AM8/18/08
to CorpLing with R
Sorted now, it was the colour coding. Although plot doesn't seem to
show an interaction despite the t values

surface -10.22
morph -3.32
surface:morph 3.44

Possible effect of outliers, I guess. The morph variable has a few
outliers, but I though it was still passably close to normal.
Reply all
Reply to author
Forward
0 new messages