Skip to main content

Complementary Log-Log Regression: At What Rate Do People Catch a Parasite?

Complementary log-log regression in R with glm(), on antibodies against Toxoplasma in 12,000 Americans (NHANES 2011-2014): how a yes-or-no outcome hides a rate, the catalytic model with log(age) as an offset, hazard ratios against odds ratios, testing a constant force of infection, age or birth cohort, checking the link, the same link for survival in intervals next to a Cox model, and APA reporting.

The question: a rate, seen through yes and no

Toxoplasma gondii is a parasite of cats. People catch it from undercooked meat, unwashed vegetables or cat litter. Most never notice, but the body keeps antibodies for life. So a blood test says whether a person has ever been infected, not when.

We want the rate: of 1,000 people who have not had it, how many catch it in a year? Epidemiologists call it the force of infection. Nobody followed these people for decades. All we have is one blood test for each, and their age. But that is enough. The older a person is, the longer the exposure, and the more likely a positive test. How steeply the share of positive tests rises with age tells the rate.

The regression that does this is one with the complementary log-log link, the third of the three classic links for a yes-or-no outcome, after the logit and the probit. It is the right one when the “yes” means it has happened at least once.

Code
library(foreign)    # read.xport(): the SAS transport files of the CDC (comes with R)
library(ggplot2)
library(survival)   # the Cox model, for section 8 (comes with R)

born_colours <- c(`born in the US` = "#2a78d6", `born elsewhere` = "#eb6834")

# number formats for the text
f1   <- function(x) formatC(x, format = "f", digits = 1, big.mark = ",")
f2   <- function(x) formatC(x, format = "f", digits = 2, big.mark = ",")
f3   <- function(x) formatC(x, format = "f", digits = 3, big.mark = ",")
# no leading zero
nz <- function(x, d = 2) sub("^(-?)0", "\\1", formatC(x, format = "f", digits = d))
pval <- function(p) if (p < .001) "< .001" else paste("=", nz(p, 3))
num  <- function(x) trimws(format(x, big.mark = ","))
pct  <- function(x, d = 1) paste0(formatC(100 * x, format = "f", digits = d), "%")

1. The data

NHANES tested the stored blood of its participants aged 6 and older in 2011–2012 and 2013–2014 (National Center for Health Statistics, 2016). The laboratory calls a sample positive from 33 international units per milliliter.

Code
nhanes <- function(year, file) {
  path <- tempfile(fileext = ".xpt")
  download.file(
    paste0("https://wwwn.cdc.gov/Nchs/Data/Nhanes/Public/", year, "/DataFiles/", file, ".xpt"),
    path,
    mode = "wb",
    quiet = TRUE
  )
  read.xport(path)
}
cycle <- function(year, letter) {
  merge(
    nhanes(year, paste0("SSTOXO_", letter))[, c("SEQN", "SSTOXG")],
    nhanes(year, paste0("DEMO_", letter))[, c(
      "SEQN", "RIDAGEYR", "RIAGENDR", "DMDBORN4", "INDFMPIR"
    )]
  )
}
raw <- rbind(cycle(2011, "G"), cycle(2013, "H"))
# 80 means "80 or older": age unknown
tox <- subset(raw, !is.na(SSTOXG) & DMDBORN4 %in% 1:2 & RIDAGEYR < 80)
tox <- with(
  tox,
  data.frame(
    positive = as.integer(SSTOXG >= 33),
    age = RIDAGEYR,
    male = as.integer(RIAGENDR == 1),
    elsewhere = as.integer(DMDBORN4 == 2),
    income = INDFMPIR
  )
)
nrow(tox)
[1] 12103
Code
c(
  positive = mean(tox$positive),
  born_in_US = mean(tox$positive[tox$elsewhere == 0]),
  born_elsewhere = mean(tox$positive[tox$elsewhere == 1])
)
      positive     born_in_US born_elsewhere 
    0.11724366     0.07772077     0.24031271 

