Nest survival with logistic exposure in R

R
survival analysis
nest survival
ecology tutorial
Estimate daily nest survival in R with the logistic-exposure model, compare it against the Mayfield estimate, and let daily survival vary with nest age.
Author

Tidy Ecology

Published

2026-05-14

Modified

2026-10-14

Corrected 14 October 2026: the last section put the shortfall of both estimates down to estimating a gradient from a small sample; it now says that this set of nests failed faster than the generating rates imply, which pulls both down, and that the constant rate also carries the cost of its assumption.

Corrected 1 October 2026: the mid-interval age sat half a day late, which shifted the fitted age curve by half a day and pulled its period survival down; the age now sits at the middle of the days at risk, and the numbers and figures that depend on it are updated. The text also put the whole shortfall of the constant-rate estimate down to its assumption; it now says that part of it comes from this particular sample, which pulls the age-varying fit below the truth too.

The apparent success of a set of nests, the fraction that fledge among those you found, is one of the most widely misreported numbers in field ecology. It overstates survival, because nests that fail early are less likely to be found in the first place, and because nests discovered late in the cycle have little exposure left in which to fail. Mayfield’s fix was to count survival per day of exposure rather than per nest (Johnson 1979 proposed an alternative estimator), and the logistic-exposure model of Shaffer extends that idea into a generalised linear model, so daily survival can depend on nest age, date, habitat or weather (Dinsmore et al. 2002 describe such models for nest survival). This post builds all three, the naive fraction, the Mayfield estimate and a logistic-exposure model, in base R, and shows the daily rate climbing with nest age in a way the constant-rate methods cannot see.

Nest monitoring intervals

Nest data arrive as visits. Between two visits a nest was exposed for some number of days and then was either still active or had failed. The unit of analysis is therefore the interval, carrying its length as an exposure and a binary outcome, survived or failed. The example is 220 nests of a bird with a 28-day cycle, found at varying ages and checked every three to five days, generated from a model in which daily survival improves as the nest ages.

library(ggplot2)
library(dplyr)
Code behind this output; later chunks use it, so run it first
te_ink <- "#16241d"; te_body <- "#2c3a31"; te_forest <- "#275139"
te_label <- "#46604a"; te_sage <- "#93a87f"; te_paper <- "#f5f4ee"
te_line <- "#dad9ca"; te_gold <- "#c9b458"; te_deep <- "#1d5b4e"
te_brick <- "#b5534e"; te_faint <- "#5d6b61"
theme_te <- function(base_size = 12) {
  theme_minimal(base_size = base_size) +
    theme(text = element_text(colour = te_body),
          plot.title = element_text(colour = te_ink, face = "bold"),
          plot.subtitle = element_text(colour = te_faint),
          axis.title = element_text(colour = te_label),
          axis.text = element_text(colour = te_body),
          panel.grid.minor = element_blank(),
          panel.grid.major = element_line(colour = te_line, linewidth = 0.3),
          plot.background = element_rect(fill = te_paper, colour = NA),
          panel.background = element_rect(fill = te_paper, colour = NA),
          legend.background = element_rect(fill = te_paper, colour = NA),
          legend.position = "none")
}

The logistic-exposure model needs a link function that raises daily survival to the power of the interval length, so that a longer exposure has more chance to end in failure. Shaffer set this out in 2004; it is a one-off custom link passed to binomial.

logexp <- function(exposure = 1) {
  linkfun <- function(mu) qlogis(mu^(1 / exposure))
  linkinv <- function(eta) plogis(eta)^exposure
  mu.eta  <- function(eta) exposure * plogis(eta)^(exposure - 1) *
                           plogis(eta) * (1 - plogis(eta))
  valideta <- function(eta) TRUE
  structure(list(linkfun = linkfun, linkinv = linkinv, mu.eta = mu.eta,
                 valideta = valideta, name = "logexp"), class = "link-glm")
}
set.seed(430)
period <- 28
dsr_true <- function(age) plogis(2.2 + 0.045 * age)     # daily survival rises with age
n_nests <- 220
rows <- list(); fledged <- 0
for (i in seq_len(n_nests)) {
  age <- sample(0:6, 1)                                  # age when found
  alive <- TRUE
  while (age < period && alive) {
    interval <- min(sample(3:5, 1), period - age)
    survived <- 1L
    for (dd in seq_len(interval)) {
      if (runif(1) > dsr_true(age + dd - 1)) { survived <- 0L; break }
    }
    # the observer only sees the visit dates, so a failed interval still
    # carries its full length as exposure: the fate day is unknown;
    # age_mid is the middle of the days at risk, age to age + interval - 1
    rows[[length(rows) + 1]] <- data.frame(nest = i, age_mid = age + (interval - 1) / 2,
                                           exposure = interval, survive = survived)
    if (survived == 0L) alive <- FALSE else age <- age + interval
  }
  if (alive) fledged <- fledged + 1
}
d <- do.call(rbind, rows)
c(nests = n_nests, intervals = nrow(d), failures = sum(d$survive == 0),
  exposure_days = sum(d$exposure))
        nests     intervals      failures exposure_days 
          220           708           172          2725 

