Chapter 6 Generalized linear models

When the variable of interest is not continuous or the assumptions of the classical linear model are not satisfied, generalized linear models provide an appropriate alternative for modeling the relationships of interest. This approach was introduced by Nelder & Wedderburn (1972), who showed that several widely used statistical methods, such as logistic regression, log-linear models for count data, and certain advanced regression models for continuous variables, could be integrated within a single unified theoretical framework. This formulation made it possible to extend regression tools beyond the settings in which the response variable follows a normal distribution.

The need for this generalization arises because classical linear models assume, among other things, normality and homogeneity of variance in the response variable, conditions that are rarely met when categorical variables, proportions, or counts are analyzed. In these situations, generalized linear models offer a flexible framework for appropriately modeling the relationship between variables by selecting a probability distribution suitable for the response and a link function that connects the mean of that distribution with the linear predictor.

To illustrate the models presented in this chapter, the survey_data database and the BigCity population are used, following the same structure used in previous chapters. After loading tidyverse (Wickham, Averick, et al., 2026), survey (Lumley, 2024), srvyr (Freedman Ellis & Schneider, 2024), broom (Robinson et al., 2026), and jtools (Long, 2026), the following code block creates two new categorical variables (poverty and unemployment) from the original variables Poverty and Employment, respectively.

options(digits = 4)
library(tidyverse)
library(survey)
library(srvyr)
library(broom)
library(jtools)

survey_data <- readRDS("Data/encuesta.rds")
data("BigCity", package = "TeachingSampling")

survey_design <- survey_data %>%
  as_survey_design(
    strata = Stratum,
    ids = PSU,
    weights = wk,
    nest = TRUE
  )

survey_design <- survey_design %>%
  mutate(
    poverty = factor(
      ifelse(Poverty != "NotPoor", 1, 0),
      levels = c(0, 1),
      labels = c("=Poor", "=Not poor")
    ),
    unemployment = factor(ifelse(Employment == "Unemployed", 1, 0),
      levels = c(0, 1),
      labels = c("=Unemployed", "=Not unemployed")
    )
  )

References

Freedman Ellis, G., & Schneider, B. (2024). Srvyr: ’Dplyr’-like syntax for summary statistics of survey data. https://doi.org/10.32614/CRAN.package.srvyr
Long, J. A. (2026). Jtools: Analysis and presentation of social scientific data. https://doi.org/10.32614/CRAN.package.jtools
Lumley, T. (2024). Survey: Analysis of complex survey samples.
Nelder, J. A., & Wedderburn, R. W. M. (1972). Generalized linear models. Journal of the Royal Statistical Society: Series A (General), 135(3), 370–384. https://doi.org/10.2307/2344614
Robinson, D., Hayes, A., Couch, S., & Hvitfeldt, E. (2026). Broom: Convert statistical objects into tidy tibbles. https://doi.org/10.32614/CRAN.package.broom
Wickham, H., Averick, M., Bryan, J., Chang, W., McGowan, L. D., François, R., Grolemund, G., Hayes, A., Henry, L., Hester, J., Kuhn, M., Pedersen, T. L., Miller, E., Bache, S. M., Müller, K., Ooms, J., Robinson, D., Seidel, D. P., Spinu, V., … Yutani, H. (2026). Tidyverse: Easily install and load the tidyverse. https://doi.org/10.32614/CRAN.package.tidyverse