Occupancy Models in R for Frog Surveys with Imperfect Detection

A species can be present but undetected: occupancy models in R

An evening survey of wetlands often starts with a simple question: Did we hear the frogs? But a quiet site is not necessarily an empty one. A species may be present and still go unheard because calling activity changes with season, weather, or observation time. Occupancy models address this problem by separating the ecological state of a site from our chance of detecting the species there.

This tutorial uses historical 2001 Delaware North American Amphibian Monitoring Program (NAAMP) observations of the spring peeper (Pseudacris crucifer), distributed with R’s unmarked::frogs example. The method generalizes to repeated surveys of crop pests, weed patches, pollinators, birds, amphibians and other organisms, provided the underlying monitoring design supports its assumptions.

The statistical idea: occupancy is latent; detection is observed

Let \(z_i=1\) mean that site \(i\) is genuinely occupied, even if the observer hears nothing. Let \(y_{ij}=1\) indicate that the frog was detected on survey visit \(j\) to site \(i\). The classical model assumes

\[ z_i \sim \operatorname{Bernoulli}(\psi), \qquad y_{ij}\mid z_i \sim \operatorname{Bernoulli}(z_i p_{ij}). \]

Here \(\psi\) is the probability a site is occupied and \(p_{ij}\) is the probability of detection conditional on occupancy. Thus, an all-zero history can arise either from a genuinely unoccupied site or from an occupied site whose visits all missed the animal:

\[ \Pr(y_{i1}=\cdots=y_{iJ}=0)= (1-\psi)+\psi\prod_{j=1}^{J}(1-p_{ij}). \]

That mixture is why simple counting of detected sites usually does not measure the same quantity as site occupancy. Repeated visits provide the additional information needed to estimate both processes under the model’s assumptions. For a clear original derivation, see MacKenzie and colleagues (2002).

1. Read and audit the real observations

The original calling-index variable Pcru has values 0–3. It is an ordinal call-intensity index, not a count of individual frogs. The accompanying data preparation converts any positive index into detection 1, retaining zero as non-detection. Missing visits remain NA, never zero.

The dataset contains 337 recorded site visits at 130 distinct sites, including 140 visits with a positive call. Only 97 sites have all three survey occasions; 53 potential visit slots are missing. The first code section verifies that the original observations and wide-format export agree before any model is estimated. These are descriptions of historical monitoring records, not contemporary population numbers.

# 01 | Import and verify the historical observations
required_packages <- c("unmarked", "ggplot2")
missing_packages <- required_packages[
  !vapply(required_packages, requireNamespace, logical(1), quietly = TRUE)
]
if (length(missing_packages) > 0) {
  stop("Install the missing packages first: ",
       paste(missing_packages, collapse = ", "))
}
# Attach unmarked so its S4 generics/methods (vcov, coef, predict) are used.
library(unmarked)
Warning: package 'unmarked' was built under R version 4.5.3
library(ggplot2)

out_dir <- "04_outputs"
dir.create(out_dir, showWarnings = FALSE, recursive = TRUE)

raw <- read.csv("01_data/frog2001pcru_raw.csv",
                colClasses = c(RouteNumStopNum = "character"))
wide <- read.csv("01_data/frog2001pcru_unmarked_wide.csv",
                 colClasses = c(site = "character"))

response_names <- paste0("y.", 1:3)
stopifnot(all(c("RouteNumStopNum", "JulianDate", "Pcru") %in% names(raw)),
          all(c("site", response_names) %in% names(wide)),
          nrow(raw) == 337L, nrow(wide) == 130L,
          !anyDuplicated(wide$site),
          !anyDuplicated(raw[c("RouteNumStopNum", "JulianDate")]),
          setequal(wide$site, raw$RouteNumStopNum),
          all(raw$Pcru %in% 0:3))

y <- as.matrix(wide[response_names])
storage.mode(y) <- "numeric"
stopifnot(all(y[!is.na(y)] %in% 0:1),
          sum(!is.na(y)) == nrow(raw),
          sum(y, na.rm = TRUE) == sum(raw$Pcru > 0),
          all(rowSums(!is.na(y)) >= 1))

