Learn R Programming

flocker: flexible occupancy estimation in R

The flocker R package enables users to fit flexible occupancy models using the extended lme4 formula syntax provided by R package brms. Also included are functions to format data for occupancy modeling and functions for model post-processing, including posterior predictions, the posterior distribution of the latent true occupancy state, and model comparison. flocker is under active development: development priorities include better integrated functionality for posterior predictive checking and full cross-validation.

Compared to existing R packages for fitting occupancy models, flocker is substantially more flexible in the variety of models that can be fit, and contains advanced functionality for model comparison and checking.

Getting started

To get started, check out our tutorial vignette, available here and our introductory paper, available here. For installation instructions, see below.

Installation

Install the latest CRAN release of flocker with

install.packages("flocker")

Install the current development version of flocker with

# install.packages("remotes")
remotes::install_github("jsocolar/flocker")

flocker requires a working version of either rstan or cmdstan, which are interfaces to Stan, a state-of-the-art the probabilistic programming language. We recommend using cmdstan if possible. To do so, first install R package cmdstanr with

install.packages("cmdstanr", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

You must additionally install cmdstan itself. We strongly recommend using cmdstanr to manage the cmdstan installation:

cmdstanr::install_cmdstan()

Both rstan and cmdstan require a working C++ toolchain, which has posed occasional complications for Stan users. See here for rstan focused advice on installing the toolchain, and see here for cmdstan focused advice. If you encounter toolchain issues that you are unable to troubleshoot, ask for help at https://discourse.mc-stan.org/.

Bugs, features, contributions

To request a feature or report a bug (much appreciated!) please open an issue at the GitHub repository. To contribute to flocker (very much appreciated!) have a look at existing open issues, or open a new issue to discuss.

Citing flocker

When using flocker, please cite the companion manuscript:

Additionally, please consider citing Stan and R package brms.

Copy Link

Version

Install

install.packages('flocker')

Monthly Downloads

162

Version

1.0-0

License

BSD_3_clause + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Jacob B. Socolar

Last Published

February 5th, 2024

Functions in flocker (1.0-0)

loo_compare_flocker

LOO comparisons for flocker models.
make_flocker_data_dynamic

Format data for dynamic (multi-season) occupancy model, to be passed to flock().
loo_flocker

Compute loo for flocker_fit objects
predict_flocker

Get posterior predictions from a flocker model
simulate_flocker_data

Simulate data for use with make_flocker_data() and downstream functions.
make_flocker_data_static

Format data for single-season occupancy model, to be passed to flock().
log_lik_flocker

Compute unit-wise or series-wise log-likelihood matrix for a flocker_fit object
flocker_stancode

Generate stan code for an occupancy model
log_inv_logit

Numerically stable log inverse logit
fitted_flocker

Posterior predictive distributions for modeled probabilities
flocker_standata

Generate stan data for an occupancy model
get_flocker_prior

Get prior for occupancy model
log1m_inv_logit

Numerically stable log one-minus inverse logit
get_Z

Get posterior distribution of the Z matrix
flock

Fit an occupancy model
example_flocker_model_single

Example single-season flocker model
make_flocker_data

Format data for occupancy model with flock().
make_flocker_data_augmented

#' Format data for data-augmented occupancy model, to be passed to flock().