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,
  ...
)

Arguments

f_occ

A brms-type model formula for occupancy. If provided, must begin with "~".

f_det

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.

flocker_data

data, generally the output of make_flocker_data().

data2

additional data (e.g. a covariance matrix for a phylogenetic effect)

multiseason

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.

f_col

A brms-type model formula for colonization in colonization-extinction dynamic models. If provided, must begin with "~".

f_ex

A brms-type model formula for extinction probabilities in colonization-extinction dynamic models. If provided, must begin with "~".

multi_init

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.

f_auto

Relevant only for autologistic models. A brms-type model formula for the autologistic offset parameter (theta). If provided, must begin with "~".

augmented

Logical. Must be TRUE if data are formatted for a data-augmented multi-species model, and FALSE otherwise.

threads

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()

Value

a brmsfit containing the fitted occupancy model.

Examples

# \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.003037 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 30.37 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.126 seconds (Warm-up)
#> Chain 1:                7.356 seconds (Sampling)
#> Chain 1:                7.482 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: Examine the pairs() plot to diagnose sampling problems
#> Warning: The largest R-hat is 1.16, 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
#> 
#> Smoothing Spline Hyperparameters:
#>                 Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
#> sds(occ_suc1_1)     0.45      0.41     0.03     1.51 1.01       27       52
#> 
#> Multilevel Hyperparameters:
#> ~species (Number of levels: 30) 
#>                   Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
#> sd(Intercept)         0.90      0.13     0.66     1.19 1.05       66       84
#> sd(occ_Intercept)     0.89      0.14     0.66     1.20 1.01       85       86
#> 
#> Regression Coefficients:
#>               Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
#> Intercept         0.10      0.18    -0.25     0.47 1.05       44       58
#> occ_Intercept     0.12      0.19    -0.23     0.53 1.01       47       93
#> uc1               0.26      0.06     0.15     0.37 1.00      191      180
#> ec1               0.18      0.04     0.10     0.25 1.01      185      133
#> occ_suc1_1        0.38      1.06    -1.98     2.84 1.04       18       19
#> 
#> 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).
# }