We keep 12,103 people aged 6 to 79 whose country of birth is known. 11.7% have antibodies: 7.8% of those born in the United States and 24.0% of those born elsewhere. income is the family income divided by the poverty line. (NHANES is a complex sample with weights. We do not use them: we study the relations in the data, not the share in the US population.)


2. Look at the data

Code
tox$band <- cut(tox$age, c(5, 11, 19, 29, 39, 49, 59, 69, 79))
bands <- aggregate(cbind(positive, age) ~ band + elsewhere, data = tox, FUN = mean)
bands$n    <- aggregate(positive ~ band + elsewhere, data = tox, FUN = length)$positive
bands$born <- factor(
  ifelse(bands$elsewhere == 1, "born elsewhere", "born in the US"),
  levels = names(born_colours)
)
bands$se   <- sqrt(bands$positive * (1 - bands$positive) / bands$n)

ggplot(bands, aes(age, positive, colour = born)) +
  geom_pointrange(aes(ymin = positive - 1.96 * se, ymax = positive + 1.96 * se)) +
  geom_line(linewidth = 0.6, alpha = 0.6) +
  scale_colour_manual(values = born_colours, name = NULL) +
  scale_y_continuous(labels = function(v) paste0(100 * v, "%"), limits = c(0, NA)) +
  labs(title = "Share of people with antibodies, by age", x = "age (years)", y = NULL) +
  theme_bw() + theme(legend.position = "bottom")

Plot: 2. Look at the data

The share rises with age in both groups. Those born elsewhere are ahead already in childhood: 6.3% at ages 6 to 11, against 0.7%.


3. The model step by step, with formulas

Step 1: a constant rate

Suppose that people catch the parasite at a constant rate \(\lambda\) per year. The probability to escape for \(a\) years is \(e^{-\lambda a}\), as for any event that comes at a constant rate. So the probability of a positive test at age \(a\) is

\[P(a) = 1 - e^{-\lambda a}\]

This is the catalytic model (Muench, 1959; Hens et al., 2010, tell its history). There is no logistic curve anywhere in it.

Step 2: make it linear

Solve for the rate, and take logarithms:

\[-\log(1 - P) = \lambda a \qquad\Rightarrow\qquad \log\big[-\log(1 - P)\big] = \log\lambda + \log a\]

The left side is the complementary log-log function of \(P\). The right side is a straight line in \(\log a\) with a slope of exactly 1. A term with a known coefficient of 1 is called an offset.

Step 3: rates that differ between people

Let the rate depend on predictors, as a product: \(\lambda_i = \exp(\beta_0 + \beta_1 x_i)\). Then

\[\text{cloglog}(P_i) = \log a_i + \beta_0 + \beta_1 x_i\]

It is a generalized linear model, and

  • \(e^{\beta_0}\) is the rate per year for \(x = 0\);
  • \(e^{\beta_1}\) is a rate ratio (hazard ratio): by how many times one unit of \(x\) multiplies the rate.

This is the great advantage over the logit, whose coefficients are odds ratios with no such meaning.

Step 5: maximum likelihood, by hand

Code
minus_loglik <- function(b) {
  p <- 1 - exp(-exp(log(tox$age) + b[1] + b[2] * tox$elsewhere))
  -sum(ifelse(tox$positive == 1, log(p), log(1 - p)))
}
hand <- optim(c(-6, 0.5), minus_loglik, method = "BFGS", control = list(reltol = 1e-14))
fit  <- glm(positive ~ offset(log(age)) + elsewhere, family = binomial("cloglog"), data = tox)
rbind(by_hand = hand$par, glm = coef(fit))
        (Intercept) elsewhere
by_hand   -6.041215 0.9919758
glm       -6.041214 0.9919757

4. Fitting the model and reading the output

Code
summary(fit)

Call:
glm(formula = positive ~ offset(log(age)) + elsewhere, family = binomial("cloglog"), 
    data = tox)

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept) -6.04121    0.03738 -161.62   <2e-16 ***
elsewhere    0.99198    0.05321   18.64   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 7986.0  on 12102  degrees of freedom
Residual deviance: 7652.4  on 12101  degrees of freedom
AIC: 7656.4

