Skip to content
Prev 199288 / 398503 Next

qu: predict with lmer (lme4) or other ways to get classification accuracy

I had to deal with this issue yesterday, and I'm guessing many who use lme4
have this same issue because of the lack of a predict.lmer function.  It
seems to me that one would need to plug the X %*% b output from the
predict.lmerBin function below into the logistic distribution to get the
actual predicted probabilities. In other words:

predict.lmerBin <- function(object, X){
	if(missing(X))
		X <- object at X
	b <- fixef(object)
	plogis(X %*% b)
} 

The example below demonstrates the equivalence between plogis(X %*% b) and 
predict.glm(...,	type = "response",...) :

ldose <- rep(0:5, 2)
numdead <- c(1, 4, 9, 13, 18, 20, 0, 2, 6, 10, 12, 16)
sex <- rep(c(1, 2), c(6, 6))
SF <- cbind(numdead, numalive=20-numdead)
budworm.lg <- glm(SF ~ sex*ldose, family=binomial)
summary(budworm.lg)
ld <- seq(0, 5, 0.1)

preds = predict(budworm.lg, newdata= data.frame(sex=1, ldose=ld),
		type = "response")
X = as.matrix(data.frame(int=1,sex=1, ldose=ld, sex.ldose=1*ld))#, sex.ldose
= 2*ld))
b=coef(budworm.lg)
plogis(X%*%b) == preds

If anyone can see a problem with the above approach, please let me know as I
am using this for a paper.

-Solomon
Spencer Graves wrote: