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.003472 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 34.72 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.125 seconds (Warm-up)
#> Chain 1:                8.685 seconds (Sampling)
#> Chain 1:                8.81 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.09, 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
#>  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.36      0.34     0.01     1.32 1.00       39       79
#> 
#> Multilevel Hyperparameters:
#> ~species (Number of levels: 30) 
#>                   Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
#> sd(Intercept)         0.92      0.14     0.68     1.25 1.01       68      108
#> sd(occ_Intercept)     0.87      0.16     0.61     1.19 1.05       32       23
#> 
#> Regression Coefficients:
#>               Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
#> Intercept         0.13      0.17    -0.19     0.43 1.04       43       86
#> occ_Intercept     0.10      0.22    -0.31     0.51 1.00       33       77
#> uc1               0.25      0.06     0.11     0.38 1.00      178      139
#> ec1               0.19      0.04     0.11     0.27 1.00      157       78
#> occ_suc1_1        0.39      0.72    -1.09     1.74 1.01       47       83
#> 
#> 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).
# }