Number of Fisher Scoring iterations: 6
Code
rate   <- exp(coef(fit)[["(Intercept)"]]); ratio <- exp(coef(fit)[["elsewhere"]])
ci_fit <- exp(confint.default(fit))
1000 * c(rate_US = rate, rate_elsewhere = rate * ratio)
       rate_US rate_elsewhere 
      2.378668       6.414214 
  • (Intercept): \(e^{-6.04}\) = 0.00238: people born in the US catch the parasite at a rate of 2.4 per 1,000 people per year, 95% CI [2.2, 2.6].
  • elsewhere: \(e^{0.99}\) = 2.70: for those born elsewhere the rate is 2.70 times as high, 95% CI [2.43, 2.99], which is 6.4 per 1,000 per year.
  • offset(log(age)) has no coefficient: it is fixed at 1.

With more predictors, each \(e^{\beta}\) is a rate ratio given the others:

Code
fit_more <- glm(
  positive ~ offset(log(age)) + elsewhere + male + income,
  family = binomial("cloglog"),
  data = tox
)
tab <- cbind(exp(coef(fit_more)), exp(confint.default(fit_more)))
colnames(tab) <- c("rate ratio", "low", "high")
round(tab[-1, ], 2)
          rate ratio  low high
elsewhere       2.59 2.32 2.89
male            1.24 1.11 1.38
income          0.87 0.84 0.90

Men have a 1.24 times higher rate than women, and each step of income (one poverty line more) multiplies it by 0.87. (822 people without an income are left out of this model.)


5. Is the rate constant? Test the offset

The constant rate is an assumption. Let the coefficient of \(\log(\text{age})\) be free instead of 1. If the cumulative rate grows like \(a^k\), the rate at age \(a\) is proportional to \(a^{k-1}\): rising with age if \(k > 1\), falling if \(k < 1\). And let it differ between the groups:

Code
fit_slope  <- glm(positive ~ log(age) + elsewhere, family = binomial("cloglog"), data = tox)
fit_groups <- glm(positive ~ log(age) * elsewhere, family = binomial("cloglog"), data = tox)
tests <- anova(fit, fit_slope, fit_groups, test = "Chisq")
tests
Analysis of Deviance Table

Model 1: positive ~ offset(log(age)) + elsewhere
Model 2: positive ~ log(age) + elsewhere
Model 3: positive ~ log(age) * elsewhere
  Resid. Df Resid. Dev Df Deviance  Pr(>Chi)    
1     12101     7652.4                          
2     12100     7629.4  1   22.916 1.692e-06 ***
3     12099     7587.3  1   42.098 8.683e-11 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Code
k_us   <- coef(fit_groups)[["log(age)"]]
k_else <- k_us + coef(fit_groups)[["log(age):elsewhere"]]
se_us   <- sqrt(vcov(fit_groups)[2, 2])
se_else <- sqrt(sum(vcov(fit_groups)[c(2, 4), c(2, 4)]))
rbind(born_in_US = c(k = k_us, low = k_us - 1.96 * se_us, high = k_us + 1.96 * se_us),
      born_elsewhere = c(k_else, k_else - 1.96 * se_else, k_else + 1.96 * se_else))
                       k       low      high
born_in_US     1.5866790 1.4265870 1.7467709
born_elsewhere 0.7945375 0.6189369 0.9701381

For those born in the US, the exponent is 1.59, clearly above 1: the share rises more steeply with age than a constant rate allows. For those born elsewhere it is 0.79, below 1: they catch it early.

Code
grid <- expand.grid(age = 6:79, elsewhere = 0:1)
grid$born <- factor(
  ifelse(grid$elsewhere == 1, "born elsewhere", "born in the US"),
  levels = names(born_colours)
)
grid$constant <- predict(fit, grid, type = "response")
grid$free     <- predict(fit_groups, grid, type = "response")
long <- rbind(
  data.frame(grid[, 1:3], p = grid$constant, model = "constant rate"),
  data.frame(grid[, 1:3], p = grid$free, model = "rate changes with age")
)

