Tutorials › Generalized Linear Mixed Models (GLMM) › Modeling School Absence Counts

Software and Case Studies · Tutorial 678 of 698

Modeling School Absence Counts

Learn to prepare school absence data, fit and check a classroom-level count GLMM, and translate its coefficients into interpretable count and rate contrasts.

Intermediate 11 min read

What You'll Learn

  • Specify a Poisson random-intercept model for students nested within classrooms.
  • Use an exposure offset to account for different numbers of observed school days.
  • Interpret lunch-eligibility and commute-distance contrasts in their measurement units.
  • Distinguish classroom-conditional predictions from predictions averaged over classrooms.
  • Check model fit and recognize when the Poisson GLMM may be inadequate.
  • Report rate ratios, uncertainty, and classroom context without making causal claims.

Why School Absence Counts Need a Clustered Count Model

A student’s absences are counts, and students in the same classroom may share influences on attendance. For example, they may experience the same classroom routines or disruptions. Treating all student records as independent can therefore understate uncertainty. A generalized linear mixed model (GLMM) can represent both the count outcome and this classroom clustering.

The worked case below is entirely hypothetical. Suppose a school district records each student’s number of absences during an observation window, the number of school days the student was enrolled during that window, lunch-eligibility status, commute distance, and classroom. The aim is to describe associations with absences while accounting for classroom-level variation. These are observational associations, not estimates of causal effects.

Model: Let \(Y_{ij}\) be the absence count for student \(i\) in classroom \(j\), and let \(E_{ij}\) be that student’s observed enrolled days. Suppose \(L_{ij}=1\) for a lunch-eligible student and 0 otherwise, and let \(D_{ij}\) be commute distance in units of 5 km. A Poisson random-intercept model is
$$ Y_{ij}\mid b_j \sim \operatorname{Poisson}(\mu_{ij}), \qquad \log(\mu_{ij})= \log(E_{ij}/60)+\beta_0+\beta_L L_{ij}+\beta_D D_{ij}+b_j, \qquad b_j\sim N(0,\sigma_b^2). $$
Here \(E_{ij}/60\) is exposure relative to 60 enrolled school days. The offset \(\log(E_{ij}/60)\) has coefficient fixed at 1. Conditional on the classroom effects and covariates, the model assumes independent Poisson counts; classroom effects are independent draws from a normal distribution with mean 0 and variance \(\sigma_b^2\). The log link makes expected counts positive.

Prepare the Data and Specify the Fit

Use one row per student and keep the classroom identifier, absence count, exposure, and predictors on that row. The count should be a nonnegative integer. The exposure must be positive: a student with zero observed enrolled days has no usable rate for this model and needs a separately considered handling decision. Scaling distance as \(D_{ij}=\text{distance in km}/5\) means its coefficient compares students whose commute distances differ by 5 km. The reference group for \(L_{ij}\) is students who are not lunch-eligible.

In R, a corresponding fit with lme4 is specified as follows:

