--- title: "Use from one night to the next" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Use from one night to the next} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r setup, include = FALSE} # The fit takes about 35 minutes on 8 cores (97,806 occasions) and the # cross-validation 50 fits on AWS, so the results were saved by # dev/precompute-dynamic.R and dev/dyn-kfold/ and are read from # dynamic-results.rds. knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 6.5, fig.height = 4, out.width = "100%") invisible(Sys.setlocale("LC_TIME", "C")) # month names in English library(crywolf) res <- readRDS("dynamic-results.rds") row <- function(var) res$summary[res$summary$variable == var, ] ci <- function(var, digits = 2) { r <- row(var) sprintf(paste0("%.", digits, "f (%.", digits, "f to %.", digits, "f)"), r$mean, r$lower, r$upper) } cv <- res$cv$total pika <- res$pika pal <- c("#0072B2", "#D55E00", "#009E73", "#CC79A7", "#E69F00") fig_theme <- ggplot2::theme_minimal() + ggplot2::theme(panel.grid.minor = ggplot2::element_blank()) pika_ci <- function(var, digits = 2) { r <- pika$summary[pika$summary$variable == var, ] sprintf(paste0("%.", digits, "f (%.", digits, "f to %.", digits, "f)"), r$mean, r$lower, r$upper) } prob_ci <- function(var) { r <- pika$summary[pika$summary$variable == var, ] sprintf("%.3f (%.3f to %.3f)", plogis(r$mean), plogis(r$lower), plogis(r$upper)) } long_draws <- function(d) { data.frame(variable = rep(names(d), each = nrow(d)), value = unlist(d, use.names = FALSE)) } pair <- function(name) { r <- res$cv$pairs[res$cv$pairs$comparison == name, ] sprintf("%.1f (SE %.1f)", r$diff, r$se) } ``` ```{r stale, echo = FALSE, results = "asis"} cat(crywolf:::.stale_note(res, "dynamic-results.rds")) ``` The other articles on the `curiango` data (Piatti et al., 2026) treat each site-night as an independent site. A recorder that picked up the Common Pauraque last night is then no more likely to pick it up tonight than one that has been silent for a month. `fp_occu_dyn()` drops that assumption. It fits the dynamic occupancy model (MacKenzie et al., 2003) with the false positives of the multiple-methods design (Miller et al., 2013), with the nights of each site as seasons. This article fits it to the `curiango` data, compares it with the model of independent site-nights by blocked cross-validation, reports how it behaved in simulations, and applies it to a second data set. ## The model Each site $i$ is in use ($z_{it} = 1$) or not ($z_{it} = 0$) on night $t$. On the first night, $\Pr(z_{i1} = 1) = \psi_1$. On every later night, the state follows a Markov chain: $$ \Pr(z_{it} = 1 \mid z_{i,t-1} = 0) = \gamma_{it}, \qquad \Pr(z_{it} = 0 \mid z_{i,t-1} = 1) = \epsilon_{it}, $$ where the colonization $\gamma_{it}$ and the extinction $\epsilon_{it}$ have logit-linear predictors (`col` and `ext`). Within a night, the observation model is that of `fp_occu()`: true detections with probability $p_{11}$ on nights in use, false positives with probability $p_{10}$ on every night, and verified recordings that settle what was recorded. The states are summed out by the forward algorithm, so the model has no latent discrete parameters for Stan to sample. ```{r dag, echo = FALSE, out.width = "100%", fig.cap = "Directed acyclic graph of the model fitted by `fp_occu_dyn()`. Hexagons are priors (defaults of `fp_priors()`), yellow ellipses are parameters, blue boxes are covariates, green ellipses are latent quantities and linear predictors, and octagons are the observed data. Dashed outlines mark optional components. The false-positive coefficients are called eta here because gamma is colonization. The options `markov`, `random_det` and `random_fp` are not drawn."} knitr::include_graphics("dynamic-dag.png") ``` With nights as seasons, "occupancy" means use of the site on a given night. Colonization is the start of use after a night without it, and extinction is the end of use after a night with it. Neither is a change in the population of the site. `fp_data(season = )` takes the column of the night. When the seasons are dates, it fills in the dates without data, so that every transition spans one night. A site without data on a night contributes to that night only through the transitions. In `curiango`, the nights run from 25 November 2023 to 26 February 2025, with between `r min(res$sites_per_night)` and `r max(res$sites_per_night)` of the seven sites recorded on each night. ## Fitting The colonization and the extinction depend on the temperature and relative humidity of the night. Transitions into nights without data need these covariates too, so we use the mean over the sites recorded on each date (`temp_d`, `rh_d`), passed as season covariates. Every date has at least one site recorded. Detection depends on the soundscape indices of each minute, and the false-positive rate on the temperature and humidity at the site that night. ```{r fit, eval = FALSE} zs <- function(v) as.numeric(scale(v)) m <- curiango$minutes nt <- curiango$nights daily <- aggregate(cbind(temp, rh) ~ night, nt, mean) daily <- data.frame(night = daily$night, temp_d = zs(daily$temp), rh_d = zs(daily$rh)) i <- match(m$site_night, nt$site_night) auto <- data.frame(site = m$site, night = nt$night[i], time = m$time, y = as.integer(m$conf_custom >= 0.40), bio = zs(m$bio), aci = zs(m$aci), temp = zs(nt$temp[i]), rh = zs(nt$rh[i]), recorder = m$site) ver <- data.frame(site = curiango$verified$site, night = nt$night[match(curiango$verified$site_night, nt$site_night)], y = curiango$verified$y) d <- fp_data(auto, data.frame(site = unique(auto$site)), ver, site = "site", recorder = "recorder", season = "night", season_covs = daily) fit <- fp_occu_dyn(d, psi1 = ~ 1, col = ~ temp_d + rh_d, ext = ~ temp_d + rh_d, det = ~ bio + aci, fp = ~ temp + rh, threads_per_chain = 2) ``` The fit took about `r round(res$minutes)` minutes with four chains of two threads. It converged: the largest R-hat was `r sprintf("%.3f", res$diagnostics$max_rhat)`, the smallest bulk effective sample size `r round(res$diagnostics$min_ess_bulk)`, with `r res$diagnostics$divergences` divergent transitions. ## Results ```{r estimates, echo = FALSE, fig.height = 4.5, fig.cap = "Posterior distributions of the parameters of `curiango`, from 1,000 draws. Points are medians, and the thick and thin bars are the 66% and 95% intervals. Coefficients are on the logit scale, and the dashed line marks zero."} est <- long_draws(res$draws) est$panel <- factor(ifelse(startsWith(est$variable, "col_"), "Colonization (logit)", ifelse(startsWith(est$variable, "ext_"), "Extinction (logit)", est$variable)), c("Colonization (logit)", "Extinction (logit)", "p11_ref", "p10_ref")) est$term <- factor(ifelse(grepl("Intercept", est$variable), "Intercept", ifelse(grepl("temp", est$variable), "Temperature", ifelse(grepl("rh", est$variable), "Humidity", " "))), c(" ", "Humidity", "Temperature", "Intercept")) zero <- data.frame(panel = factor(c("Colonization (logit)", "Extinction (logit)"), levels(est$panel)), x = 0) ggplot2::ggplot(est, ggplot2::aes(value, term)) + ggplot2::geom_vline(ggplot2::aes(xintercept = x), zero, linetype = "dashed", colour = "grey60") + ggdist::stat_halfeye(fill = pal[1], alpha = 0.8, .width = c(0.66, 0.95), point_size = 1.5, normalize = "groups") + ggplot2::facet_wrap(~ panel, scales = "free") + ggplot2::labs(x = NULL, y = NULL) + fig_theme ``` On a night of average temperature and humidity, a site not in use starts being used with probability `r sprintf("%.3f", plogis(row("col_(Intercept)")$mean))`. A site in use stops with probability `r sprintf("%.2f", plogis(row("ext_(Intercept)")$mean))`, so a spell of use lasts about `r round(1 / plogis(row("ext_(Intercept)")$mean), 1)` nights on average. Humid nights start fewer spells: the humidity coefficient of colonization is `r ci("col_rh_d")`. Its coefficient of extinction, `r ci("ext_rh_d")`, points to humid nights also ending spells, but its interval reaches zero. The intervals of both temperature coefficients include zero. A minute of a night in use yields a true detection with probability `r ci("p11_ref", 3)` at the reference values. A minute yields a false positive with probability `r ci("p10_ref", 4)`. The model also estimates, for each night, the fraction of the seven sites in use (`psi_fs`, from the states sampled given all the data). On nights when a site was not recorded, its state is inferred from the nights around it. ```{r psi-fs, fig.cap = "Fraction of the seven sites in use on each night (posterior mean and 95% interval of psi_fs)."} fs <- res$summary[grepl("^psi_fs\\[", res$summary$variable), ] fs$night <- as.Date(fs$season) ggplot2::ggplot(fs, ggplot2::aes(night, mean)) + ggplot2::geom_ribbon(ggplot2::aes(ymin = lower, ymax = upper), fill = "#2DE2E6", alpha = 0.4) + ggplot2::geom_line(linewidth = 0.3) + ggplot2::labs(x = NULL, y = "Fraction of sites in use") + ggplot2::theme_minimal() ``` `fp_sites()` gives, for each site and night, the probability that the site was in use given all its data: ```{r use, fig.height = 3, fig.cap = "Probability that each site was in use on each night given all the data. Nights without recordings at a site are paler."} s <- res$sites rec <- paste(s$site, s$night) %in% paste(curiango$nights$site, curiango$nights$night) s$recorded <- ifelse(rec, "recorded", "not recorded") ggplot2::ggplot(s, ggplot2::aes(as.Date(night), site, fill = occupied, alpha = recorded)) + ggplot2::geom_tile() + ggplot2::scale_fill_viridis_c(limits = c(0, 1)) + ggplot2::scale_alpha_manual(values = c(recorded = 1, "not recorded" = 0.35)) + ggplot2::labs(x = NULL, y = NULL, fill = "Pr(in use)", alpha = NULL) + ggplot2::theme_minimal() ``` ### Posterior predictive check The posterior predictive check compares the detections of each site-night with those replicated from the fit. It gives p = `r res$ppc$p_value`: the observed discrepancy (median `r round(stats::median(res$ppc$fit_obs))`) exceeds the replicated one (median `r round(stats::median(res$ppc$fit_rep))`) on every draw. The model of independent site-nights fails this check by a similar margin (`vignette("markov")`). The misfit therefore lies within nights, where the minutes are taken as independent, and not in the dynamics across nights. `fp_occu_dyn(markov = )` adds the Markov term of `vignette("markov")` for runs of detections within a night. The next section compares it by cross-validation. ## Comparison with independent site-nights LOO cannot compare the two models here. The log-likelihood of `fp_occu_dyn()` has one value per site, because the nights of a site are not independent. With seven sites, leaving one out would remove a seventh of the data at a time. Instead, we cross-validated on blocks of nights. The dates were cut into weeks, and the weeks were dealt at random into ten folds, the same for every site. The first and the last week stayed in every training set, so that every fit spans the same nights. Each model was fitted ten times, each time without one fold. For the dynamic model, the left-out nights became nights without data, whose states are predicted from the neighbouring nights. The model of independent site-nights used the same detection, false-positive and recorder terms, with `occ ~ temp_d + rh_d`. The score of each site and fold is the log of the posterior predictive density of its left-out minutes and verified recordings (elpd). The comparison has five models. `dyn` is the fit above and `ind` the model of independent site-nights. `dyn_mk` and `ind_mk` add `markov = "time"`. `ind_rd` adds `random_det` to `ind`, a detection effect for each site-night, which competes with the dynamics for the variation between nights. ```{r cv, echo = FALSE, fig.height = 2.6, fig.cap = "Difference in elpd from `dyn` in the blocked cross-validation. Bars are two standard errors of the difference, and `dyn` itself has none."} cvd <- cv[order(cv$diff_from_dyn), ] cvd$model <- factor(cvd$model, cvd$model) ggplot2::ggplot(cvd, ggplot2::aes(diff_from_dyn, model)) + ggplot2::geom_vline(xintercept = 0, linetype = "dashed", colour = "grey60") + ggplot2::geom_pointrange(ggplot2::aes(xmin = diff_from_dyn - 2 * se_diff, xmax = diff_from_dyn + 2 * se_diff), colour = pal[1], size = 0.4) + ggplot2::labs(x = "elpd difference from dyn", y = NULL) + fig_theme ``` The dynamic model predicts the left-out nights better than the independent one, by `r pair("dyn - ind")` in elpd over `r res$cv_units` site and fold units. The same holds with the Markov term, by `r pair("dyn_mk - ind_mk")`. The Markov term itself gains more than the dynamics: `r pair("ind_mk - ind")` over `ind`. The two gains add up, and `dyn_mk` has the highest elpd in all ten folds and at all seven sites: ```{r cv-site, echo = FALSE, fig.height = 4, fig.cap = "Gain in elpd over `ind` at each site and in each fold. Positive values favour the model over independent site-nights."} gain <- function(x, id, label) { m <- c("dyn", "dyn_mk", "ind_mk", "ind_rd") do.call(rbind, lapply(m, function(k) { data.frame(unit = as.character(x[[id]]), model = k, panel = label, gain = x[[paste0("elpd.", k)]] - x$elpd.ind) })) } g <- rbind(gain(res$cv$by_site, "site", "By site"), gain(res$cv$by_fold, "fold", "By fold")) g$unit <- factor(g$unit, c(sort(unique(res$cv$by_site$site)), 10:1)) g$panel <- factor(g$panel, c("By site", "By fold")) ggplot2::ggplot(g, ggplot2::aes(gain, unit, colour = model, shape = model)) + ggplot2::geom_vline(xintercept = 0, linetype = "dashed", colour = "grey60") + ggplot2::geom_point(size = 2) + ggplot2::scale_colour_manual(values = pal[1:4]) + ggplot2::facet_wrap(~ panel, scales = "free_y") + ggplot2::labs(x = "elpd gain over ind", y = NULL, colour = NULL, shape = NULL) + fig_theme + ggplot2::theme(legend.position = "bottom") ``` `random_det` also improves on `ind`, by `r pair("ind_rd - ind")`, but less than the Markov term does. Runs of detections, then, explain more of these data than differences between nights alone. Three caveats apply. The SE treats the site and fold units as independent, although the units of a fold share a training fit, so it is likely too small. Each left-out week has nights in the training data on both sides, so the dynamic model interpolates as well as forecasts. And the elpd of `ind_rd` comes from 400 posterior draws, because integrating its effects is slow, against 4,000 for the other models. All 50 training fits converged; one fit of the independent model was rerun with another seed after a chain stuck in a second mode (see `dev/dyn-kfold/README.md` in the source repository). ## Validation in simulation We simulated data with `simulate_fp_dyn()` and fitted the model to them, in 6,320 tasks, with none ending in error. The criteria were set before the results, and the tables are in `dev/dyn-val/` in the source repository. All the designs had 100 sites. With p11 of at least 0.30 and at least 10% of site-seasons verified, the model was well calibrated. Coverage of the 95% intervals of initial occupancy, colonization, extinction, `p10_bar` and `psi_fs` was at least 0.90, and the absolute bias was at most 0.024. Observation-confirmation, with 10% or 30% of occasions confirmed, met the same thresholds. Simulation-based calibration found no departure from uniform ranks in 1,000 replicates. ```{r val-bias, echo = FALSE, fig.height = 6, fig.cap = "Bias of the posterior mean in the designs with low detection, by the fraction of site-seasons verified. Dashed lines mark the threshold of 0.05."} lowp <- res$val$lowp lowp$p11 <- factor(lowp$p11) lowp$seasons <- factor(paste(lowp$nseason, "seasons"), paste(c(3, 6, 10), "seasons")) val_plot <- function(y, line, label) { ggplot2::ggplot(lowp, ggplot2::aes(frac_verified, .data[[y]], colour = p11, shape = p11)) + ggplot2::geom_hline(yintercept = line, linetype = "dashed", colour = "grey60") + ggplot2::geom_line() + ggplot2::geom_point(size = 2) + ggplot2::scale_colour_manual(values = pal[1:2]) + ggplot2::facet_grid(param ~ seasons) + ggplot2::labs(x = "Fraction of site-seasons verified", y = label) + fig_theme + ggplot2::theme(legend.position = "bottom") } val_plot("bias", c(-0.05, 0.05), "Bias") ``` ```{r val-coverage, echo = FALSE, fig.height = 6, fig.cap = "Coverage of the 95% intervals in the same designs. The dashed line marks the threshold of 0.90."} val_plot("coverage", 0.90, "Coverage") ``` The limits lie at low detection with little verification: * With p11 = 0.15 and no verification, colonization was biased upwards by 0.12 to 0.17 and extinction by 0.09 to 0.13, and up to 40% of fits did not converge. * With p11 = 0.15 and 10% verified, both biases stayed above 0.05 with 3 or 6 seasons, and fell below it with 10 seasons. * With p11 = 0.15 and 20% or more verified, the thresholds were met. ```{r val-converged, echo = FALSE, fig.height = 2.8, fig.cap = "Fraction of the fits of each design cell with R-hat below 1.01. Each point is a cell, and the dashed line marks the threshold of 0.95."} cells <- res$val$lowp_fits cells$p11 <- factor(cells$p11) ggplot2::ggplot(cells, ggplot2::aes(factor(frac_verified), converged, colour = p11, shape = p11)) + ggplot2::geom_hline(yintercept = 0.95, linetype = "dashed", colour = "grey60") + ggplot2::geom_point(position = ggplot2::position_jitter(width = 0.2, height = 0, seed = 1), alpha = 0.7) + ggplot2::scale_colour_manual(values = pal[1:2]) + ggplot2::labs(x = "Fraction of site-seasons verified", y = "Fits converged") + fig_theme ``` Ignoring a source of variation was costly. When false positives varied with a covariate, `fp ~ 1` kept `psi_fs` nearly unbiased (at most 0.018), but the coverage of `p10_bar` fell to between 0.72 and 0.89. When site effects on detection had an SD of 1, leaving out `random_det` gave a bias of -0.10 in `psi_fs` and a coverage of 0.01. With runs of detections of strength 2 on the logit scale, leaving out `markov` gave a coverage of 0.44 for `psi_fs`. With the option on, both models recovered these quantities, with a coverage of at least 0.90 for `sd_det_site` and `det_y_prev`. ```{r val-omit, echo = FALSE, fig.height = 5, fig.cap = "Coverage of the 95% intervals when the data have a source of variation and the model leaves it out or includes it. The dashed line marks the threshold of 0.90. False positives on a covariate are shown for the design with 20% of site-seasons verified."} one <- function(x, scenario, on) { data.frame(scenario = scenario, param = x$param, coverage = x$coverage, model = ifelse(x$model == on, "Included", "Left out")) } ca <- res$val$calib ca <- ca[ca$b_fp == 1 & ca$frac_verified == 0.2, ] ra <- res$val$randet ma <- res$val$markov om <- rbind(one(ca, "fp on a covariate", "fp_x"), one(ra[ra$sd_det == 0.5, ], "Site effects, SD 0.5", "random_det"), one(ra[ra$sd_det == 1, ], "Site effects, SD 1", "random_det"), one(ma[ma$a == 1, ], "Runs, strength 1", "markov"), one(ma[ma$a == 2, ], "Runs, strength 2", "markov")) om <- om[om$param %in% c("col", "ext", "p10_bar", "psi_fs", "psi1"), ] om$scenario <- factor(om$scenario, unique(om$scenario)) ggplot2::ggplot(om, ggplot2::aes(coverage, param, colour = model, shape = model)) + ggplot2::geom_vline(xintercept = 0.90, linetype = "dashed", colour = "grey60") + ggplot2::geom_point(size = 2) + ggplot2::scale_colour_manual(values = pal[1:2]) + ggplot2::facet_wrap(~ scenario, ncol = 2) + ggplot2::labs(x = "Coverage", y = NULL, colour = NULL, shape = NULL) + fig_theme + ggplot2::theme(legend.position = "bottom") ``` With strong site effects, `random_det` needed longer chains. With an SD of 1 and 1,000 + 1,000 iterations, 93% of fits reached R-hat below 1.01. With 2,000 + 2,000 iterations on the same data, 99% did, and the estimates did not change. ## A second data set We also fitted the model to surveys of the American pika (*Ochotona princeps*) by Goldman et al. (2023), with 771 plots in five park units from 2010 to 2021. Years are the seasons, and 2015 and 2016 are seasons without data. Each survey gives one occasion for each ambiguous sign (fresh scat, fresh haypile, call), with the sign as a covariate of `det` and `fp`. Sightings and unambiguous fresh scat form the verified method. Unlike the article, this model does not give each sign its own detection process. The dynamic model has `psi1 ~ park`, with constant colonization and extinction. The independent model treats each plot-year as a site, with `occ ~ park + year`. All five fits had no divergent transitions, R-hat of at most `r sprintf("%.3f", max(sapply(pika$diagnostics, "[[", "max_rhat")))`, and a bulk effective sample size of at least `r round(min(sapply(pika$diagnostics, "[[", "min_ess_bulk")))`. ```{r pika-rates, echo = FALSE, fig.height = 3.6, fig.cap = "Posterior distributions of the rates of the pika model, from 1,000 draws. `psi_eq` is the occupancy implied by colonization and extinction at equilibrium."} pr <- pika$draws pr[c("col_(Intercept)", "ext_(Intercept)")] <- lapply(pr[c("col_(Intercept)", "ext_(Intercept)")], plogis) names(pr)[1:2] <- c("Colonization", "Extinction") pr <- long_draws(pr) pr$variable <- factor(pr$variable, unique(pr$variable)) ggplot2::ggplot(pr, ggplot2::aes(value)) + ggdist::stat_halfeye(fill = pal[1], alpha = 0.8, .width = c(0.66, 0.95), point_size = 1.5, normalize = "panels") + ggplot2::facet_wrap(~ variable, scales = "free_x", ncol = 3) + ggplot2::scale_y_continuous(breaks = NULL) + ggplot2::labs(x = "Probability", y = NULL) + fig_theme ``` Colonization was `r prob_ci("col_(Intercept)")` and extinction `r prob_ci("ext_(Intercept)")` per year. Occupancy at equilibrium was `r pika_ci("psi_eq")`. A call, the reference sign, was recorded on a survey of an occupied plot with probability `r pika_ci("p11_ref")`, and on a survey of an unoccupied plot with probability `r pika_ci("p10_ref", 3)`. Goldman et al. (2023) report about 0.06 for both colonization and extinction with a different model, so the comparison is only of order of magnitude. ```{r pika-occ, echo = FALSE, fig.height = 3.4, fig.cap = "Mean probability that the plots of each park unit were occupied in each year, given all the data. The shaded years have no surveys, so their states come from the years around them."} occ <- pika$occ_park occ$year <- as.numeric(as.character(occ$year)) ggplot2::ggplot(occ, ggplot2::aes(year, occupied, colour = park, shape = park)) + ggplot2::annotate("rect", xmin = 2014.5, xmax = 2016.5, ymin = -Inf, ymax = Inf, fill = "grey92") + ggplot2::geom_line() + ggplot2::geom_point(size = 2) + ggplot2::scale_colour_manual(values = pal) + ggplot2::scale_x_continuous(breaks = seq(2010, 2021, 2)) + ggplot2::labs(x = NULL, y = "Pr(occupied)", colour = NULL, shape = NULL) + fig_theme ``` Occupancy moved towards the equilibrium in most park units. Colonization and extinction are constant and shared in this model, so that movement is built in. It is not evidence of a trend in any park unit. The posterior predictive checks gave p = `r sprintf("%.2f", pika$ppc$dyn_auto$p_value)` for the automated method and p = `r sprintf("%.2f", pika$ppc$dyn_ver$p_value)` for the verified one, so the misfit seen on `curiango` did not appear here. The independent model gave p = `r sprintf("%.2f", pika$ppc$ind_auto$p_value)` for the automated method. ```{r pika-ppc, echo = FALSE, fig.height = 2.8, fig.cap = "Posterior predictive checks of the pika models. Each point is a draw, and points on the line have equal observed and replicated discrepancies."} pp <- do.call(rbind, Map(function(x, label) { data.frame(check = sprintf("%s (p = %.2f)", label, x$p_value), obs = x$fit_obs, rep = x$fit_rep) }, pika$ppc, c("dyn, automated", "dyn, verified", "ind, automated"))) pp$check <- factor(pp$check, unique(pp$check)) ggplot2::ggplot(pp, ggplot2::aes(obs, rep)) + ggplot2::geom_abline(linetype = "dashed", colour = "grey60") + ggplot2::geom_point(colour = pal[1], alpha = 0.4, size = 0.8) + ggplot2::facet_wrap(~ check, scales = "free") + ggplot2::labs(x = "Observed discrepancy", y = "Replicated discrepancy") + fig_theme ``` Prior means of 1 to 3 for `fp_gap`, and a doubled prior SD, left the estimates nearly unchanged. ```{r pika-priors, echo = FALSE, fig.height = 3.6, fig.cap = "Posterior means and 95% intervals of the pika model under four priors of `fp_gap`, on the scale of each parameter."} se <- pika$sensitivity se <- se[se$variable %in% c("col_(Intercept)", "ext_(Intercept)", "fp_gap", "p11_ref", "p10_ref", "psi_eq"), ] se$prior <- factor(se$prior, c("gap_wide", "gap_high", "gap_low", "default"), c("mean 2, SD 3", "mean 3", "mean 1", "default")) ggplot2::ggplot(se, ggplot2::aes(mean, prior)) + ggplot2::geom_pointrange(ggplot2::aes(xmin = lower, xmax = upper), colour = pal[1], size = 0.3) + ggplot2::facet_wrap(~ variable, scales = "free_x", ncol = 3) + ggplot2::labs(x = NULL, y = NULL) + fig_theme ``` Leaving out whole plots, PSIS-LOO favoured the dynamic model over independent plot-years by `r sprintf("%.1f (SE %.1f)", -pika$loo$elpd_diff[2], pika$loo$se_diff[2])` in elpd, with no Pareto k above 0.7. With 771 plots, leaving one out removes little of the data, which is why LOO works here and not on the seven sites of `curiango`. Two simplifications matter. The verified occasion shares its survey with the automated ones, and unambiguous scat is a subset of fresh scat, so the two methods are not fully independent given the state. The sign also enters `det` and `fp` as a covariate, whereas the article gives each sign its own model. The checks above also have a limit. Goldman et al. (2023) class fresh scat as unambiguous when a fresh haypile was seen on the same survey. In this design, the automated scat and haypile occasions therefore never coincide. We refitted the model with two other verified methods, which return that scat to the automated occasions: sightings and unambiguous scat without a fresh haypile, and sightings alone. Both fits converged, and both failed the check of the automated method (p = 0.00). The two signs then coincided on 423 surveys, 2.5 to 3 times the number expected from their marginal rates. Part of this excess may only reflect that occupied plots have more signs. Our reading, which we did not test, is that signs of one survey are more alike than the model allows. The good check above is therefore not evidence that the signs are independent. Because these two fits failed the check, they only suggest the size of the effect. Their `psi_eq` was 0.42 and 0.34, against 0.41 in a refit of the model above. Colonization fell from 0.048 to 0.038 and 0.035, and extinction from 0.071 to 0.053 and 0.068. The data are in `pika`, and the scripts are in `dev/dyn-pika/` in the source repository. ## When to use it * With repeated nights or visits at the same sites, use on one night is informative about the next, and the dynamic model uses that information. * Each season needs covariates for the transitions into it, including seasons without data. Choose covariates that exist on every night. * Compare with the independent model on blocks of seasons, not by LOO, whenever the sites are few. * Verify recordings in at least 10% of site-seasons, and more when detection is low. Without verification, colonization and extinction are biased at low detection. * Runs of detections are common in passive acoustic monitoring, where occasions are minutes close in time. Check for them and consider `markov`. * `fp_calibrate()` simulates only single-season designs, so it does not plan a dynamic study; `simulate_fp_dyn()` is the starting point for that. ## References Goldman, M. R., Shinderman, M., Jeffress, M. R., Rodhouse, T. J., & Shoemaker, K. T. (2023). Integrating multiple sign types to improve occupancy estimation for inconspicuous species. *Ecology and Evolution*, 13(5), e10019. https://doi.org/10.1002/ece3.10019 MacKenzie, D. I., Nichols, J. D., Hines, J. E., Knutson, M. G., & Franklin, A. B. (2003). Estimating site occupancy, colonization, and local extinction when a species is detected imperfectly. *Ecology*, 84(8), 2200–2207. https://doi.org/10.1890/02-3090 Miller, D. A. W., Nichols, J. D., Gude, J. A., Rich, L. N., Podruzny, K. M., Hines, J. E., & Mitchell, M. S. (2013). Determining occurrence dynamics when false positives occur: Estimating the range dynamics of wolves from public survey data. *PLoS ONE*, 8(6), e65808. https://doi.org/10.1371/journal.pone.0065808 Piatti, L., de Sousa, D. L. H., Oliveira, B. S., de Melo, A. V., Sugai, L. S. M., & Provete, D. B. (2026). Methodological choices influence ecological inference in passive acoustic monitoring of a Neotropical nightjar. *Journal of Avian Biology*, in press.