Suppose I fit a generalized mixed logistic model such like that:
set.seed(2014)
require(lme4)
df<-data.frame(id=rep(1:5, c(8,10,12,14,15)),
out=c(rbinom(8,1,0.1), rbinom(10,1,0.3),rbinom(12,1,0.1),rbinom(14,1,0.05),rbinom(15,1,0.1)),
age=rnorm(59,50,10),
gender=rbinom(59,1,0.5))
fit<-glmer(out~age+gender+(1|id),data=df,binomial)
df$predicted<-predict(fit,type="response")
df$pred.binary<-with(df,ifelse(predicted>=0.5,1,0))
apply(df[,c(2,6)],2,sum)
out pred.binary
9 0
What's the best way to predict a binary outcomes by accounting the random effects and with an optimized threshold based on the original data set?
predict
(i.e.?predict.merMod
) withtype="response"
to get probabilities, and then tell us more about your definition of an optimal threshold ... $\endgroup$