[R] extracting p-values from lmer outputs
lngmyers at ccu.edu.tw
lngmyers at ccu.edu.tw
Fri Mar 3 14:54:52 CET 2006
I would like to write a function that runs GLMM using lmer
on a user-input model containing interactions, but if the
model doesn't produce significant results for the interaction,
a reduced model will be run without the interaction.
Doing this seems to require getting the p-values out of an
lmer object, but I don't know how to do this. (The grand
DF debate seems to be irrelevant since the number of observations
for what I want to do with this will always be over 600 or so.)
The problem is that the output of lmer is a list of length 0.
My "brilliant" idea, shown below, is to divert the display to
a file, then read the file as a string. I guess it's useful
to save the full summary somewhere, but is there really
no more elegant way to do this?
- James Myers
National Chung Cheng University
Minhsiung Chiayi 621 Taiwan
lmerout = lmer(Y ~ X1 * X2 + (1|Subj), data = dat, family = "binomial")
sink("lmerout.txt")
lmerout
sink()
lmerout.string = readChar("lmerout.txt",20000)
splitstring = strsplit(lmerout.string,"\r\n")
# If I counted right, the line with the interaction is [19]:
interstring = strsplit(splitstring[[1]][19]," ")
# Lines contain TABs, so the p-value is the eighth element along:
pvalue = as.numeric(interstring[[1]][8])
if(pvalue < .05) print("The interaction is significant!")
More information about the R-help
mailing list