cat("Actual site-visit records:", nrow(raw), "\n")
Actual site-visit records: 337 
cat("Distinct sites:", nrow(wide), "\n")
Distinct sites: 130 
cat("Positive calling observations:", sum(y, na.rm = TRUE), "\n")
Positive calling observations: 140 

2. Detection histories tell us what was heard, not what was present

A history such as 101 means the species was heard on the first and third recorded occasions, but not on the second. A history like 00- means two non-detections and one unrecorded visit. The dash matters: recording it as a third zero would pretend that an observer visited and failed to hear the frog.

We calculate the fraction of sites with at least one positive call, sometimes called naive occupancy. In these source observations the frogs were recorded at 96 of 130 sites (73.8%). That is an observed-site detection fraction, not an adjusted ecological occupancy estimate; sites with fewer visits also had fewer opportunities for detection.

# 02 | Observed histories and naive site detection
n_visits <- rowSums(!is.na(y))
ever_detected <- rowSums(y, na.rm = TRUE) > 0
naive_fraction <- mean(ever_detected)

site_summary <- data.frame(
  site = wide$site,
  visits = n_visits,
  ever_detected = as.integer(ever_detected)
)
visit_summary <- data.frame(
  visits_per_site = 1:3,
  sites = as.integer(table(factor(n_visits, levels = 1:3))),
  sites_with_detection = vapply(1:3, function(k) {
    sum(ever_detected[n_visits == k])
  }, numeric(1))
)
visit_summary$observed_fraction <-
  visit_summary$sites_with_detection / visit_summary$sites

history_string <- apply(y, 1, function(x) {
  paste(ifelse(is.na(x), "-", as.character(as.integer(x))), collapse = "")
})
history_counts <- as.data.frame(table(history_string),
                                stringsAsFactors = FALSE)
names(history_counts) <- c("history", "sites")
history_counts <- history_counts[
  order(-history_counts$sites, history_counts$history), ]
row.names(history_counts) <- NULL

survey_days <- sort(unique(raw$JulianDate))
observed_by_day <- data.frame(
  JulianDate = survey_days,
  visits = vapply(survey_days, function(d) {
    sum(raw$JulianDate == d)
  }, numeric(1)),
  detections = vapply(survey_days, function(d) {
    sum(raw$Pcru[raw$JulianDate == d] > 0)
  }, numeric(1))
)
observed_by_day$detection_fraction <-
  observed_by_day$detections / observed_by_day$visits

write.csv(site_summary,
          file.path(out_dir, "01_site_detection_by_site.csv"),
          row.names = FALSE)
write.csv(visit_summary,
          file.path(out_dir, "02_visit_coverage.csv"),
          row.names = FALSE)
write.csv(history_counts,
          file.path(out_dir, "03_detection_history_counts.csv"),
          row.names = FALSE)
write.csv(observed_by_day,
          file.path(out_dir, "04_observed_by_survey_day.csv"),
          row.names = FALSE)

cat(sprintf("Naive observed site-detection fraction: %.1f%% (%d/%d sites)\n",
            100 * naive_fraction, sum(ever_detected), nrow(y)))
Naive observed site-detection fraction: 73.8% (96/130 sites)
print(visit_summary)
  visits_per_site sites sites_with_detection observed_fraction
1               1    20                   17         0.8500000
2               2    13                    3         0.2307692
3               3    97                   76         0.7835052

The visit-coverage table shows a notable imbalance: 17 of 20 one-visit sites have a positive call, compared with 3 of 13 two-visit sites and 76 of 97 three-visit sites. This is not evidence that more visits reduce detection; the site groups and survey dates differ. Among the repeated histories, 110 occurs at 36 sites, 100 at 34, and 000 at 21. The day-level summaries are descriptive, not a controlled seasonal experiment: monitoring routes and sites may differ from one date to another.

3. Separate the environmental state from observation conditions

The model’s occupancy formula is intercept-only: the source provides no suitable site-level habitat predictor. The detection formula can change with recorded Julian survey day or the number of minutes relative to sunset. Both are centered and divided by their observed standard deviations to stabilize numerical estimation.