$$ \texttt{glmer(absences \textasciitilde{} lunch + distance5 + offset(log(days/60) )} $$

The code line continues with + (1 | classroom), family = poisson(link = "log"), data = student_data. In an actual script, write this as a single function call. The term (1 | classroom) supplies a random intercept for each classroom. The model assumes the rate is proportional to enrolled days: doubling exposure doubles the expected count when the other model terms are held fixed. If that assumption is unsuitable, the offset does not fix the problem.

These choices also define what a coefficient means. At the same exposure and commute distance, \(\exp(\beta_L)\) is the conditional ratio of expected absence counts for lunch-eligible versus non-eligible students in the same classroom. For students differing by 5 km in commute distance, \(\exp(\beta_D)\) is the corresponding conditional count ratio, holding lunch status and classroom fixed. Because the offset scales expected counts by exposure, these are also rate ratios per enrolled day.

Worked Example: Fit the Classroom Count Model

Suppose the hypothetical data contain 120 students in 12 classrooms, with 60 enrolled days for most students and fewer days for some who joined late. A Poisson GLMM gives \(\hat{\beta}_L=-0.223\), \(SE=0.090\), \(\hat{\beta}_D=0.080\), \(SE=0.035\), and estimated classroom-intercept standard deviation \(\hat{\sigma}_b=0.35\). Assume the fit converged and no boundary or singular-fit warning was reported. The enrolled-day offset is appropriate only if exposure is positive and proportionality to days is a reasonable model assumption.

For lunch eligibility, the estimated conditional rate ratio is

$$ \exp(\hat{\beta}_L)=\exp(-0.223)=0.8001. $$

At the same commute distance and exposure, and within the same classroom, the fitted expected absence count for lunch-eligible students is about 0.800 times the count for non-eligible students—a 20.0% lower rate. The model is associational; this contrast does not show that eligibility causes fewer absences.

A Wald 95% confidence interval for the log rate ratio is

$$ -0.223 \pm 1.96(0.090)=(-0.3994,\,-0.0466). $$

Exponentiating the endpoints gives \((0.671,\,0.955)\). Thus, under the model and its repeated-sampling assumptions, the interval procedure would cover the conditional rate ratio in 95% of repeated samples. Here the interval corresponds to a rate between 0.671 and 0.955 times that of non-eligible students, for the specified classroom, exposure, and commute-distance comparison.

For commute distance, the estimated rate ratio for a 5 km increase is \(\exp(0.080)=1.083\), or about an 8.3% higher expected absence rate, holding lunch status and classroom fixed. The Wald interval on the log scale is \(0.080\pm1.96(0.035)=(0.0114,0.1486)\); exponentiating gives a rate-ratio interval of \((1.011,1.160)\).

From Conditional Contrasts to Expected Counts

A coefficient contrast is not itself an expected count. To obtain an expected count, specify the exposure, covariates, and classroom context. Setting \(b_j=0\) gives a prediction for a classroom at the center of the assumed random-effect distribution on the log scale. Averaging predictions over the random-effect distribution instead gives a population-average expected count for the modeled classroom distribution. These are different targets.

Worked Example: Compare Predictions Averaged Across Classrooms

Continue with the hypothetical fit. For illustration, use \(\hat{\beta}_0=2.5185\) and \(\hat{\sigma}_b=0.35\), and predict for students with 60 enrolled days and a commute distance of 0 km. For a normally distributed random intercept, the average of \(\exp(b_j)\) is \(\exp(\sigma_b^2/2)\). Thus the population-average prediction for non-eligible students is

$$ \exp\{2.5185+(0.35^2/2)\} =\exp(2.57975)\approx 13.19\text{ absences per 60 enrolled days}. $$

For lunch-eligible students, the fitted mean is multiplied by \(\exp(-0.223)\). The displayed predictions are therefore about 10.56 and 13.19 absences per 60 enrolled days, respectively. Using these rounded displayed counts, the ratio is \(10.56/13.19\approx0.801\). The ratio computed from the unrounded model contrast is \(\exp(-0.223)\approx0.8001\). The small difference is due to rounding the two expected counts; it is not a change in the model’s contrast.

Both predictions average over the same classroom-effect distribution, at the same exposure and commute distance. Their ratio therefore equals the fixed-effect rate ratio before rounding. They do not describe the expected count in every classroom: a classroom with a positive random intercept has a higher conditional mean, while one with a negative intercept has a lower one.

Worked Example: Report a 10 km Distance Contrast

The distance coefficient is for a 5 km increase. A 10 km increase is two such units, so its estimated conditional log count ratio is \(2(0.080)=0.160\). Exponentiating,

$$ \exp\{2(0.080)\}=\exp(0.160)=1.174. $$

At equal exposure and lunch status, students whose commute distances differ by 10 km have a fitted expected-count ratio of 1.174 within the same classroom: the longer-distance student’s expected rate is about 17.4% higher. The scaled coefficient interval from the preceding example doubles for this contrast: \((2(0.0114),2(0.1486))=(0.0228,0.2972)\). Exponentiating gives \((1.023,1.346)\). This interval describes uncertainty in the 10 km rate ratio, not a range containing 95% of individual students’ counts.

Checking the Fit and Recognizing Its Limits

A successful optimizer message is not evidence that every model assumption is adequate. Begin by checking the data coding: absence counts should be integers, the offset should be finite, and the classroom identifier should reflect the actual grouping. Inspect observed counts and fitted values across classrooms, as well as residual or simulation-based checks for systematic discrepancies. Patterns by fitted count or classroom can reveal lack of fit that a single summary statistic misses.

The Poisson assumption implies that, conditional on the covariates and classroom effect, the count variance equals its conditional mean. A classroom random intercept accounts for some shared variation, but it does not guarantee this conditional variance relationship is correct. If residual checks show more variation than expected, or an excess of zeros relative to model predictions, investigate the source and consider whether another count distribution or model structure is justified. Do not add complexity solely because a diagnostic is imperfect; check whether the alternative fits the data and answers the same scientific question.

The random-intercept specification assumes that the classroom effects are normally distributed and that the modeled covariates are appropriately represented. It also assumes observations are conditionally independent after accounting for those effects and predictors. A singular fit, a variance estimate near zero, convergence warnings, or strong residual patterns deserve investigation. With few classrooms, estimation of the random-effect distribution and uncertainty can be fragile. Repeated observations on a student would also require a dependence structure beyond the classroom intercept; that is not the data structure specified here.

The offset is useful when students have unequal observation time, but it imposes proportionality: expected absences scale directly with enrolled days. The model does not account automatically for missing covariates, informative enrollment duration, or unmeasured confounding. The fixed-effect GLM from GLM is a possible alternative when clustering is absent or not part of the target analysis; ignoring genuine classroom dependence can yield misleading standard errors. A random-intercept GLMM instead estimates conditional associations while representing classroom heterogeneity, but its estimates rely on its distributional and conditional-independence assumptions.

Common mistake: Reporting \(\exp(\hat{\beta}_D)\) as the effect of a 1 km increase when distance was entered in 5 km units. The coefficient compares students 5 km apart. For a 1 km contrast, use \(\exp(\hat{\beta}_D/5)\); for 10 km, use \(\exp(2\hat{\beta}_D)\). Always state the units, exposure, and whether the comparison is conditional on the same classroom or averaged across classrooms.
1
Define the observation and exposure.
Use one student record, a valid absence count, and positive enrolled days; state the time window and how the offset is scaled.
2
Specify the hierarchy and contrasts.
Identify classroom as the grouping factor, choose the random-intercept structure, define reference groups, and scale continuous predictors so coefficient units are clear.
3
Fit, diagnose, and report.
Check convergence and fit, transform log-scale contrasts to rate ratios, and give the measurement units, exposure, classroom context, and uncertainty.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions.

  1. If a student was enrolled for 30 days, what exposure multiplier does the model use relative to 60 days?
  2. With \(\hat{\beta}_L=-0.223\), what is the estimated lunch-eligibility rate ratio, and how should it be described?
  3. If distance is coded in 5 km units and \(\hat{\beta}_D=0.080\), what is the fitted rate ratio for a 10 km increase?
  4. Why can the ratio from displayed expected counts differ slightly from the exponentiated model coefficient?
  5. Name one diagnostic warning sign and a model assumption it may prompt you to investigate.

Solutions. (1) The exposure multiplier is \(30/60=0.5\), so expected absences are half those for 60 days when the other terms are fixed. (2) \(\exp(-0.223)=0.8001\); at equal exposure, distance, and classroom, the fitted rate for eligible students is about 0.800 times the non-eligible rate, an association rather than a causal effect. (3) A 10 km increase is two units, giving \(\exp(2(0.080))=\exp(0.160)=1.174\). (4) Displayed counts are rounded, while the exponentiated coefficient uses the unrounded fitted contrast; the displayed ratio can consequently differ in the last digits. (5) For example, a singular fit or classroom-patterned residuals can prompt checks of the random-intercept structure or the assumed conditional distribution and independence.

Clinical Biostats