GLM vs GLMM: How to Choose Between Them — Modeling Logic and a Selection Guide

    Generalized Linear Models (GLM) and Generalized Linear Mixed Models (GLMM) are easy to confuse, yet they answer different questions. This guide explains how to choose between them based on the correlation structure of the data. It covers the core structure of GLM (distribution family, link function, and linear predictor), why GLM breaks down on grouped or repeated-measures data, and how GLMM adds random effects to model within-group correlation. You will find a side-by-side comparison of GLM, cluster-robust standard errors, GLMM, and marginal (GEE-type) models, a practical selection decision flow, common pitfalls in random-effects specification and inference, implementation and diagnostic tips, worked cases, cloud deployment patterns, and a quick-reference FAQ.

    Introduction: Choosing Between GLM and GLMM Comes Down to the Correlation Structure of Your Data

    In linear regression, the response variable is assumed to follow a normal distribution with constant variance, and observations are assumed to be independent. Real data often violates these assumptions: the response may be a count, a proportion, or a right-skewed positive continuous value, and its variance may change systematically with the mean. Observations also frequently arrive in groups — multiple orders from the same user, daily sales from the same store, or repeated measurements from the same subject. To handle these features, statistical modeling developed the Generalized Linear Model (GLM) and the Generalized Linear Mixed Model (GLMM).

    The two names differ by a single word, “mixed,” and in practice they are often used interchangeably. Three misconceptions are common:

    • Looking only at the distribution, not the correlation. Applying a GLM to any count or binary variable while ignoring that observations are correlated within groups.
    • Treating random effects as a fail-safe improvement. Adding random intercepts to every model without scrutiny, leading to convergence problems and confusion in parameter interpretation.
    • Assuming GLMM is a strict upgrade of GLM. Using it to answer questions that are fundamentally about the “population average,” which quietly changes the meaning of the effect size.

    In summary:

    • The GLM boundary is defined by “distribution family + link function.” It flexibly handles non-normal and non-linear data, but requires observations to be independent.
    • The GLMM boundary is defined by the “random effects structure.” Built on top of GLM, it explicitly models the correlation between observations and answers conditional (given-group) questions.

    This article walks through the core structure of GLM, the motivation and mathematical form of GLMM, a practical selection workflow, and common pitfalls, followed by a quick-reference table and worked cases.

    1.1 The Three Elements: What Makes GLM “Generalized”

    The “generalized” in GLM has two aspects: the response distribution is no longer restricted to the normal distribution, and the systematic component can be non-linear. At the same time, it retains the skeleton of the linear model and can be written as:

    1. g(μ_i) = η_i = x_i'β, μ_i = E(Y_i)

    where:

    • g(·) is a smooth and monotonic link function that maps a mean whose range may be restricted (e.g., probabilities confined to (0,1), counts constrained to be non-negative) onto the entire real line;
    • x_i is the i-th row of the model matrix, and β is the vector of parameters to be estimated.

    The entire model is determined by three parts:

    1. Random component: given the linear predictor, Y_i follows some distribution;
    2. Systematic component: the linear predictor η = Xβ;
    3. Link function: a monotonic mapping between the mean and the linear predictor.

    Compared with the ordinary linear model, GLM only changes items 1 and 3, while item 2 stays the same. This is exactly its value: the form of the model equation is nearly identical to that of the linear model, and many concepts and results from the linear model (such as the design matrix, goodness of fit, residual analysis, and maximum likelihood estimation) carry over directly. In practice, the most demanding decision in modeling is often not “how to write the equation” but “which distribution to choose and which link to pair with it.”

    1.2 The Exponential Family: The Foundation of GLM’s General Estimation Method

    GLM typically assumes that observations Y_i are mutually independent and each follows a distribution from the exponential family. The probability density (or probability mass) function of the exponential family can be written uniformly as:

    1. f(y; θ, φ) = exp{ [yθ - b(θ)] / a(φ) + c(y, φ) }

    where θ is the natural parameter and φ is the dispersion parameter. From this unified form, we can directly derive:

    • E(Y) = b’(θ)
    • Var(Y) = b’’(θ)·a(φ)

    It follows that the mean and variance of a distribution are not independent settings: once the mean is fixed, the shape of the variance is determined, up to a proportionality constant. This is the variance function commonly discussed in the GLM context, and it is the key to GLM “correctly handling non-normal data,” as detailed in Table 1.

    The unified form brings two benefits:

    • It allows deriving general score equations, solved by Iteratively Reweighted Least Squares (IRLS). Each iteration is a weighted linear regression, which aligns with the computational ideas of the ordinary linear model.
    • It naturally defines the deviance as a measure of goodness of fit — “how far the model is from the saturated model” — and supports likelihood ratio tests between nested models.

    Table 1: Common response distributions and link choices

    Response data characteristics Common distribution Common link How variance changes with the mean Typical scenarios
    Non-negative counts, mean and variance roughly equal Poisson Log Variance = mean Number of failures per unit time, daily new cases
    Counts, overdispersed (variance clearly greater than mean) Negative binomial Log Variance = mean + mean²/k Visits per person, claim counts with many zeros
    Number of successes / number of trials Binomial logit (others such as probit, complementary log-log) Depends on mean and number of trials Conversion rate, pass rate
    Non-negative, right-skewed continuous, roughly constant coefficient of variation Gamma Log, inverse Variance proportional to the square of the mean Duration, amount, capture rate
    Can be positive or negative, approximately symmetric Normal Identity Constant Measurement-error-type metrics
    Rates, proportion-type ratios Poisson or binomial with an offset Log, logit Same as Poisson/binomial Return rate, conversion rate

    1.3 Two Classic Examples: How Non-linear Laws Become Linear Models

    Example 1: Growth of new cases in the early stage of an epidemic. In the early stage of an epidemic, the number of new cases often grows approximately exponentially, i.e., the expected number of new cases on day t_i satisfies μ_i = γ·exp(δ·t_i). Taking logarithms of both sides and defining β0 = ln γ and β1 = δ gives:

    1. ln(μ_i) = β0 + β1·t_i

    This is exactly the standard form of “log link + linear predictor.” New cases are counts, so a Poisson distribution is appropriate. If the metric is “daily increase per 100,000 people,” you can take the logarithm of the total population as an offset, so the model describes relative risk rather than absolute counts. In this way, the non-linear relationship in the original problem — where “parameters appear in the exponent” — is transformed by the link function into a form that is linear in the parameters.

    Example 2: Saturation of prey capture rate with prey density. A predator’s capture rate y_i increases with prey density x_i, but when handling prey takes time and reaches the predator’s processing limit, the capture rate saturates. Ecology commonly uses the following function to describe this “Type II functional response”:

    1. μ(x) = α·x / (h + x)

    where α is the maximum capture rate and h is the prey density at which the capture rate reaches half its maximum. Here the parameters appear in a fractional form, clearly non-linear. But taking the reciprocal of both sides gives:

    1. 1/μ_i = (h + x_i) / (α·x_i) = 1/α + (h/α)·(1/x_i)

    So, using an inverse link, with 1/x_i as the predictor and β0 + β1·(1/x_i) as the linear predictor, the model returns to the GLM framework, with β0 = 1/α and β1 = h/α. As for the distribution: the capture rate is a positive continuous ratio whose standard deviation is approximately proportional to the mean — that is, variance proportional to the square of the mean — so a gamma distribution is reasonable.

    These two examples illustrate two points:

    1. The choice of distribution should serve the mean-variance relationship, not “what the data looks like.” The capture rate falls in the (0,1) interval, so some intuitively choose the binomial distribution. But the binomial distribution assumes the number of successes in a fixed number of trials, with variance determined jointly by the mean and the number of trials; here the data is a continuous rate whose variability grows with the mean, so the gamma distribution fits better.
    2. Linearization does not mean simplification. Transformations like log and reciprocal convert “equal-proportion perturbations of the mean” into “additive perturbations on the log scale.” Before modeling, you need to judge whether this perturbation mode matches the data-generating mechanism.

    Of course, the structure of the linear predictor is not limited to a straight line; interaction terms, spline bases, group dummy variables, offsets, and so on can all be incorporated, and their combination space is as rich as that of the ordinary linear model.

    1.4 Estimation and Inference: A Unified Maximum Likelihood Framework

    Parameter estimation in GLM is built on the maximum likelihood principle; only the likelihood function has no closed-form maximum and requires iterative methods such as IRLS. It is worth distinguishing the notation of observed data y from the random variable Y, but the estimator and the estimate have the same form in the formulas.

    On this basis, the commonly used inference tools include:

    • Coefficient tests: Wald test, likelihood ratio test, profile-based confidence intervals;
    • Goodness of fit: deviance, Pearson χ² statistic;
    • Dispersion: the ratio of Pearson χ² to residual degrees of freedom.

    If this ratio is clearly greater than 1, it indicates that the actual variability exceeds the distributional assumption, and you should consider overdispersion or switch distributions. These are important bases for later judging “whether to introduce random effects.”

    2. GLMM: A Natural Extension of GLM When Facing Correlated Data

    2.1 Positioning the Relationship

    The relationship between GLMM and the linear mixed model (LMM) corresponds exactly to the relationship between GLM and the ordinary linear model. They can be written side by side as four lines:

    1. Ordinary linear model: Y_i = x_i'β + ε_i
    2. Generalized linear model: g(μ_i) = x_i'β
    3. Linear mixed model: Y_ij = x_ij'β + z_ij'b_i + ε_ij
    4. Generalized linear mixed: g(μ_ij) = x_ij'β + z_ij'b_i, b_i ~ N(0, Σ)

    where i indexes the group (individual, store, region, batch, etc.), j indexes the observation within the group, and z_ij is the random-effects design vector. With the identity link and normal distribution, μ_ij = E(Y_ij | b_i) = x_ij’β + z_ij’b_i, so LMM becomes a special case of GLMM; likewise, with no random effects, GLMM reduces to GLM. In other words, the difference between GLM and LMM is exactly what GLMM adds relative to GLM.

    2.2 Why GLM Fails on Grouped Data

    GLM’s independence assumption is broken by grouped structure from at least three directions.

    Correlation. Observations within the same group are affected by common, unobserved factors — for example, a store’s location and foot traffic, or a subject’s personal traits. Even when the fixed-effects part is identical, within-group observations remain positively correlated, and GLM’s independence premise no longer holds.

    Shift in the mean-variance relationship. In GLM, once covariates are given, the mean fully determines the variance — for example, the Poisson distribution requires the conditional variance to equal the conditional mean. If there are systematic differences between groups beyond the mean, the observed variance after pooled modeling is markedly greater than the mean, forming overdispersion, and the Poisson model then underestimates uncertainty.

    Homogeneity of parameters. In GLM, all observations share the same set of coefficients, implying that “given the same covariate values, different individuals behave identically.” If effects differ markedly across individuals (some subjects are sensitive to the intervention, others barely respond), a single mean curve cannot capture this heterogeneity.

    The consequences concentrate at the inference level. Correlated observations carry far less effective information than their apparent count. If the within-group correlation coefficient is ρ and the average group size is m, then under a common approximation, the variance inflation factor (design effect) is:

    1. Design effect ≈ 1 + (m - 1)·ρ

    The effective sample size is roughly the total number of observations divided by the design effect. For example, with 30 records per group and a within-group correlation of 0.05, the design effect is about 1 + 29×0.05 = 2.45. Nominally 10,000 observations actually provide information equivalent to only about 4,000 independent observations. If standard errors are still computed as if the data were independent, they are underestimated by about √2.45 ≈ 1.57 times; confidence intervals become too narrow and p-values too small, sharply raising the risk of false positives.

    Two biases in opposite directions also deserve attention:

    • Ecological fallacy: inferring individual-level relationships from between-group (aggregate) associations, or vice versa.
    • Atomistic fallacy: attributing all between-group differences to individuals while ignoring the effect of grouping itself.

    Whether to explicitly model the grouped structure directly determines at which level the conclusion stands.

    2.3 GLMM’s Likelihood: Complexity from a Single Integral

    Once written as a GLMM, observations within a group are conditionally independent given b_i, but after integrating over b_i, they are marginally correlated:

    1. P(Y_i = y_i) = ∫ ∏_j f(y_ij | b_i; β, φ) · p(b_i; Σ) db_i

    Groups are mutually independent, so the total log-likelihood is the sum of the per-group log-likelihoods. Only in the case of “identity link + normal distribution” does the integral have a closed form; all other cases require numerical approximation. Common methods include:

    • Laplace approximation and its adaptive Gauss-Hermite quadrature version: approximate the integral via Gaussian quadrature. The number of quadrature points affects accuracy, and discrete responses especially require enough quadrature points.
    • Penalized quasi-likelihood (PQL): repeatedly fit a linear mixed model within GLM’s IRLS framework; fast to compute, but may underestimate variance components when binary data is rare or groups are small.
    • Monte Carlo methods: including Markov chain Monte Carlo and Hamiltonian Monte Carlo, which are mainstream tools in the Bayesian paradigm and can also provide posterior distributions of the parameters.

    This “integration” is the root of the complexity in model selection. The more random effects and the finer the quadrature, the higher the computational cost. In model selection, you must trade off accuracy, speed, and interpretability.

    2.4 A Key Corollary: The Marginal Mean Is Not the Conditional Mean

    Inverting the link function and taking the expectation are two operations that generally do not commute. For a non-linear link, “the mean at the average random effect” is not equal to “the population-average mean.” The consequences have two aspects:

    • The larger the random-effects variance, the more pronounced the difference in effect strength between the two perspectives;
    • Only under the identity link are the two equal. Under a log link, the variance of the random intercept additionally raises the marginal mean; under a logit link, the conditional effect (subject/group-specific) is usually larger than the marginal effect (population average).

    Therefore, the fixed-effects coefficients in a GLMM must be read as “comparing within the same group,” or expressed as “conditional on the random effects.”

    3. GLM, GLMM, and Cluster-Robust Inference: How the Three Differ in Selection

    Facing non-normal data with grouped structure, there are usually three routes, each with different assumptions and applicability conditions.

    Dimension GLM GLM + cluster-robust (sandwich) standard errors GLMM Marginal models (GEE-type methods)
    Correlation structure of observations Assumes independence Not modeled, only corrects standard errors Explicitly modeled (random effects) Approximated via a “working correlation structure”
    Target parameter Coefficients under no group structure Population-average effect Conditional (group-specific) effect Population-average effect
    Specification of distribution/mean structure Full assumption Keeps GLM’s mean structure Full assumption + random-effects distribution Only needs correct mean structure
    Dependence on number of groups Not applicable Needs enough groups Random slopes and variance components need more groups Needs enough groups for robust SEs to hold
    Group/individual-level prediction Not supported Not supported Supported (shrinkage estimates) Generally not supported
    Missing data Inference under given assumptions Limited robustness Uses all observations under MAR mechanism Generally valid under MAR mechanism
    Computational complexity Low Low to medium Medium to high Medium
    Typical scenarios Single cross-section Many groups, targeting population-average effect Few groups, non-negligible individual differences, need individual prediction Repeated measures, panel data, interested in population-average trends

    The “marginal model” here refers to a class of methods that target the “population average,” do not explicitly specify random effects, and handle within-group correlation via a working correlation structure plus robust standard errors. It belongs to the same “population-average” route as GLM with cluster-robust standard errors layered on top; the two are combined here for explanation.

    3.1 First Determine Which Level the Problem Belongs To

    The first step in selection is not to look at what the data looks like, but at who the question is asking about:

    • Asking “on average, how much does the intervention raise the conversion rate overall” is a population-average question; marginal models or cluster-robust standard errors suffice.
    • Asking “given a store’s characteristics, what is its sales level” or “what is the effect of an intervention on a specific individual” is a conditional question and requires random effects.
    • Asking “how large are the differences in effects across individuals” — this is precisely what the random-effects variance captures, and only a GLMM can answer it.

    3.2 The Applicable Boundaries of Cluster-Robust Standard Errors

    Applying a cluster correction (sandwich estimator) to the coefficient covariance matrix of a GLM is the lightest-weight approach to handling within-group correlation. It does not require guessing the within-group correlation form correctly; it only corrects uncertainty without changing the meaning of the coefficients.

    But it has three clear limitations:

    1. It cannot give group-level predictions;
    2. It cannot estimate the strength of within-group correlation, nor test whether a random slope exists;
    3. Its asymptotic properties depend on having enough groups; with very few groups, small-sample corrections are needed.

    3.3 Alternatives When There Are Very Few Groups

    When there are very few groups (e.g., only single digits), you can treat the group as a fixed effect, i.e., dummy coding, combined with cluster-robust standard errors; this is then equivalent to a fixed-effects model. This treatment has two problems:

    • It cannot extrapolate to unseen new groups;
    • When there are very many groups, it introduces a large number of parameters and exhausts degrees of freedom — which is exactly the advantage of random effects, “achieving much with little.”

    3.4 Selection Decision Flow

    1. Response variable
    2. ├─ Approximately normal, constant variance ─────────────→ Linear model / Linear mixed model
    3. └─ Non-normal or clear non-linearity
    4. ├─ Observations mutually independent, no grouping/repeated measures
    5. │ ├─ Conditional variance ≈ conditional mean ──────→ Poisson GLM
    6. │ └─ Variance ≫ mean ──────────────────────────────→ Negative binomial GLM or quasi-Poisson GLM
    7. └─ Grouping, repeated measures, or nested structure present
    8. ├─ Interested in population-average effect, with sufficient groups ─→ Marginal model / Cluster-robust SEs
    9. └─ Interested in conditional effects, individual differences, or group prediction
    10. ├─ Enough groups (empirically ≥ 10, more with random slopes)
    11. │ └───────────────────────────────────→ GLMM
    12. └─ Very few groups ───────────────────────→ Group fixed effects + Cluster-robust SEs

    4. GLMM Implementation Points and Common Pitfalls

    • Binary outcomes: a logit link gives odds ratios; a probit link gives effects on an underlying normal scale; a complementary log-log link suits modeling “rare events”; each is interpreted differently.
    • Counts and rates: for count data with time as a predictor, if you care about “intensity” rather than “total,” take log(exposure) as an offset with its coefficient fixed to 1.
    • Proportion data: “successes/total” with differing denominators suits a binomial model; continuous (0,1) proportions can use beta-regression-type methods (an extension of the exponential-family framework).
    • Zero-inflated or hurdle structures: when zeros far exceed the expectation of Poisson/negative binomial, consider zero-inflated or hurdle models; they are natural extensions of the GLM and GLMM frameworks.

    4.2 Random-Effects Structure

    • Random intercepts capture individual differences in baseline level; simplest and most common.
    • Random slopes capture individual differences in effect strength; they need more groups and within-group observations to estimate stably.
    • Crossed random effects suit non-nested structures such as “subjects × items” and “users × products.”
    • Random-effects correlation structure: whether to retain the correlation between intercept and slope affects the model’s meaning.

    A common practice is to first fit a model with the maximal reasonable random structure (e.g., intercept and slope and their correlation), then simplify step by step based on convergence, singular-fit signals, and test results. Another view holds that you should start from a parsimonious structure and add gradually to avoid over-parameterization. Both strategies are used in practice; the key is to maintain identifiability according to the number of groups and the data size.

    4.3 Convergence and Identifiability

    • Singular fits: a random-effects variance estimated as 0, or an intercept-slope correlation estimated at ±1, often indicates the data is insufficient to support that random structure.
    • Scaling issues: when continuous predictors are not centered, the correlation between the random intercept and random slope may be artificially inflated, and the fit becomes unstable. Centering continuous variables is a low-cost robustness measure.
    • Complete separation: in a logit model, when outcomes are completely determined at certain covariate values, coefficients diverge.
    • Numerical optimization failure: you can try changing the optimizer, adjusting initial values, or increasing the number of integration points.

    4.4 Within-Group and Between-Group Effects Must Be Separated

    The same predictor may have opposite effects at the “within-group change” and “between-group difference” levels. In a classic example: the sweetness of a watermelon in a region correlates positively with its own weight; but on average, small watermelons may come from high-sugar varieties and are actually sweeter. Conflating the two levels leads to misleading conclusions.

    Two common approaches:

    1. Group-mean centering: split the variable into “group mean” and “individual deviation from the group mean,” entering them separately into the model.
    2. Random-effects model with group means (Mundlak device): add each group’s predictor mean to the GLMM; between-group information is carried by the group-mean term, and the within-group effect is carried by the original variable.

    4.5 Inference and Interval Estimation

    • Testing variance components: the null hypothesis lies on the boundary of the parameter space, so the likelihood ratio statistic does not follow the usual chi-square distribution; you should use the appropriate mixture-chi-square distribution or a parametric bootstrap.
    • Comparing fixed effects: when using likelihood ratio tests or information criteria to compare models with different fixed effects, use maximum likelihood estimation rather than restricted maximum likelihood; restricted maximum likelihood is preferred when estimating variance components.
    • Predicting random effects: a single group’s random-effects value carries uncertainty, so report prediction intervals rather than point values.

    4.6 Diagnostics and Evaluation

    • GLM level: deviance residual plots, the ratio of Pearson χ² to degrees of freedom, influential-point checks (e.g., Cook’s distance based on hat values), and link-function adequacy checks.
    • GLMM level: normality checks of random effects (QQ plots or density plots), the relationship between random effects and covariates, simulation-based residual diagnostics (comparing observations with data repeatedly simulated from the fitted model), and comparison of the distributions of observed and predicted values.
    • Clarifying the scale: report marginal goodness of fit (reflecting only fixed effects) and conditional goodness of fit (including random effects) separately, and state which question each answers.
    • Predictive evaluation: perform leave-group-out cross-validation, avoiding having observations from the same group appear in both the training and test sets, which would cause information leakage.

    5. Case Walkthroughs

    Case A: Hierarchical binary outcome. A platform wants to evaluate the impact of a push-notification strategy on order conversion. The data is conversion rates aggregated by city and by day, with city population size as an offset. There are three candidate model types:

    1. Binomial GLM + logit link: coefficients read as odds ratios “at the city-average level”;
    2. Binomial GLMM (random intercept for city): coefficients read as odds ratios “within the same city”;
    3. Binomial marginal model (city as the clustering unit): coefficients read as population-average odds ratios.

    If the business question is “how much does the platform-wide average conversion improve,” you can choose option 1 or 3; if you further want to characterize heterogeneity across cities, or need to make predictions for a single city, choose option 2. If you also find that the effect differs across days within the same city, you should add a random slope rather than simply treating the date as a fixed effect.

    Case B: Longitudinal repeated measures. A study measures a binary outcome for multiple subjects at multiple time points. Each subject has both a random intercept (differences in individual baseline levels) and a random slope (differences in how fast individuals respond to the intervention); the time variable is centered within groups. The model answers “the conditional effect of the intervention on the outcome, given individual characteristics,” and outputs individual-level prediction trajectories as well as the magnitude of between-individual effect differences (i.e., the slope variance).

    6. Engineering Deployment: Running GLM/GLMM Training in the Cloud

    Once the model is selected, engineering deployment comes into play. Taking a cloud data platform as an example, common practices can be built on general-purpose capabilities:

    • Data preparation: use object storage to manage training data and features in a unified way, with version retention;
    • Compute and scheduling: run fitting tasks on elastic compute instances or in containerized environments, using scheduling components to train models in batches and by group;
    • Scenarios with many grouped samples: split into sub-tasks by group, fit GLM/GLMM independently within each group, then aggregate the coefficients and variance components across groups;
    • Large-scale GLM: for decomposable GLMs (e.g., iteratively reweighted least squares under log links for Poisson and gamma), adopt a distributed fitting mode of “each data shard accumulates independently, the master node aggregates,” mapping each IRLS weighted least-squares step to a distributed computation;
    • GLMM approximation methods: large-scale GLMM computation is costly; prioritize biased-but-controllable approximations such as the Laplace approximation or penalized quasi-likelihood, then validate with the full likelihood on a small amount of data;
    • Deployment and monitoring: use logging services and monitoring/alerting to track changes in fitting time, convergence status, and residual-diagnostic metrics; when model drift is significant, automatically trigger refitting or rollback;
    • Versioning and compliance: use the cloud platform’s model-management capabilities to record model versions and evaluation metrics.

    Taking general-purpose product capabilities like those in Baidu AI Cloud — compute, object storage, monitoring and alerting — as an example, one can chain “grouped fitting — diagnostics — deployment” into a reproducible, rollback-able pipeline, turning statistical modeling from a one-off analysis into a sustainable engineering process.

    7. Quick-Reference FAQ

    • Can a GLM directly handle repeated measures? No. GLM assumes observation independence; for non-normal modeling of grouped data, use a GLMM or marginal model.
    • Is a GLMM always better than a GLM? No. The two answer different questions. A GLMM is more complex and demands more groups; if there are very few groups or you only need a population-average effect, prefer the simpler option.
    • Are more random effects always better? No. Random slopes and random correlation structures need enough groups and within-group information to support them; over-parameterization leads to singular fits and non-identifiability.
    • How to decide whether to add random effects? Look at three things: whether there is a grouping/repeated-measures structure; whether the within-group correlation is significant (use the design effect or intraclass correlation coefficient for an initial check); whether the question needs explanation or prediction at the group level.
    • Can marginal and conditional effects be mixed? No. Under non-linear links the two differ numerically, and the scale must be stated when reporting.

    8. Summary

    The choice between GLM and GLMM can be summarized as three judgment lines:

    1. The distribution line: choose the distribution and link based on the response variable’s type and the mean-variance relationship, bringing “non-normal, non-linear” problems into the linear-modeling framework;
    2. The structure line: decide whether to introduce random effects based on whether observations have grouping, repeated measures, or nested relationships;
    3. The question line: decide whether to use a GLM, GLMM, or marginal model based on whether you are answering a population-average question or a conditional question.

    Crossing these three lines basically lets you pick the right model. In practice, you also need convergence diagnostics, scale clarification, and group-level predictive evaluation so that statistical modeling is both rigorous and deployable.