unmarkedFrameOccu() arranges the binary responses into a site-by-visit matrix and links each recorded visit to the corresponding date and sunset-time covariates. The 53 NA response cells remain missing, rather than being misclassified as non-detections. The observed standard deviations used for standardization are approximately 31.84 Julian days and 45.22 minutes relative to sunset; these define the scales of the model coefficients.

# 03 | Organize visit-level predictors for the observation process
julian_day <- as.matrix(wide[paste0("JulianDate.", 1:3)])
minutes_after_sunset <- as.matrix(wide[paste0("MinAfterSunset.", 1:3)])
storage.mode(julian_day) <- "numeric"
storage.mode(minutes_after_sunset) <- "numeric"

# Compare dimensions and element-wise NA positions, not whole-matrix
# identity: the response and covariate matrices have different column names.
stopifnot(
  identical(dim(julian_day), dim(y)),
  identical(dim(minutes_after_sunset), dim(y)),
  all(is.na(julian_day) == is.na(y)),
  all(is.na(minutes_after_sunset) == is.na(y))
)

day_center <- mean(julian_day, na.rm = TRUE)
day_scale <- sd(as.vector(julian_day), na.rm = TRUE)
sunset_center <- mean(minutes_after_sunset, na.rm = TRUE)
sunset_scale <- sd(as.vector(minutes_after_sunset), na.rm = TRUE)
stopifnot(day_scale > 0, sunset_scale > 0)

day_z <- (julian_day - day_center) / day_scale
sunset_z <- (minutes_after_sunset - sunset_center) / sunset_scale

frog_frame <- unmarked::unmarkedFrameOccu(
  y = y,
  obsCovs = list(day_z = day_z, sunset_z = sunset_z)
)
cat("Day standardization: mean =", day_center,
    ", SD =", day_scale, "\n")
Day standardization: mean = 127.3858 , SD = 31.84158 
cat("Sunset-minute standardization: mean =", sunset_center,
    ", SD =", sunset_scale, "\n")
Sunset-minute standardization: mean = 97.56677 , SD = 45.21558 

4. Fit the models without confusing the formula order

In unmarked::occu(), the first formula models detection and the second models occupancy. We deliberately compare three modest models fitted to the same 130 sites and the same observations:

  • constant detection and constant occupancy;
  • detection that changes with Julian survey day;
  • detection that changes with survey day and minutes after sunset.

The ecological occupancy component remains constant across sites in each candidate. AIC measures relative likelihood-based support while penalizing extra coefficients; it cannot establish biological correctness or validate the closure assumption. Numerical convergence and finite, positive covariance diagonals are explicitly checked before interpreting fitted probabilities.

# 04 | Estimate occupancy and detection with three specified models
# unmarked::occu expects detection ~ occupancy, in that order.
models <- list(
  "Constant detection" = unmarked::occu(~ 1 ~ 1, data = frog_frame),
  "Survey day" = unmarked::occu(~ day_z ~ 1, data = frog_frame),
  "Day and sunset" = unmarked::occu(~ day_z + sunset_z ~ 1,
                                   data = frog_frame)
)

valid_covariance <- vapply(models, function(fit) {
  v <- vcov(fit)
  all(is.finite(v)) && all(diag(v) > 0)
}, logical(1))
model_comparison <- data.frame(
  model = names(models),
  parameters = vapply(models, function(fit) {
    length(coef(fit))
  }, integer(1)),
  AIC = vapply(models, function(fit) as.numeric(fit@AIC), numeric(1)),
  convergence_code = vapply(models, function(fit) {
    as.integer(fit@opt$convergence)
  }, integer(1)),
  finite_positive_covariance_diagonal = unname(valid_covariance),
  row.names = NULL
)
model_comparison$delta_AIC <-
  model_comparison$AIC - min(model_comparison$AIC)
model_comparison <- model_comparison[order(model_comparison$AIC), ]
row.names(model_comparison) <- NULL

write.csv(model_comparison,
          file.path(out_dir, "05_model_comparison.csv"),
          row.names = FALSE)
print(model_comparison)
               model parameters      AIC convergence_code