ggplot(long, aes(age, p, colour = born)) +
  geom_pointrange(
    data = bands,
    aes(age, positive, ymin = positive - 1.96 * se, ymax = positive + 1.96 * se),
    alpha = 0.6,
    size = 0.3
  ) +
  geom_line(aes(linetype = model), linewidth = 0.9) +
  scale_colour_manual(values = born_colours, name = NULL) +
  scale_linetype_manual(values = c("dashed", "solid"), name = NULL) +
  guides(colour = guide_legend(order = 1), linetype = guide_legend(order = 2)) +
  scale_y_continuous(labels = function(v) paste0(100 * v, "%"), limits = c(0, NA)) +
  labs(title = "Constant and changing rates", x = "age (years)", y = "share with antibodies") +
  theme_bw() +
  theme(legend.position = "bottom")

Fitted chart – 5. Is the rate constant? Test the offset

Age or birth cohort?

Does the rate really rise with age in the US? Not necessarily. People of 70 in this survey were children in the 1940s and 1950s, when meat was less safe and the infection more common. People of 20 grew up in the 1990s. A survey at one moment cannot tell “older people catch it faster” from “everybody caught it faster in the past”. Earlier rounds of NHANES showed that the infection became rarer over time (Jones et al., 2014), so the second explanation is at least part of the story. For those born elsewhere there is a third reading: the rate belongs to the country of childhood, and it fell when they moved.

This is a limit of the data and not of the link. All models for “has it ever happened?” share it.


6. Against the logit

Code
logit <- glm(positive ~ log(age) * elsewhere, family = binomial("logit"), data = tox)
probit <- glm(positive ~ log(age) * elsewhere, family = binomial("probit"), data = tox)
AIC(fit_groups, logit, probit)
           df      AIC
fit_groups  4 7595.344
logit       4 7596.471
probit      4 7602.260
Code
# the same comparison, three ways of saying it: born elsewhere against born in the US
simple_c <- glm(positive ~ offset(log(age)) + elsewhere, family = binomial("cloglog"), data = tox)
simple_l <- glm(positive ~ log(age) + elsewhere, family = binomial("logit"), data = tox)
p40 <- predict(simple_c, data.frame(age = 40, elsewhere = 0:1), type = "response")
c(
  rate_ratio = exp(coef(simple_c)[["elsewhere"]]),
  odds_ratio = exp(coef(simple_l)[["elsewhere"]]),
  risk_ratio_at_40 = p40[[2]] / p40[[1]]
)
      rate_ratio       odds_ratio risk_ratio_at_40 
        2.696557         2.954587         2.493354 
Code
# and how the risk ratio changes with the age, when the rate ratio does not
ages <- c(10, 20, 40, 60, 79)
pc <- sapply(0:1, function(e) {
  predict(simple_c, data.frame(age = ages, elsewhere = e), type = "response")
})
round(
  data.frame(
    age = ages,
    US = pc[, 1],
    elsewhere = pc[, 2],
    risk_ratio = pc[, 2] / pc[, 1],
    odds_ratio = (pc[, 2] / (1 - pc[, 2])) / (pc[, 1] / (1 - pc[, 1]))
  ),
  3
)
  age    US elsewhere risk_ratio odds_ratio
1  10 0.024     0.062      2.643      2.752
2  20 0.046     0.120      2.591      2.809
3  40 0.091     0.226      2.493      2.930
4  60 0.133     0.319      2.402      3.060
5  79 0.171     0.398      2.320      3.192
  • The fit hardly decides. The complementary log-log and the logit are within 1.1 AIC points of each other, and the probit 6.9 points behind: with probabilities below 40% the curves are nearly the same.
  • The meaning decides. If people differ by one constant rate ratio, then the risk ratio shrinks with age and the odds ratio grows, as the table shows. Only the rate ratio stays the same. A study of 20-year-olds and one of 60-year-olds would report different odds ratios for the same difference in rates.

