GLM vs. GLMM: Check the Distribution First, Then Test Independence

    Choosing between a generalized linear model (GLM) and a generalized linear mixed model (GLMM) depends on two questions: whether the response requires a non-normal distribution and link function, and whether observations are independent. This guide explains the GLM components, random effects in GLMMs, distribution and link-function choices, and two examples: epidemic growth and predator capture rates. It also covers temporal dependence, overdispersion, offsets, and the interpretation of conditional effects.

    1. Check the Distribution First, Then Independence

    Choosing between a GLM and a GLMM requires answering two questions:

    1. Is the response variable non-normal, with a link function needed to relate its mean to the predictors?
    2. Are the observations independent?

    These questions can be evaluated separately, producing four common cases:

    Data structure Independent observations Non-independent observations
    Normal response with an identity link Ordinary linear model Linear mixed model
    Non-normal response requiring a link function Generalized linear model (GLM) Generalized linear mixed model (GLMM)

    The first question is mainly determined by the physical meaning of the response variable. Counts, proportions, and positive continuous measurements are generally not normally distributed.

    The second question depends on how the data were collected. Repeated measurements from the same person, patients from the same hospital, repeated samples from the same site, daily observations on adjacent dates, and geographically nearby locations may all produce correlated observations.

    A practical decision process is:

    1. Is the response variable non-normal? If so, use a GLM or GLMM. If not, and the observations are independent, an ordinary linear model may be sufficient.
    2. Are the observations independent? If they are independent, use a GLM. If they are not, use a GLMM.
    3. When uncertain, start with the study design. Grouping, repeated measurements, or temporal ordering usually indicate that random effects should be considered. Residual diagnostics can then be used for confirmation.

    2. The Three Components of a Generalized Linear Model

    A GLM consists of three components: the random component, the systematic component, and the link function.

    2.1 Random component

    The response variables (Y_i) are assumed to be independent and to follow a distribution from the exponential family, such as the Poisson, binomial, gamma, or normal distribution.

    The distribution should be selected according to the response variable’s range and the way its variance changes with the mean:

    • For a Poisson distribution, the variance equals the mean.
    • For a gamma distribution, the variance is proportional to the square of the mean.
    • For a normal distribution, the variance does not depend on the mean.

    2.2 Systematic component

    The linear predictor is

    [
    \eta_i = x_i^\mathsf{T}\beta
    ]

    where (x_i) is the (i)-th row of the model matrix and (\beta) is the vector of parameters to be estimated.

    The linear predictor is linear in the parameters. Therefore, common techniques from linear modeling—including dummy-variable coding, interaction terms, and spline-basis expansions—can also be used in GLMs.

    The link function (g) satisfies

    [
    g(\mu_i) = \eta_i
    ]

    where

    [
    \mu_i = E(Y_i)
    ]

    The link function should be smooth and monotonic. It maps the range of the response mean to the entire real-number line.

    Common combinations include:

    Data type Distribution Common link Notes
    Counts Poisson Log Ensures a positive predicted mean
    Binary outcomes or proportions Binomial Logit Proportion data require the number of trials
    Positive continuous values with an approximately constant coefficient of variation Gamma Inverse, typically, or log Variance grows with the square of the mean
    Normal response Normal Identity Reduces to an ordinary linear model

    Distribution selection should begin with the physical meaning of the data and then consider the variance pattern. For example, count data generally have a variance that increases with the mean, making the Poisson distribution more appropriate than the normal distribution in many cases.

    3. GLMMs: Adding Random Effects

    When observations are not independent, random effects can be added to the linear predictor. For a random-intercept model:

    [
    \eta{ij} = x{ij}^\mathsf{T}\beta + b_i
    ]

    where

    [
    b_i \sim N(0,\sigma^2)
    ]

    Each group has its own baseline level, which makes observations within the same group more similar.

    Important considerations for random effects include the following:

    • The grouping variable represents the level at which observations become correlated, such as an individual, location, or hospital.
    • A random slope allows the effect of a predictor to vary between groups. It can be written in a form such as (time | id). Random slopes require sufficient data. When the dataset is small, it is generally safer to begin with a random intercept.
    • If a grouping variable has very few levels, its variance estimate can be unstable. At least five or six levels are commonly recommended.
    • If the groups are specific entities of direct interest—for example, three particular hospitals—they can be treated as fixed effects. If the groups are sampled from a broader population, such as randomly selected locations, they are more appropriately modeled as random effects.

    GLMMs do not have a closed-form likelihood. Software typically estimates their parameters using a Laplace approximation or adaptive Gaussian-Hermite quadrature.

    In R, a Poisson GLMM for count data can be written as:

    1. glmer(y ~ x + offset(log(t)) + (1 | site), family = poisson)

    The coefficients in a GLMM are conditional effects, evaluated given the group-specific effects. They are generally interpreted as subject-level effects. If the goal is to estimate a population-averaged effect, a marginal model such as a generalized estimating equation (GEE) may be more appropriate.

    4. Example 1: Exponential Growth in Early Disease Transmission

    Let (\mu_i) denote the expected number of new cases on day (t_i). During the early stage of an outbreak, the number of new cases may approximately follow exponential growth:

    [
    \mu_i = \gamma \cdot \exp(\delta t_i)
    ]

    Taking the logarithm of both sides gives:

    [
    \log(\mu_i) = \beta_0 + \beta_1 t_i
    ]

    where

    [
    \beta_0 = \log(\gamma), \qquad \beta_1 = \delta
    ]

    The right-hand side is now linear. Therefore, when observations are independent and the mean-variance relationship is reasonably close to Poisson, a Poisson GLM can be used.

    Key modeling considerations include:

    • The response is the daily number of new cases, which is count data. The Poisson distribution is a reasonable starting point.
    • The log link ensures a non-negative mean and converts exponential growth into a linear relationship.
    • The linear predictor contains only an intercept and a time term, making the parameters straightforward to interpret.

    The coefficient interpretation is direct. The quantity

    [
    \exp(\beta_1)
    ]

    is the factor by which the expected number of cases changes when time increases by one day.

    For example, if (\beta_1) is approximately 0.1, then

    [
    \exp(0.1) \approx 1.105
    ]

    which corresponds to an increase of approximately 10.5% per day. This interpretation is valid only during the period in which the exponential-growth assumption holds. Later turning points in the outbreak must be modeled separately.

    Two additional assumptions should be checked.

    Temporal autocorrelation

    Consecutive daily observations from the same region may be temporally correlated. If residuals show strong correlation between adjacent dates, a GLM alone may not be sufficient.

    Possible approaches include adding a temporal structure, such as an autoregressive term or a smoothing spline. If data are available from multiple regions, a regional random intercept can also be added, converting the model into a GLMM.

    Overdispersion

    Count data often exhibit overdispersion, meaning that the observed variance is larger than the variance assumed by the Poisson model.

    One diagnostic is the ratio of the Pearson residual sum of squares to the residual degrees of freedom:

    [
    \phi =
    \frac{\sum(\text{Pearson residual}^2)}
    {\text{residual degrees of freedom}}
    ]

    If (\phi) is substantially greater than 1, common options include:

    1. A quasi-Poisson model, which keeps the mean estimates but adjusts the standard errors.
    2. A negative binomial model, which explicitly adds an extra variance component.
    3. An observation-level random effect.

    5. Example 2: Saturating Predator Capture Rates

    A predator’s capture rate (y) may increase with prey density (x), but the increase eventually levels off. A common representation is the Holling Type II function:

    [
    \mu = \frac{\alpha x}{h+x}
    ]

    where:

    • (\alpha) is the maximum capture rate.
    • (h) is the prey density at which the capture rate reaches half of its maximum.

    This equation is nonlinear in the parameters (\alpha) and (h), so it cannot be fitted directly with an ordinary linear model.

    Using an inverse link, it can be rewritten as:

    [
    \frac{1}{\mu}
    =
    \frac{1}{\alpha}
    +
    \frac{h}{\alpha}\cdot\frac{1}{x}
    ]

    Let

    [
    \beta_0 = \frac{1}{\alpha},
    \qquad
    \beta_1 = \frac{h}{\alpha}
    ]

    The linear predictor then becomes:

    [
    \beta_0 + \beta_1\left(\frac{1}{x}\right)
    ]

    After fitting the model, the original parameters can be recovered as:

    [
    \alpha = \frac{1}{\beta_0},
    \qquad
    h = \frac{\beta_1}{\beta_0}
    ]

    This example shows that a nonlinear relationship between the response and a predictor does not necessarily prevent the use of a GLM. With an appropriate link function, the relationship can be transformed into a predictor that is linear in the parameters.

    Choosing the distribution

    The distribution should be selected according to the variance pattern. If the standard deviation of the capture rate is approximately proportional to its mean, the coefficient of variation is roughly constant and the variance is proportional to the square of the mean.

    A gamma distribution has this property and can therefore be paired with an inverse link. After fitting the model, plot residuals against fitted values to check whether the variance still increases with the mean.

    Accounting for exposure time

    If the number of captures is recorded over observation windows of different lengths, exposure must also be handled.

    Suppose (y) is the capture count recorded over (t) hours, and the goal is to estimate the capture rate per unit time. A Poisson model with a log link can be used with (\log(t)) as an offset:

    [
    \log(E[y]) = \log(t) + x^\mathsf{T}\beta
    ]

    The offset coefficient is fixed at 1 and is not estimated. Consequently,

    [
    \frac{E[y]}{t} = \exp(x^\mathsf{T}\beta)
    ]

    so the parameters directly describe the rate.

    Do not use (y/t) as the response in a Poisson model. Doing so ignores the different weights associated with observation windows of different lengths.

    If the same predator or enclosure is observed repeatedly, observations within that group are not independent. A random intercept should then be added, resulting in a GLMM.