Calibration of a fitted model on data like the real ones
Source:R/fp_calibrate_fit.R
fp_calibrate_fit.RdAsks whether the credible intervals of a model would cover the truth in
data like the ones it was fitted to. The function simulates datasets from
the fit with simulate.fp_occu(), so that they keep the design of the
real data (sites, covariates, occasions, verification, recorders) and
follow the fitted model, refits each candidate model to every dataset,
and scores the coverage and bias of their intervals, as fp_calibrate()
does for designed simulations.
Arguments
- fit
An
fp_occuobject: the generating model.- models
Named list of false-positive formulas (or
NULLfor no false positives) to refit. The default refits the generating model. The occupancy and detection formulas, the recorder effect, and the priors are those offit.- reps
Number of simulated datasets.
- truth
"mean"(default) or"posterior"; seesimulate.fp_occu().- prob
Width of the credible intervals.
- base_seed
Seeds are
base_seed + 1, ..., base_seed + reps.- parallel, fit_args
As in
fp_calibrate().
Value
An object of class fp_calibration, as from fp_calibrate(),
with a single design cell.
Details
The scored quantities are the occupancy coefficients, the detection
coefficients, the intercept of the verified method, the mean
false-positive rate over sites (p10_bar, when both the generating and
the refitted model have false positives), and the slopes of the
false-positive rate in the refitted model. A slope that is not in the
generating model has a true value of zero.
The most useful comparison pits the model you fitted against a simpler
one. For example, if a model with fp = ~ temp + rh estimated clear
effects of the covariates on the false-positive rate, refitting
fp = ~ 1 to data simulated from it shows how much a constant rate would
bias the occupancy effects at your sample size and verification effort.
This answers the question for the fitted structure only: a dependence of
the false-positive rate on something you did not measure is not part of
the generating model.
Each replicate refits every model, so the cost is that of reps times
the number of models fits of the size of the real data. Use parallel
for large datasets; each fit runs on one thread per chain unless
fit_args sets threads_per_chain.
Examples
# \donttest{
sim <- simulate_fp(nsite = 300, nocc = 20, conf_effect = 1.5,
conf_cor = 0.7, seed = 1)
m_x <- fp_occu(sim$data, occ = ~ x, fp = ~ x, random_recorder = FALSE,
chains = 2, threads_per_chain = 1)
#> Running MCMC with 2 parallel chains, with 1 thread(s) per chain...
#>
#> Chain 1 finished in 25.5 seconds.
#> Chain 2 finished in 25.7 seconds.
#>
#> Both chains finished successfully.
#> Mean chain execution time: 25.6 seconds.
#> Total execution time: 25.8 seconds.
#>
cal <- fp_calibrate_fit(m_x, models = list(constant = ~ 1, fp_on_x = ~ x),
reps = 5,
fit_args = list(chains = 2, threads_per_chain = 1))
summary(cal)
#> Calibration summary (95% intervals)
#>
#> Occupancy slope:
#> cell model n failed coverage mc_se bias rmse prop_divergent verdict
#> 1 constant 5 0 0.8 0.18 0.126 0.19 0 low
#> 1 fp_on_x 5 0 1.0 0.00 -0.026 0.13 0 ok
#>
#> All quantities: inspect the returned tibble.
plot(cal, parameter = "occ_x")
# }