7. Checking the model

The link test. Add the square of the linear predictor. If the link is right, it adds nothing:

Code
eta_hat <- predict(fit_groups, type = "link")
lt <- glm(positive ~ eta_hat + I(eta_hat^2), family = binomial("cloglog"), data = tox)
round(coef(summary(lt)), 3)
             Estimate Std. Error z value Pr(>|z|)
(Intercept)     0.089      0.145   0.616    0.538
eta_hat         1.094      0.140   7.805    0.000
I(eta_hat^2)    0.021      0.029   0.700    0.484
Code
p_link <- coef(summary(lt))[3, 4]

Calibration. Compare the predicted with the observed share in tenths of the prediction:

Code
p_hat <- fitted(fit_groups)
tenth <- cut(p_hat, unique(quantile(p_hat, 0:10 / 10)), include.lowest = TRUE)
cal <- data.frame(
  predicted = tapply(p_hat, tenth, mean),
  observed = tapply(tox$positive, tenth, mean),
  n = as.vector(table(tenth))
)
cal$z <- (cal$observed - cal$predicted) / sqrt(cal$predicted * (1 - cal$predicted) / cal$n)
round(cal, 3)
                  predicted observed    n      z
[0.00435,0.00976]     0.007    0.007 1256  0.099
(0.00976,0.0205]      0.016    0.013 1367 -0.753
(0.0205,0.0361]       0.028    0.042 1124  2.707
(0.0361,0.0631]       0.051    0.051 1116  0.077
(0.0631,0.0978]       0.082    0.070 1202 -1.477
(0.0978,0.133]        0.117    0.106 1227 -1.225
(0.133,0.166]         0.152    0.144 1209 -0.780
(0.166,0.205]         0.187    0.204 1198  1.473
(0.205,0.267]         0.232    0.234 1220  0.115
(0.267,0.365]         0.311    0.313 1184  0.190

The quadratic term of the link test has p = .484, and the largest difference between predicted and observed shares is 2.7 standard errors. The model describes the data well.


9. Things to keep in mind

  • Use it when “yes” means “at least once”. Presence of a species in a plot (offset: log of the area), a positive sample in a test of pooled blood (offset: log of the number pooled), infection by a given age.
  • Other shapes of the rate. Polynomials in age and other forms are possible, as long as the rate stays positive (Farrington, 1990).
  • Independence of the events. The formula \(1 - e^{-\lambda a}\) needs events that come independently at a rate. Immunity that is lost, or antibodies that fade, break it.
  • The offset is a statement. Test it, as in section 5, by freeing the coefficient.
  • Code the event as 1. The link is not symmetric.
  • Rare outcomes: all the links agree, and rate ratio, odds ratio and risk ratio are the same number.
  • Predictors that were the same during the whole exposure. Sex and country of birth were. Income was measured at the survey, and it was probably different during the years in which people caught the infection.
  • The sample. The CDC selected people with unequal probabilities and in clusters. For the US population, use survey::svyglm() with the weights; for our standard errors, treat them as approximate.

10. Reporting the results in APA style

A report (APA 7th edition) needs the link and why, the offset, the rates and rate ratios with intervals, and the check of the constant rate. The numbers come from the R objects:

Code
s_more <- coef(summary(fit_more))
apa_table <- data.frame(
  Predictor = c("Born outside the US", "Male", "Income (per poverty line)"),
  b  = f2(s_more[-1, 1]), SE = f2(s_more[-1, 2]), z = f2(s_more[-1, 3]),
  p  = sapply(s_more[-1, 4], function(p) sub("^= ", "", pval(p))),
  RR = paste0(f2(tab[-1, 1]), " [", f2(tab[-1, 2]), ", ", f2(tab[-1, 3]), "]"))

Method (data analysis):

