[R-sig-ME] lmer/pamer.fnc error
Ben Bolker
bbolker at gmail.com
Thu Jun 19 21:55:20 CEST 2014
Richa Bharti <richabharti74 at ...> writes:
>
> *Dear R group,*
>
> *I am doing lmer with 2 factors and cage and as random effect.*
> *
> library(lmerTest)
> library(LMERConvenienceFunctions)
>
> lmer_null<-lmer(D1 ~ 1 + (1|Cage_Nr), data=data_m)
> lmer_full<-lmer(D1 ~ Day*Mutant+Gender+(1|Cage_Nr),
> REML=FALSE, data=data_m)
> (anova_full<-anova(lmer_null,lmer_full))
> summary(lmer_full)
> (expl.dev<-pamer.fnc(lmer_full))
> but with last command I am getting an error
> Error in pf(anova.table[term, "F value"], anova.table[term, "Df"],
> nrow(model <at> frame) - :
Non-numeric argument to mathematical function
> I don't what's the reason of this error? Is my model not
> correct or could it any other reason.
It looks like at least this part of LMERConvenienceFunctions must
not have been updated to work with new lme4.
Here's an updated version (I haven't tested carefully,
use at your own risk!) (The package must not contain any
examples or testing of this function, or this would have failed
a while ago ...)
library(lme4)
library(LMERConvenienceFunctions)
library(lmerTest)
fm1 <- lmer(Reaction~Days+(1|Subject),sleepstudy)
fm2 <- update(fm1,.~.-Days)
print(pamer.fnc(fm1),digits=3)
## Sum Sq Mean Sq NumDF DenDF F.value Pr(>F) DenDF(UPPER) Pr(>F,UPPER)
## Days 162703 162703 1 161 169 7.88e-244 178 1.21e-27
## DenDF(LOWER) Pr(>F,LOWER) expl.dev(%)
## Days 160 7.12e-27 0.286
Transform <- function (`_data`, ..., check.names=TRUE)
{
e <- eval(substitute(list(...)), `_data`, parent.frame())
tags <- names(e)
inx <- match(tags, names(`_data`))
matched <- !is.na(inx)
if (any(matched)) {
`_data`[inx[matched]] <- e[matched]
`_data` <- data.frame(`_data`,check.names=check.names)
}
if (!all(matched))
do.call("data.frame", c(list(`_data`), e[!matched],
list(check.names=check.names)))
else `_data`
}
pamer.fnc <- function (model, ndigits = 4)
{
if (length(rownames(anova.table <- anova(model))) == 0) {
cat("nothing to evaluate: model has only an intercept.\n\n")
cat("printing model fixed effects:\n")
fixef(model)
} else {
dims <- NULL
rank.X = qr(getME(model,"X"))$rank
lower.bound <- sum(sapply(ranef(model),function(x) prod(dim(x))))
updf <- nobs(model) - rank.X
lodf <- updf - lower.bound
dv <- as.character(formula(model)[[2]])
ss.tot <- sum(scale(model.frame(model)[[dv]],scale=FALSE)^2)
aov.table <- as.data.frame(anova(model))
new.anova.table <-
Transform(anova.table,
`Pr(>F)`=pf(`Mean Sq`,NumDF,DenDF,lower.tail=FALSE),
`DenDF(UPPER)` = updf,
`Pr(>F,UPPER)`=pf(F.value,NumDF,updf,lower.tail=FALSE),
`DenDF(LOWER)` = lodf,
`Pr(>F,LOWER)`=pf(F.value,NumDF,lodf,lower.tail=FALSE),
`expl.dev(%)`=aov.table[,2]/ss.tot,
check.names=FALSE)
class(new.anova.table) <- class(anova.table)
return(new.anova.table)
}
}
More information about the R-sig-mixed-models
mailing list