1     Day and sunset          4 280.1481                0
2         Survey day          3 280.8742                0
3 Constant detection          2 461.0042                0
  finite_positive_covariance_diagonal   delta_AIC
1                                TRUE   0.0000000
2                                TRUE   0.7261426
3                                TRUE 180.8560927
if (any(model_comparison$convergence_code != 0L) ||
    !all(model_comparison$finite_positive_covariance_diagonal)) {
  stop("At least one fitted model failed convergence or covariance checks. ",
       "Inspect 05_model_comparison.csv before interpreting estimates.")
}

best_name <- model_comparison$model[1]
best_model <- models[[best_name]]
cat("Lowest-AIC candidate:", best_name, "\n")
Lowest-AIC candidate: Day and sunset 

The lowest-AIC candidate is Day and sunset, with AIC 280.15, compared with 280.87 for the survey-day model and 461.00 for constant detection. The additional sunset-time term reduces AIC by only 0.73 relative to the day-only model. That modest difference should not be presented as decisive support for the extra term. All three supplied fits have convergence code zero and finite, positive covariance diagonals; these numerical checks do not validate the closure assumption or establish causal effects of survey timing.

5. Express the fitted logits as probabilities

Logistic regression coefficients are on the log-odds scale. For a reader, a probability of occupancy \(\psi\) and a conditional probability of detection \(p\) are much easier to interpret. The predict() method also returns an approximate interval based on the fitted covariance matrix.

A prediction curve then holds minutes after sunset at the observed mean while varying survey day across the recorded range. When the selected model has no day term, its line is flat by construction. Prediction intervals convey model-parameter uncertainty, not the full range of future survey-to-survey outcomes.

Finally, using the fitted visit-specific detection probabilities, we calculate each site’s expected probability of at least one positive call, \(\psi[1-\prod_j(1-p_{ij})]\). Grouping those expectations by the number of visits provides an elementary diagnostic comparison. It is not a formal global goodness-of-fit test.

# 05 | Convert fitted logits to probabilities and check survey effort
reference_data <- data.frame(day_z = 0, sunset_z = 0)
model_estimates <- do.call(rbind, lapply(names(models), function(label) {
  psi <- predict(models[[label]], type = "state",
                           newdata = reference_data)
  p <- predict(models[[label]], type = "det",
                         newdata = reference_data)
  data.frame(
    model = label,
    naive_fraction = naive_fraction,
    psi = psi$Predicted[1],
    psi_lower = psi$lower[1],
    psi_upper = psi$upper[1],
    p_at_mean_survey = p$Predicted[1],
    p_lower = p$lower[1],
    p_upper = p$upper[1]
  )
}))
row.names(model_estimates) <- NULL
stopifnot(all(is.finite(unlist(model_estimates[-1]))),
          all(model_estimates$psi >= 0 & model_estimates$psi <= 1),
          all(model_estimates$p_at_mean_survey >= 0 &
              model_estimates$p_at_mean_survey <= 1))

prediction_days <- seq(min(julian_day, na.rm = TRUE),
                       max(julian_day, na.rm = TRUE), length.out = 100)
curve_data <- data.frame(
  day_z = (prediction_days - day_center) / day_scale,
  sunset_z = 0
)
detection_pred <- predict(best_model, type = "det",
                                    newdata = curve_data)
detection_curve <- data.frame(
  JulianDate = prediction_days,
  predicted_p = detection_pred$Predicted,
  lower = detection_pred$lower,
  upper = detection_pred$upper
)

# Probability of ever detecting the species: psi * [1 - product(1-p)].
recorded <- !is.na(y)
p_at_recorded_visits <- predict(
  best_model, type = "det",
  newdata = data.frame(day_z = day_z[recorded],
                       sunset_z = sunset_z[recorded])
)$Predicted
p_matrix <- matrix(NA_real_, nrow = nrow(y), ncol = ncol(y))
p_matrix[recorded] <- p_at_recorded_visits
psi_best <- model_estimates$psi[match(best_name, model_estimates$model)]
expected_any_detection <- psi_best * apply(p_matrix, 1, function(p) {
  1 - prod(1 - p[!is.na(p)])
})
calibration <- data.frame(
  visits_per_site = 1:3,
  sites = vapply(1:3, function(k) sum(n_visits == k), numeric(1)),
  observed_detected_sites = vapply(1:3, function(k) {
    sum(ever_detected[n_visits == k])
  }, numeric(1)),
  model_expected_detected_sites = vapply(1:3, function(k) {
    sum(expected_any_detection[n_visits == k])
  }, numeric(1))
)

