Fit an occupancy model
flock(
f_occ = NULL,
f_det,
flocker_data,
data2 = NULL,
multiseason = NULL,
f_col = NULL,
f_ex = NULL,
multi_init = NULL,
f_auto = NULL,
augmented = FALSE,
threads = NULL,
...
)
A brms-type model formula for occupancy. If provided, must begin with "~".
A brms-type model formula for detection. Must begin with "~".
OR, a brmsformula
object including formulas for all of the relevant
distributional parameters in the desired model (det and at least one of occ,
colo, ex, autologistic, and Omega). The $formula
element of the
brmsformula
must be the detection formula, beginning with det ~
.
This latter option unadvisable except when necessary (e.g. when a nonlinear
formula is desired), as input checking is less thorough.
data, generally the output of make_flocker_data()
.
additional data (e.g. a covariance matrix for a phylogenetic effect)
Must be NULL (the default) or one of "colex" or "autologistic". If NULL, data must be formatted for a single-season model. Otherwise, the data must be formatted for a multiseason model. If "colex", a colonization-extinction model will be fit, and `f_col` and `f_ex` must be specified. If "autologistic", an autologistic model will be fit, and `f_col` and `f_ex` must both be NULL.
A brms-type model formula for colonization in colonization-extinction dynamic models. If provided, must begin with "~".
A brms-type model formula for extinction probabilities in colonization-extinction dynamic models. If provided, must begin with "~".
Must be NULL unless the model is a dynamic (multiseason) model, in which case must be either "explicit" or "equilibrium". If "explicit", then `f_occ` must be provided to model occupancy probabilities in the first timestep. If "equilibrium", then `f_occ` must be `NULL` and the initial occupancy probabilities are assumed to be the (possibly site-specific) equilibrium probabilities from the colonization- extinction dynamics.
Relevant only for autologistic models. A brms-type model formula for the autologistic offset parameter (theta). If provided, must begin with "~".
Logical. Must be TRUE if data are formatted for a data-augmented multi-species model, and FALSE otherwise.
NULL or positive integer. If integer, the number of threads to use per chain in within chain parallelization. Currently available only with single-season rep-constant models, and must be set to NULL otherwise.
additional arguments passed to brms::brm()
a brmsfit
containing the fitted occupancy model.
# \donttest{
sfd <- simulate_flocker_data()
fd <- make_flocker_data(
sfd$obs,
sfd$unit_covs,
sfd$event_covs
)
#> Formatting data for a single-season occupancy model. For details, see make_flocker_data_static. All warnings and error messages should be interpreted in the context of make_flocker_data_static
flock(
f_occ = ~ s(uc1) + (1|species),
f_det = ~ uc1 + ec1 + (1|species),
flocker_data = fd,
refresh = 50, chains = 1, warmup = 5, iter = 200,
control = list(adapt_engaged = FALSE, stepsize = .05, max_treedepth = 5),
seed = 123
)
#> Compiling Stan program...
#> Start sampling
#>
#> SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 1).
#> Chain 1:
#> Chain 1: Gradient evaluation took 0.006651 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 66.51 seconds.
#> Chain 1: Adjust your expectations accordingly!
#> Chain 1:
#> Chain 1:
#> Chain 1: Iteration: 1 / 200 [ 0%] (Warmup)
#> Chain 1: Iteration: 6 / 200 [ 3%] (Sampling)
#> Chain 1: Iteration: 55 / 200 [ 27%] (Sampling)
#> Chain 1: Iteration: 105 / 200 [ 52%] (Sampling)
#> Chain 1: Iteration: 155 / 200 [ 77%] (Sampling)
#> Chain 1: Iteration: 200 / 200 [100%] (Sampling)
#> Chain 1:
#> Chain 1: Elapsed Time: 0.431 seconds (Warm-up)
#> Chain 1: 29.86 seconds (Sampling)
#> Chain 1: 30.291 seconds (Total)
#> Chain 1:
#> Warning: There were 195 transitions after warmup that exceeded the maximum treedepth. Increase max_treedepth above 5. See
#> https://mc-stan.org/misc/warnings.html#maximum-treedepth-exceeded
#> Warning: There were 1 chains where the estimated Bayesian Fraction of Missing Information was low. See
#> https://mc-stan.org/misc/warnings.html#bfmi-low
#> Warning: Examine the pairs() plot to diagnose sampling problems
#> Warning: The largest R-hat is 1.12, indicating chains have not mixed.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#r-hat
#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#bulk-ess
#> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#tail-ess
#> Warning: Parts of the model have not converged (some Rhats are > 1.05). Be careful when analysing the results! We recommend running more iterations and/or setting stronger priors.
#> Family: occupancy_single
#> Links: mu = identity; occ = identity
#> Formula: ff_y | vint(ff_n_unit, ff_n_rep, ff_Q, ff_rep_index1, ff_rep_index2, ff_rep_index3, ff_rep_index4) ~ uc1 + ec1 + (1 | species)
#> occ ~ s(uc1) + (1 | species)
#> Data: data (Number of observations: 6000)
#> Draws: 1 chains, each with iter = 200; warmup = 5; thin = 1;
#> total post-warmup draws = 195
#>
#> Smooth Terms:
#> Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
#> sds(occ_suc1_1) 0.84 0.61 0.01 2.43 1.01 21 21
#>
#> Group-Level Effects:
#> ~species (Number of levels: 30)
#> Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
#> sd(Intercept) 0.85 0.15 0.60 1.12 0.99 73 49
#> sd(occ_Intercept) 0.98 0.18 0.73 1.40 1.06 70 25
#>
#> Population-Level Effects:
#> Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
#> Intercept 0.26 0.18 -0.05 0.61 1.00 59 59
#> occ_Intercept -0.06 0.21 -0.48 0.35 1.00 34 104
#> uc1 0.07 0.06 -0.04 0.17 1.00 257 164
#> ec1 0.31 0.05 0.21 0.39 1.00 241 173
#> occ_suc1_1 -1.92 1.67 -5.48 0.42 1.12 10 48
#>
#> Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
#> and Tail_ESS are effective sample size measures, and Rhat is the potential
#> scale reduction factor on split chains (at convergence, Rhat = 1).
# }