Closed Gabatsarl closed 10 months ago
@Gabatsarl just to pin down exactly what you are asking for, are you looking for output like this?
# example from ?glmer examples
require(lme4)
gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
data = cbpp, family = binomial)
predict(gm1)
# 1 2 3 4 5 6 7
# -0.8087134 -1.8006384 -1.9369296 -2.3884588 -1.6974362 -2.6893612 -2.8256524
resid(gm1)
# 1 2 3 4 5 6 7 8
# -1.43770782 0.98847195 2.35668826 -0.93702271 -0.24317316 -0.14282938 -0.17032930 0.95457653
Yes exactly @pdbailey0, but I want it with the model using WeMix
.
I have two questions
Question 1: if
model<- mix(READ1 ~ qe21+qe22+qe25+qe28+(1|ID_ECOLE),
data = data2019,weights=c("rwgt0", "W_SCH_ADJ2"),family = "binomial")
can we do predict(model)
?
Question 2: for a new dataset newdata
, can we also do predit(model,newdata=newdata)
?
Thanks
[edited by PB for format and type in name "WeMix"]
There is no such function in WeMix
. You could request it.
Thanks. Conclusion: You can't predict with a model fitted with mix.
Here is some demo code
require(lme4)
require(WeMix)
cbpp2 <- cbpp1 <- cbpp[,c("herd", "period")]
cbpp1$n <- cbpp$size - cbpp$incidence
cbpp1$level <- 0
cbpp2$n <- cbpp$incidence
cbpp2$level <- 1
cbpp_ <- rbind(cbpp1, cbpp2)
repn <- function(x) {
x[rep(1, x$n),]
}
cbpp_rep <- do.call(rbind, lapply(split(cbpp_, factor(1:nrow(cbpp_))), repn))
cbpp_rep$one <- 1
gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
data = cbpp, family = binomial)
gm2 <- glmer(level ~ period + (1 | herd),
data = cbpp_rep, family = binomial)
we1 <- mix(level ~ period + (1|herd), data=cbpp_rep, family=binomial(), weights=c("one", "one"))
predict(we1) # does not work
Thank you for pointing this out @ Gabatsarl. Our returns lacked some important information for using the results and now have that information. In particular, predict
does now work. It also works with new data.
Hello, I would like to use the "WeMix" package. I would like to know if there is a prediction function in the R software? How can I get the residuals out of the model?
my model is
I know that with package "glmer" it's easy with the "predict" function and the "resid" function for the residuals. But how do you do it with the "WeMix" package? Thanks, Talagbe [updated by PB to format code]