write.csv(model_estimates,
          file.path(out_dir, "06_model_estimates.csv"), row.names = FALSE)
write.csv(detection_curve,
          file.path(out_dir, "07_detection_probability_curve.csv"),
          row.names = FALSE)
write.csv(calibration,
          file.path(out_dir, "08_effort_calibration.csv"), row.names = FALSE)
print(model_estimates)
               model naive_fraction       psi psi_lower psi_upper
1 Constant detection      0.7384615 0.9503621 0.5335218 0.9968896
2         Survey day      0.7384615 0.8114748 0.7212183 0.8774747
3     Day and sunset      0.7384615 0.8090299 0.7199338 0.8747148
  p_at_mean_survey   p_lower   p_upper
1        0.4380678 0.3586375 0.5208049
2        0.4735814 0.3740249 0.5752839
3        0.4814195 0.3805525 0.5838241
print(calibration)
  visits_per_site sites observed_detected_sites model_expected_detected_sites
1               1    20                      17                     13.947469
2               2    13                       3                      5.629232
3               3    97                      76                     77.074907

The candidate with the lowest AIC estimates \(\psi = \mathbf{0.809}\) (approximate model-based 95% interval: 0.720–0.875). The directly observed site-detection fraction is 73.8%, roughly 7.1 percentage points lower. These are distinct quantities: the first is a latent occupancy parameter under a particular model; the second is the fraction of sites with an observed call.

At mean recorded survey conditions, the selected model’s probability of hearing the species given that it occupies a site is 0.481, with approximate 95% interval 0.381–0.584. This is not the fraction of visits with a positive call, and it does not mean every occupied site is detectable with that same probability on all dates.

The constant-detection candidate instead estimates occupancy at 0.950, with an especially wide interval, 0.534–0.997. Thus the assumed detection process materially affects the inferred state probability. The intervals condition on each fitted model and do not capture uncertainty from model selection or possible violation of occupancy assumptions.

6. Read the five graphical answers

The following plots connect the raw evidence, the adjustment for non-detection and the model’s implied probability of hearing a frog. A positive call is evidence of detection; an unrecorded visit is no evidence either way.

# 06 | Figures: observed evidence, fitted states and detection
plot_theme <- theme_minimal(base_size = 13) +
  theme(plot.title.position = "plot",
        panel.grid.minor = element_blank())

figure_histories <- ggplot(history_counts,
                           aes(x = reorder(history, sites), y = sites)) +
  geom_col(fill = "#286D75") + coord_flip() +
  labs(title = "Repeated survey histories are not all identical",
       subtitle = "1 = heard, 0 = not heard, – = no recorded visit",
       x = "Site history (visits in date order)", y = "Number of sites") +
  plot_theme

figure_observed <- ggplot(observed_by_day,
                          aes(x = JulianDate, y = detection_fraction)) +
  geom_point(aes(size = visits), color = "#207A8C", alpha = 0.85) +
  scale_y_continuous(labels = function(x) paste0(round(100*x), "%"),
                     limits = c(0, 1)) +
  scale_size_continuous(name = "Visits that day", range = c(2, 5)) +
  labs(title = "Recorded calling is not constant across survey dates",
       subtitle = "Raw visit-level fractions; routes and sites may differ by day",
       x = "Julian day of 2001", y = "Visits with a positive calling index") +
  plot_theme

