Measuring Performance with Mixed-Effects Logistic Regression

Vignette Author

2026-02-25

Mixed-effects logistic regression

A mixed-effects logistic regression was used to predict performance outcomes (0 = incorrect and 1 = correct) based on image type (non-social vs social), sex, age in months while accounting for multiple trials per participant. This approach is appropriate for binary outcome data (Coxe et al., 2013) and includes all trials while accounting for the non-independence of observations from repeated measures within participants (Agresti, 2013).

The code below demonstrates how the model was estimated using maximum likelihood with a Laplace approximation as implemented by lme4 package in R (Bates et al., 2015). Function glmer was used to model how image type, sex, and age in months predicts accuracy. Random intercepts for participants were included (1|id) to account for repeated measures and individual differences. The model was set to family = binominal (link = “logit”), which specifies that the outcome is binary and predicts the log-odds of correct responses.

#Load library 
library(lme4)

#Set Seed
> set.seed(2)

#Run model 
> mod <- glmer(performance ~ imagetype + sex + ageinmonth + (1 | id),
+   data = data_1,
+   family = binomial(link = "logit")
+ )

#Run summary outout
> summary(mod)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
 Family: binomial  ( logit )
Formula: correct ~ social + sex + ageinmonth + (1 | id)
   Data: data_1

      AIC       BIC    logLik -2*log(L)  df.resid 
 155816.5  155866.9  -77903.2  155806.5    177869 

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.3975 -0.7002 -0.0178  0.7717  4.9957 

Random effects:
 Groups Name        Variance Std.Dev.
 id     (Intercept) 20.34    4.51    
Number of obs: 177874, groups:  id, 161

Fixed effects:
              Estimate Std. Error z value Pr(>|z|)    
(Intercept)  -6.417623   0.473386 -13.557  < 2e-16 ***
socialsocial  0.968627   0.012404  78.092  < 2e-16 ***
sex1          0.389964   0.586947   0.664    0.506    
ageinmonth    0.051719   0.009395   5.505 3.69e-08 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
            (Intr) sclscl sex1  
socialsocil  0.000              
sex1        -0.126  0.002       
ageinmonth  -0.688 -0.011 -0.343
> 

The model was evaluated using the summary() function. Odds ratios (OR) were obtained by exponentiating the log-odds (Est) coefficients. Odd-ratios compares the odds of correct versus incorrect responses between non-social and social images. The model successfully converged without warnings. Shown in Table III:1, children were significantly more likely to respond correctly on social trials than non-social trials (β = 0.97, SE = 0.01, p < .001). There was a 2.6% increase in the odds of a correct response for social trials. Correct responses also increased with age (β = 0.05, SE = 0.01, p < .001). There was a 5% increase in odds of correctness with each additional month that a child ages. There was no significant effect of sex (p = .51). The estimated variance for the random effect indicated substantial individual differences and children differed in their baseline likelihood of responding correctly.

Plotting Predicted Probabilities from Model

Predicted probabilities from the model can easily be plotted using the plot() fucntion from the ggeffects package. The plot below demonstatres that when children were shown social images (images with faces) they had a higher chance of answering correctly. Boys coded as 0 had a slightly lower chance of answering correclty regardless of image type when compared to girls coded as 1. However, this was NOT significant.

#load library 
library(ggeffects)

#get predicted values 
pred <- ggpredict(mod2, terms = c("social", "sex"))

#plot 
plot(pred)

We can also quickly plot the predicted probabilities of how performace changed acorss age in months. However, since age in months is a continous variable the plotting code is slighty different.

The plot below demonstartes how there was a 5% increase in odds of correctness with each additional month that a child ages regardless of image type. We can also see that performance increased more between ages in months when children were presented with socail images.

#get predicted values for continous variable 
pred1 <- ggpredict(mod2, terms = c("ageinmonth", "social"))

#plot predicted values
plot(pred1)

References

Bates, D., Mächler, M., Bolker, B. M., & Walker, S. C. (2015). Fitting linear mixed-effects models using lme4. Journal of Statistical Software, 67(1). https://doi.org/10.18637/jss.v067.i01

Coxe, S., West, S. G., & Aiken, L. S. (2013). Generalized linear models. In T. D. Little (Ed.), The Oxford handbook of quantitative methods (Vol. 2, pp. 26–51).