The naive fraction and the Mayfield estimate

The naive apparent success is just the share of nests that fledged. The Mayfield estimate instead pools every failure against every exposure day to give a constant daily survival rate, then raises it to the length of the cycle. A failed interval gets credited with half its length, Mayfield’s convention for a fate day that fell somewhere between two visits.

naive_success <- fledged / n_nests
may_exposure <- ifelse(d$survive == 1L, d$exposure, d$exposure / 2)
mayfield_dsr <- 1 - sum(d$survive == 0) / sum(may_exposure)
c(naive_apparent_success = round(naive_success, 3),
  mayfield_daily_survival = round(mayfield_dsr, 4),
  mayfield_period_survival = round(mayfield_dsr^period, 3))
  naive_apparent_success  mayfield_daily_survival mayfield_period_survival 
                  0.2180                   0.9276                   0.1220 

The naive fraction is about 0.22, while the Mayfield period survival is about 0.12. The naive figure runs high because nests found part way through the cycle only had to survive the days that remained, so counting them as full successes credits survival that was never observed. Pooling per exposure day removes that bias, but it buys the correction with an assumption: 0.12 is the probability that a nest present on day zero reaches day 28 only if daily survival is the same on every one of those days. It is not here. Multiplying the rates that generated the data gives a true period survival of 0.175, so the constant-rate estimate lands 30 per cent low. Only part of that gap is the assumption: this particular set of nests also happened to fail faster than the generating rates imply, and that pulls the age-varying fit, which assumes no constant rate, below the truth too in the last section. Both the naive fraction and the Mayfield figure are wrong, in opposite directions and for different reasons.

Letting daily survival vary with nest age

Constant daily survival is a strong claim. Eggs and small young are usually more vulnerable than nests about to fledge, so the daily rate should climb with age. Logistic exposure fits exactly that: a generalised linear model with the custom link, the interval outcome as response and nest age as a covariate.

m0 <- glm(survive ~ 1,       family = binomial(link = logexp(d$exposure)), data = d)
m1 <- glm(survive ~ age_mid, family = binomial(link = logexp(d$exposure)), data = d)
round(summary(m1)$coefficients, 4)
            Estimate Std. Error z value Pr(>|z|)
(Intercept)   1.9523     0.1452 13.4472        0
age_mid       0.0593     0.0127  4.6575        0
c(AIC_constant = round(AIC(m0), 1), AIC_age = round(AIC(m1), 1),
  delta_AIC = round(AIC(m0) - AIC(m1), 1))
AIC_constant      AIC_age    delta_AIC 
       772.1        750.2         21.9 

The age coefficient is about 0.059 on the logit scale with a standard error near 0.013, so daily survival rises reliably with age, and the age model beats the constant one by about 22 AIC units. The true slope behind the data is 0.045, comfortably inside a standard error or two of the estimate. Translating the fit back to daily survival shows the size of the change across the cycle.

b <- coef(m1)
ages <- c(2, 14, 26)
data.frame(age = ages,
           fitted_DSR = round(plogis(b[1] + b[2] * ages), 3),
           true_DSR = round(dsr_true(ages), 3))
  age fitted_DSR true_DSR
1   2      0.888    0.908
2  14      0.942    0.944
3  26      0.971    0.967

Daily survival climbs from roughly 0.89 for a two-day-old nest to about 0.97 for one near fledging, within a few thousandths of the values that generated the data at the middle and upper ages. A constant rate averages across that gradient and so overstates the danger to old nests while understating it for young ones. The plotted curve makes the trend and its uncertainty explicit against the flat Mayfield rate.

nd <- data.frame(age_mid = seq(0, period, by = 0.5))
pr <- predict(m1, nd, type = "link", se.fit = TRUE)
nd$dsr <- plogis(pr$fit)
nd$lo <- plogis(pr$fit - 1.96 * pr$se.fit)
nd$hi <- plogis(pr$fit + 1.96 * pr$se.fit)