psi_points <- rbind(
  data.frame(label = "Naive observed site fraction",
             estimate = naive_fraction, lower = NA_real_, upper = NA_real_),
  data.frame(label = paste("Model:", model_estimates$model),
             estimate = model_estimates$psi,
             lower = model_estimates$psi_lower,
             upper = model_estimates$psi_upper)
)
psi_points$label <- factor(psi_points$label, levels = rev(psi_points$label))
figure_occupancy <- ggplot(psi_points,
                           aes(x = estimate, y = label)) +
  geom_segment(aes(x = lower, xend = upper, yend = label),
               linewidth = 0.8, color = "#286D75", na.rm = TRUE) +
  geom_point(size = 3, color = "#BD5B32") +
  scale_x_continuous(limits = c(0, 1), labels = function(x) paste0(100*x, "%")) +
  labs(title = "Observed detection versus estimated occupancy",
       subtitle = "Intervals are model-based 95% Wald intervals; no interval for the naive fraction",
       x = "Proportion / probability", y = NULL) +
  plot_theme

figure_detection <- ggplot(detection_curve, aes(x = JulianDate)) +
  geom_ribbon(aes(ymin = lower, ymax = upper),
              fill = "#7EB8C2", alpha = 0.34) +
  geom_line(aes(y = predicted_p), color = "#1C6477", linewidth = 1.15) +
  scale_y_continuous(limits = c(0, 1),
                     labels = function(x) paste0(100*x, "%")) +
  labs(title = paste("Predicted detection probability:", best_name),
       subtitle = "Conditional on occupancy; sunset minutes fixed at their observed mean",
       x = "Julian day of 2001", y = "Probability of hearing a frog") +
  plot_theme

calibration_long <- rbind(
  data.frame(visits = factor(calibration$visits_per_site),
             series = "Observed sites with a call",
             sites = calibration$observed_detected_sites),
  data.frame(visits = factor(calibration$visits_per_site),
             series = "Expected under fitted model",
             sites = calibration$model_expected_detected_sites)
)
figure_calibration <- ggplot(calibration_long,
                            aes(x = visits, y = sites, fill = series)) +
  geom_col(position = position_dodge(width = 0.76), width = 0.65) +
  scale_fill_manual(values = c("Observed sites with a call" = "#286D75",
                               "Expected under fitted model" = "#D49E68")) +
  labs(title = "A simple check by the number of recorded visits",
       subtitle = "Model expectation is descriptive, not a formal goodness-of-fit test",
       x = "Recorded visits per site", y = "Sites with at least one call",
       fill = NULL) +
  plot_theme + theme(legend.position = "bottom")

figures <- list(
  "fig01_detection_histories.png" = figure_histories,
  "fig02_observed_by_survey_day.png" = figure_observed,
  "fig03_naive_vs_adjusted_occupancy.png" = figure_occupancy,
  "fig04_detection_probability.png" = figure_detection,
  "fig05_effort_calibration.png" = figure_calibration
)
for (filename in names(figures)) {
  ggsave(file.path(out_dir, filename), plot = figures[[filename]],
         width = 9.2, height = 5.4, dpi = 240, bg = "white")
}
if (interactive()) print(figure_occupancy)

Which survey histories were observed?

The first two histories (110 and 100) together account for 70 sites; the 000 group contains 21 sites. These sequences demonstrate that repeated visits convey more information than a single ever-detected indicator. A dash represents an unrecorded occasion, not a negative survey.

Observed spring-peeper detection histories at 130 monitoring sites; a dash marks a visit that was not recorded.

Observed spring-peeper detection histories at 130 monitoring sites; a dash marks a visit that was not recorded.

Does the observed fraction of positive calls depend on survey date?

The date-specific observations show high calling fractions on several early survey dates and many zeros later. The plotted fractions may be based on different routes and sets of sites, and each date has its own denominator. This pattern motivated the date covariate, but is not a within-site causal estimate of seasonal calling behavior.

Fraction of positive calling observations by Julian survey day in 2001; point size shows the number of recorded visits that day.

Fraction of positive calling observations by Julian survey day in 2001; point size shows the number of recorded visits that day.

How does the naive fraction compare with fitted occupancy?

The naive fraction is 73.8%, while the two survey-day models give occupancy estimates close to 81%. The constant-detection estimate is much higher and substantially less precise. The plotted 95% Wald intervals describe uncertainty conditional on each fitted formula; the naive fraction is shown as a point without a confidence interval in this visualization. The figure neither proves the correct model was chosen nor tests the closure assumption.

