I have two groups that I follow over 4 time points (Baseline, Three months, Six months, and Year). The outcome is some binary variable, lets say presence or absence of cancer.

model <- glmer(Binary ~ Group + Time + Group:Time + (1 | Person), 
               data = test, family = binomial(), nAGQ = 10, 
               control = glmerControl(optimizer = "bobyqa"))

When I exponeniate the fixed effects log odds (with CIs), I get the following:

se <- sqrt(diag(vcov(model)))
output <- cbind(Estimate = fixef(model), LL = fixef(model) - 1.96 * se, 
                UL =  fixef(model) + 1.96 * se)
                      Estimate         LL         UL
(Intercept)              0.0293727 0.01996715 0.04320876
Group1                   3.8690905 2.47674209 6.04417441
TimeSixMos               1.7443529 1.13560801 2.67941654
TimeThreeMos             2.1692536 1.45871709 3.22589007
TimeYear                 3.1738210 2.06651131 4.87446620
Group1:TimeSixMos         0.7220189 0.38374473 1.35848475
Group1:TimeThreeMos       0.8459276 0.48017633 1.49027247
Group1:TimeYear           0.7085735 0.37362965 1.34378115

The probability from odds is odds / (1 + odds), but how can you calculate the predicted probability (of presence of cancer) for each group at each time point from this output? More so, how do you find the predicted probability for a mixed logistic model that uses categorical covariates?


You can have a look at the emmeans package that streamlines these calculations. But if you want to see how you could do it on your own, you could try something along these lines

DF <- with(test, expand.grid(Group = levels(Group), Time = levels(Time)))
X <- model.matrix(~ Group + Time + Group:Time, data = DF)
DF$probs <- plogis(c(X %*% fixef(model)))

However, note that these probabilities are conditional on the random effects and will not match with the population-averaged probabilities at the same combinations of Group and Time; for more on this topic, check here.

  • $\begingroup$ After playing with this in Stata as well, I noticed that the above solution and the package 'effects' in R gives you the same predicted probabilities for the fixed effects only. I haven't figured out how to change that default so it would show the overall predicted probability with the person specific random effects as well. $\endgroup$ Oct 29 '19 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.