Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/poissonconsulting/jmbr
An R package to facilitate analyses using JAGS
https://github.com/poissonconsulting/jmbr
jags mbr rstats
Last synced: about 1 month ago
JSON representation
An R package to facilitate analyses using JAGS
- Host: GitHub
- URL: https://github.com/poissonconsulting/jmbr
- Owner: poissonconsulting
- License: other
- Created: 2017-01-03T00:26:30.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2024-11-24T07:44:39.000Z (about 2 months ago)
- Last Synced: 2024-11-24T08:25:48.666Z (about 2 months ago)
- Topics: jags, mbr, rstats
- Language: R
- Homepage: https://poissonconsulting.github.io/jmbr/
- Size: 54.4 MB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Support: .github/SUPPORT.md
Awesome Lists containing this project
README
---
output: github_document
---```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "tools/README-"
)
```[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/poissonconsulting/jmbr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/poissonconsulting/jmbr/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/poissonconsulting/jmbr/branch/master/graph/badge.svg)](https://codecov.io/gh/poissonconsulting/jmbr?branch=master)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/license/mit/)# jmbr
## Introduction
`jmbr` (pronounced jimber) is an R package to facilitate analyses using Just Another Gibbs Sampler ([`JAGS`](http://mcmc-jags.sourceforge.net)).
It is part of the [mbr](https://github.com/poissonconsulting/mbr) family of packages.
## Demonstration
```{r, message = FALSE}
library(jmbr)
library(mbr)
``````{r}
# define model in JAGS language
model <- model("model {
alpha ~ dnorm(0, 10^-2)
beta1 ~ dnorm(0, 10^-2)
beta2 ~ dnorm(0, 10^-2)
beta3 ~ dnorm(0, 10^-2)log_sAnnual ~ dnorm(0, 10^-2)
log(sAnnual) <- log_sAnnualfor(i in 1:nAnnual) {
bAnnual[i] ~ dnorm(0, sAnnual^-2)
}for (i in 1:length(Pairs)) {
log(ePairs[i]) <- alpha + beta1 * Year[i] + beta2 * Year[i]^2 + beta3 * Year[i]^3 + bAnnual[Annual[i]]
Pairs[i] ~ dpois(ePairs[i])
}
}")# add R code to calculate derived parameters
model <- update_model(model, new_expr = "
for (i in 1:length(Pairs)) {
log(prediction[i]) <- alpha + beta1 * Year[i] + beta2 * Year[i]^2 + beta3 * Year[i]^3 + bAnnual[Annual[i]]
}")# define data types and center year
model <- update_model(model,
select_data = list("Pairs" = integer(), "Year*" = integer(), Annual = factor()),
derived = "sAnnual",
random_effects = list(bAnnual = "Annual")
)data <- bauw::peregrine
data$Annual <- factor(data$Year)set_analysis_mode("report")
# analyse
analysis <- analyse(model, data = data)
analysis <- reanalyse(analysis)coef(analysis, simplify = TRUE)
plot(analysis)
``````{r, message = FALSE}
# make predictions by varying year with other predictors including the random effect of Annual held constant
year <- predict(analysis, new_data = "Year")# plot those predictions
library(ggplot2)ggplot(data = year, aes(x = Year, y = estimate)) +
geom_point(data = bauw::peregrine, aes(y = Pairs)) +
geom_line() +
geom_line(aes(y = lower), linetype = "dotted") +
geom_line(aes(y = upper), linetype = "dotted") +
expand_limits(y = 0)
```## Installation
To install from GitHub
```
install.packages("devtools")
devtools::install_github("poissonconsulting/jmbr")
```## Citation
```{r, comment="", echo=FALSE}
citation(package = "jmbr")
```## Contribution
Please report any [issues](https://github.com/poissonconsulting/jmbr/issues).
[Pull requests](https://github.com/poissonconsulting/jmbr/pulls) are always welcome.
## Code of Conduct
Please note that the jmbr project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.
## Inspiration
- [jaggernaut](https://github.com/poissonconsulting/jaggernaut)