ggplot(nd, aes(age_mid, dsr)) +
  geom_ribbon(aes(ymin = lo, ymax = hi), fill = te_forest, alpha = 0.16) +
  geom_hline(yintercept = mayfield_dsr, colour = te_gold, linetype = "42", linewidth = 0.8) +
  geom_line(colour = te_forest, linewidth = 1.0) +
  annotate("text", x = 1, y = mayfield_dsr - 0.012, label = "constant Mayfield rate",
           colour = "#8a7a30", hjust = 0, size = 3.1) +
  annotate("text", x = 20, y = 0.945, label = "logistic-exposure fit",
           colour = te_forest, hjust = 0, size = 3.1) +
  labs(title = "Daily nest survival rises with age",
       subtitle = "The exposure model recovers a gradient the constant rate cannot show",
       x = "Nest age (days)", y = "Daily survival rate") +
  theme_te()
A rising curve of daily survival from about 0.88 to about 0.97 across nest age, wrapped in a confidence band, crossing a flat dashed line for the constant Mayfield rate part way along.
Figure 1: Daily nest survival against nest age from the logistic-exposure model with a 95 per cent band, crossing the constant Mayfield rate (dashed) around day ten.

Survival across the whole cycle

Multiplying the age-specific daily rates across the 28 days gives the probability a nest survives the cycle, and comparing it with the constant-rate version shows where the two diverge: they part most over the vulnerable early days.

day <- 0:period
surv_age  <- c(1, cumprod(plogis(b[1] + b[2] * (0:(period - 1)))))
surv_const <- mayfield_dsr^day
pdf <- bind_rows(
  data.frame(day = day, S = surv_age,  model = "Age-varying (logistic exposure)"),
  data.frame(day = day, S = surv_const, model = "Constant (Mayfield)"))

ggplot(pdf, aes(day, S, colour = model)) +
  geom_line(linewidth = 0.95) +
  scale_colour_manual(values = c("Age-varying (logistic exposure)" = te_forest,
                                 "Constant (Mayfield)" = te_gold)) +
  annotate("text", x = 28, y = surv_age[period + 1] + 0.05, label = "age-varying",
           colour = te_forest, hjust = 1, size = 3.1) +
  annotate("text", x = 20, y = 0.24, label = "constant", colour = "#8a7a30", hjust = 0, size = 3.1) +
  coord_cartesian(ylim = c(0, 1)) +
  labs(title = "Survival across the nesting cycle",
       subtitle = "Age-specific daily rates compound differently from a single pooled rate",
       x = "Day of cycle", y = "Cumulative survival") +
  theme_te()
Two declining curves from one down to about 0.15 and 0.12 over 28 days; the age-varying curve is steeper over the first week then flattens as daily survival improves, while the constant-rate curve falls by the same proportion every day, so it flattens too, and it ends lower.
Figure 2: Cumulative survival across the nesting cycle: the age-varying model (forest) against the constant Mayfield rate (gold), diverging over the risky early days.

The age-varying path ends near 0.15 and the constant one near 0.12, both far below the naive 0.22, and they get there differently: the constant curve falls too slowly over the first week and then too fast, because it cannot know that the earliest days carry most of the risk. Neither reaches the true 0.175: this set of 220 nests failed faster than the generating rates imply, which pulls both down, and the constant rate also carries the cost of its assumption. The age-varying fit gets closer and is the only one of the two that can be wrong for a reason you can inspect. For questions that turn on timing, when to concentrate predator control, or how habitat shifts the daily rate, the exposure model is the one that answers them.

Where to go next

Logistic exposure is an ordinary generalised linear model with a purpose-built link, so everything from binomial regression carries over: additional covariates, interactions and the same care with separation and overdispersion. It shares the exposure logic of an offset for rates and densities, where a count is modelled per unit of effort rather than per record, and it sits alongside the other survival tools here, the Kaplan-Meier curve and the Cox model for known fates, and the Cormack-Jolly-Seber model when survival must be inferred from recaptures.

References

Mayfield HF 1975. The Wilson Bulletin 87(4):456-466.

Johnson DH 1979. The Auk 96(4):651-661 (10.1093/auk/96.4.651).

Shaffer TL 2004. The Auk 121(2):526-540 (10.1093/auk/121.2.526).

Dinsmore SJ, White GC, Knopf FL 2002. Ecology 83(12):3476-3488 (10.1890/0012-9658(2002)083[3476:ATFMAN]2.0.CO;2).

Download the R codeReport a problem with this page

Newsletter

Get updates by email

An occasional email when tutorials are added or substantially corrected. No spam; unsubscribe anytime.

By subscribing you agree to receive these emails and confirm your address once. See the privacy policy.