Naive fraction of spring-peeper detected sites versus occupancy probability estimates for three fitted models; horizontal segments show model-based uncertainty only.

Naive fraction of spring-peeper detected sites versus occupancy probability estimates for three fitted models; horizontal segments show model-based uncertainty only.

How does predicted detection change with survey day?

Holding minutes after sunset at its recorded mean, the selected fitted model predicts a 99.4% chance of hearing a frog at an occupied site on the first observed Julian day and 0.7% on the last. The sharp decline is a conditional model prediction, not proof that the same occupied sites became unavailable at that rate. The shaded band represents parameter uncertainty given the selected formula; site composition, potential occupancy change, and unmeasured survey conditions remain limitations.

Fitted probability of detecting a spring peeper at an occupied site across the sampled Julian days, with approximate model-based 95% interval and mean minutes-after-sunset held fixed.

Fitted probability of detecting a spring peeper at an occupied site across the sampled Julian days, with approximate model-based 95% interval and mean minutes-after-sunset held fixed.

Does the model reproduce detection patterns across survey effort?

The selected model predicts the number of sites with at least one positive call by combining fitted occupancy with the detection probabilities for each site’s actual recorded visits. For the one-visit sites, it expects 13.95 positives versus 17 observed; for the two-visit sites, 5.63 versus 3; and for the three-visit sites, 77.07 versus 76. The differences, particularly among sites with one or two visits, warrant scrutiny. These are descriptive checks, not a formal goodness-of-fit test.

Observed number of sites with at least one positive call versus expected number under the selected occupancy model, stratified by recorded visit count.

Observed number of sites with at least one positive call versus expected number under the selected occupancy model, stratified by recorded visit count.

7. What should a careful analyst conclude?

The key conclusion is inferential, not a census: the 73.8% directly observed site-detection fraction and the approximately 80.9% model-based occupancy estimate answer different questions. The large fitted decline in detection across survey dates reinforces the need to model the observation process, but its ecological interpretation remains constrained by field-design assumptions.

The useful lesson for a thesis is methodological: plan repeated visits within a biologically defensible closure window, distinguish zero from not surveyed, and record plausible detection covariates. At the repeatedly visited sites here, first-to-last survey intervals range from 31 to 96 days (median 78 days). This is a serious challenge for the constant-site-state assumption: site occupancy may change, even while the model assigns all calendar variation to the detection process. A Julian-day detection coefficient cannot repair actual occupancy changes.

The standard model also assumes no false-positive species identifications and sufficiently independent repeated detections, conditional on its predictors and latent states. Shared monitoring routes, unobserved site conditions, and calling phenology may complicate these assumptions. Accordingly, the fitted 80.9% occupancy is a model-dependent teaching estimate, not a confirmed proportion of occupied Delaware wetlands in 2001, a species-abundance estimate, or evidence of population change through 2026. These model checks are not a substitute for a field-design review or dedicated sensitivity analysis.

# 07 | Preserve model diagnostics and the native R session
model_text <- unlist(lapply(names(models), function(label) {
  c(paste("###", label),
    capture.output(print(summary(models[[label]]))), "")
}))
writeLines(model_text,
           file.path(out_dir, "09_model_summaries.txt"))
writeLines(capture.output(sessionInfo()),
           file.path(out_dir, "10_R_session_info.txt"))

cat(sprintf("Observed ever-detected sites: %d of %d (%.1f%%)\n",
            sum(ever_detected), nrow(y), 100 * naive_fraction))
Observed ever-detected sites: 96 of 130 (73.8%)
cat(sprintf("Lowest-AIC model: %s; estimated occupancy = %.3f\n",
            best_name, psi_best))
Lowest-AIC model: Day and sunset; estimated occupancy = 0.809
cat("AIC preference does not establish the closure assumption.\n")
AIC preference does not establish the closure assumption.
cat("Interpretation must consider closure and false-positive assumptions.\n")
Interpretation must consider closure and false-positive assumptions.

Sources and further reading

Comments