Edited
When we use a traditional logistic regression and make a prediction in R for example:
library(dplyr)
n = 300
xx<-c("r1","r2","r3","r4","r5")
xxx<-c("e1","e2","e3")
p=0.3
df1 <- data_frame(
xx1 = runif(n, min = 0, max = 10),
xx2 = runif(n, min = 0, max = 10),
xx3 = runif(n, min = 0, max = 10),
School = factor(sample(xxx, n,re=TRUE)),
Rank = factor(sample(xx, n,re=TRUE)),
yx = as.factor(rbinom(n, size = 1, prob = p))
)
df1
mm<-glm(yx ~ xx1 + xx2 + xx3 + School + Rank,binomial,df1)
n11 = data.frame(School="e3",Rank="r2",xx1=8.58,xx2=8.75,xx3=7.92)
predict(mm, n11, type="response") #No meu caso especifico
or predict (mm, n11)
depending on what interests us, no problem.
But when working with GLMM, for example
library(lme4)
mm2 <- glmer(yx ~ xx1 + xx2 + xx3 + Rank + (Rank | School), data = df1,
family = "binomial",control = glmerControl(calc.derivs = FALSE))
predict(mm2, n11, type="response") #No meu caso especifico
displays error
Error in 'contrasts<-'('*tmp*', value = contr.funs[1 + isOF[nn]]) :
contrastes podem ser aplicados apenas a fatores com 2 ou mais níveis
I tried to do so
predict(m2,n11, re.form=(~Rank|School))
and displays the error
Error in UseMethod("predict") :
no applicable method for 'predict' applied to an object of class "glmmadmb"
What would be the correct form of the prediction in R in GLMM?