All Projects → kenkellner → ubms

kenkellner / ubms

Licence: GPL-3.0 license
Fit models to data from unmarked animals using Stan. Uses a similar interface to the R package 'unmarked', while providing the advantages of Bayesian inference and allowing estimation of random effects.

Programming Languages

r
7636 projects
Stan
76 projects
C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to ubms

Shinystan
shinystan R package and ShinyStan GUI
Stars: ✭ 172 (+537.04%)
Mutual labels:  stan
covidestim
Bayesian nowcasting with adjustment for delayed and incomplete reporting to estimate COVID-19 infections in the United States
Stars: ✭ 20 (-25.93%)
Mutual labels:  stan
HierarchicalAttentionNetworks
Hierarchical Attention Networks for Document Classification in Keras
Stars: ✭ 70 (+159.26%)
Mutual labels:  hierarchical-models
Stancon talks
Materials from Stan conferences
Stars: ✭ 210 (+677.78%)
Mutual labels:  stan
stan-distributions
A web app to visualize distributions in Stan. Uses Stan Math C++ compiled to Webassembly to evaluate the functions using actual Stan implementations. Uses d3.js for visualizations.
Stars: ✭ 30 (+11.11%)
Mutual labels:  stan
walker
Bayesian Generalized Linear Models with Time-Varying Coefficients
Stars: ✭ 38 (+40.74%)
Mutual labels:  stan
Stan.jl
Stan.jl illustrates the usage of the 'single method' packages, e.g. StanSample, StanOptimize, etc.
Stars: ✭ 163 (+503.7%)
Mutual labels:  stan
stan-ja
Stanマニュアルの日本語への翻訳プロジェクト
Stars: ✭ 53 (+96.3%)
Mutual labels:  stan
geostan
Bayesian spatial analysis
Stars: ✭ 40 (+48.15%)
Mutual labels:  stan
gsoc17-hhmm
Bayesian Hierarchical Hidden Markov Models applied to financial time series, a research replication project for Google Summer of Code 2017.
Stars: ✭ 102 (+277.78%)
Mutual labels:  stan
MathematicaStan
A Mathematica package to interact with CmdStan
Stars: ✭ 27 (+0%)
Mutual labels:  stan
metaBMA
Bayesian Model Averaging for Random and Fixed Effects Meta-Analysis
Stars: ✭ 20 (-25.93%)
Mutual labels:  stan
Hierarchical-Word-Sense-Disambiguation-using-WordNet-Senses
Word Sense Disambiguation using Word Specific models, All word models and Hierarchical models in Tensorflow
Stars: ✭ 33 (+22.22%)
Mutual labels:  hierarchical-models
Stan
Stan development repository. The master branch contains the current release. The develop branch contains the latest stable development. See the Developer Process Wiki for details.
Stars: ✭ 2,177 (+7962.96%)
Mutual labels:  stan
JoSH
[KDD 2020] Hierarchical Topic Mining via Joint Spherical Tree and Text Embedding
Stars: ✭ 55 (+103.7%)
Mutual labels:  hierarchical-models
Nats Streaming Operator
NATS Streaming Operator
Stars: ✭ 167 (+518.52%)
Mutual labels:  stan
bayesian
Bindings for Bayesian TidyModels
Stars: ✭ 33 (+22.22%)
Mutual labels:  stan
stantargets
Reproducible Bayesian data analysis pipelines with targets and cmdstanr
Stars: ✭ 31 (+14.81%)
Mutual labels:  stan
stanTuneR
This code uses the algebra solver in Stan (https://mc-stan.org/) to find the parameters of a distribution that produce a desired tail behavior.
Stars: ✭ 28 (+3.7%)
Mutual labels:  stan
TrendinessOfTrends
The Trendiness of Trends
Stars: ✭ 14 (-48.15%)
Mutual labels:  stan

ubms: Unmarked Bayesian Models with Stan

R build status Codecov test coverage CRAN status

ubms is an R package for fitting Bayesian hierarchical models of animal occurrence and abundance. The package has a formula-based interface compatible with unmarked, but the model is fit using MCMC with Stan instead of using maximum likelihood. Currently there are Stan versions of unmarked functions occu, occuRN, colext, occuTTD, pcount, distsamp, and multinomPois. These functions follow the stan_ prefix naming format established by rstanarm. For example, the Stan version of the unmarked function occu is stan_occu.

Advantages compared to unmarked:

  1. Obtain posterior distributions of parameters and derived parameters
  2. Include random effects in parameter formulas (same syntax as lme4)
  3. Assess model fit using WAIC and LOO via the loo package

Disadvantages compared to unmarked:

  1. MCMC is slower than maximum likelihood
  2. Not all model types are supported
  3. Potential for convergence issues

Installation

ubms is on CRAN:

install.packages("ubms")

Alternatively, the latest development version can be installed from Github:

# install.packages("devtools")
devtools::install_github("kenkellner/ubms")

Example

Simulate occupancy data including a random effect on occupancy:

library(ubms)

set.seed(123)
dat_occ <- data.frame(x1=rnorm(500))
dat_p <- data.frame(x2=rnorm(500*5))

y <- matrix(NA, 500, 5)
z <- rep(NA, 500)

b <- c(0.4, -0.5, 0.3, 0.5)

re_fac <- factor(sample(letters[1:26], 500, replace=T))
dat_occ$group <- re_fac
re <- rnorm(26, 0, 1.2)
re_idx <- as.numeric(re_fac)

idx <- 1
for (i in 1:500){
  z[i] <- rbinom(1,1, plogis(b[1] + b[2]*dat_occ$x1[i] + re[re_idx[i]]))
  for (j in 1:5){
    y[i,j] <- z[i]*rbinom(1,1, 
                    plogis(b[3] + b[4]*dat_p$x2[idx]))
    idx <- idx + 1
  }
}

Create unmarked frame:

umf <- unmarkedFrameOccu(y=y, siteCovs=dat_occ, obsCovs=dat_p)

Fit a model with a random intercept, using 3 parallel cores:

(fm <- stan_occu(~x2 ~x1 + (1|group), umf, chains=3, cores=3))
## 
## Call:
## stan_occu(formula = ~x2 ~ x1 + (1 | group), data = umf, chains = 3, 
##     cores = 3, refresh = 0)
## 
## Occupancy (logit-scale):
##                 Estimate    SD   2.5%  97.5% n_eff Rhat
## (Intercept)        0.317 0.294 -0.259  0.900   668    1
## x1                -0.461 0.119 -0.693 -0.229  4502    1
## sigma [1|group]    1.388 0.277  0.929  2.018  1982    1
## 
## Detection (logit-scale):
##             Estimate     SD  2.5% 97.5% n_eff  Rhat
## (Intercept)    0.382 0.0592 0.268 0.496  5380 1.000
## x2             0.586 0.0615 0.469 0.710  4311 0.999
## 
## LOOIC: 2267.997

Examine residuals for occupancy and detection submodels (following Wright et al. 2019). Each panel represents a draw from the posterior distribution.

plot(fm)

Assess model goodness-of-fit with a posterior predictive check, using the MacKenzie-Bailey chi-square test:

fm_fit <- gof(fm, draws=500)
plot(fm_fit)

Look at the marginal effect of x2 on detection:

plot_effects(fm, "det")

A more detailed vignette for the package is available here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].