Antibodies against Toxoplasma gondii (IgG of at least 33 IU/ml) were measured in 12,103 participants of NHANES 2011–2014 aged 6 to 79. Because antibodies last for life, the presence of antibodies at age a reflects the rate of infection over a years. We used binomial regression with the complementary log-log link and the logarithm of age as an offset, so that exponentiated coefficients are ratios of infection rates (catalytic model with a constant rate). The constant rate was tested by freeing the coefficient of log(age), overall and by place of birth. Sampling weights were not used. Analyses were conducted in R (Version 4.6.2; R Core Team, 2026).

Results:

Antibodies were found in 11.7% of the participants. With a constant rate, people born in the United States were infected at a rate of 2.4 per 1,000 per year, 95% CI [2.2, 2.6], and people born elsewhere at 2.70 times this rate, 95% CI [2.43, 2.99]. Rates were higher for men and lower with a higher income (Table 1). The rate was not constant over age, and differed in shape between the groups, χ²(2) = 65.0, p < .001: the exponent of age was 1.59, 95% CI [1.43, 1.75], for those born in the United States and 0.79, 95% CI [0.62, 0.97], for the others. Differences between birth cohorts cannot be separated from age in these data.

Table 1

Rate Ratios of Toxoplasma Infection

Predictor b SE z p Rate ratio [95% CI]
Born outside the US 0.95 0.06 17.06 < .001 2.59 [2.32, 2.89]
Male 0.22 0.06 3.86 < .001 1.24 [1.11, 1.38]
Income (per poverty line) -0.14 0.02 -7.81 < .001 0.87 [0.84, 0.90]

Note. N = 11,281. Complementary log-log regression with log(age) as an offset. Income is the ratio of the family income to the poverty threshold.

Points to remember:

  • Say what the offset is, and that its coefficient was fixed at 1.
  • Call the exponentiated coefficients rate (hazard) ratios.
  • Report the rate itself, in understandable units.
  • Say that age and cohort cannot be separated in a single survey.

11. Summary

When A yes-or-no outcome that means “at least one event”, with known exposure
The model \(\log[-\log(1 - P)] = \log(\text{exposure}) + x^\top\beta\)
How (R) glm(y ~ offset(log(exposure)) + x, family = binomial("cloglog"))
Reading it \(e^{\beta_0}\): rate; \(e^{\beta_j}\): rate ratio (hazard ratio)
The link Asymmetric: code the event as 1
Against the logit Similar fit, different meaning; rate ratios do not change with exposure, odds ratios do
Other use Time to an event in intervals: the same coefficients as the Cox model
Checks Free the offset, link test, calibration
Related pages Probit, generalized linear models

References

Farrington, C. P. (1990). Modelling forces of infection for measles, mumps and rubella. Statistics in Medicine, 9(8), 953–967. https://doi.org/10.1002/sim.4780090811

Hens, N., Aerts, M., Faes, C., Shkedy, Z., Lejeune, O., Van Damme, P., & Beutels, P. (2010). Seventy-five years of estimating the force of infection from current status data. Epidemiology and Infection, 138(6), 802–812. https://doi.org/10.1017/S0950268809990781

Jones, J. L., Kruszon-Moran, D., Rivera, H. N., Price, C., & Wilkins, P. P. (2014). Toxoplasma gondii seroprevalence in the United States 2009–2010 and comparison with the past two decades. The American Journal of Tropical Medicine and Hygiene, 90(6), 1135–1139. https://doi.org/10.4269/ajtmh.14-0013

Muench, H. (1959). Catalytic models in epidemiology. Harvard University Press. https://doi.org/10.4159/harvard.9780674428928

National Center for Health Statistics. (2016). National Health and Nutrition Examination Survey 2013–2014: Toxoplasma gondii antibody (SSTOXO_H) [Data set]. https://wwwn.cdc.gov/Nchs/Data/Nhanes/Public/2013/DataFiles/SSTOXO_H.htm

Prentice, R. L., & Gloeckler, L. A. (1978). Regression analysis of grouped survival data with application to breast cancer data. Biometrics, 34(1), 57–67. https://doi.org/10.2307/2529588