https://github.com/poissonconsulting/extras
An R package of helper functions for Bayesian analyses
https://github.com/poissonconsulting/extras
cran
Last synced: 4 months ago
JSON representation
An R package of helper functions for Bayesian analyses
- Host: GitHub
- URL: https://github.com/poissonconsulting/extras
- Owner: poissonconsulting
- License: other
- Created: 2020-01-20T23:01:58.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-09-19T20:43:52.000Z (7 months ago)
- Last Synced: 2024-11-23T19:41:12.714Z (5 months ago)
- Topics: cran
- Language: R
- Homepage: https://poissonconsulting.github.io/extras/
- Size: 4.33 MB
- Stars: 9
- Watchers: 5
- Forks: 2
- Open Issues: 11
-
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
- jimsghstars - poissonconsulting/extras - An R package of helper functions for Bayesian analyses (R)
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```[](https://lifecycle.r-lib.org/articles/stages.html#stable)
[](https://github.com/poissonconsulting/extras/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/poissonconsulting/extras)
[](https://cran.r-project.org/package=extras)
`extras` provides helper functions for Bayesian analyses.
In particular it provides functions to summarise
vectors of MCMC (Monte Carlo Markov Chain) samples,
draw random samples from various distributions and
calculate deviance residuals as well as R translations of some
BUGS (Bayesian Using Gibbs Sampling), JAGS (Just Another Gibbs
Sampler), STAN and TMB (Template Model Builder) functions.## Installation
```{r, eval=FALSE, echo=FALSE}
install.packages("extras")
```To install the developmental version from [GitHub](https://github.com/poissonconsulting/extras)
```{r, eval=FALSE}
# install.packages("pak")
pak::pak("poissonconsulting/extras")
```## Demonstration
### Summarise MCMC Samples
The `extras` package provides functions to summarise MCMC samples like `svalue()` which gives the *surprisal value* (Greenland, 2019)
```{r}
library(extras)set.seed(1)
x <- rnorm(100)
svalue(rnorm(100))
svalue(rnorm(100, mean = 1))
svalue(rnorm(100, mean = 2))
svalue(rnorm(100, mean = 3))
```### Distributions
Implemented distributions with functions to draw random samples, calculate log-likelihoods, and calculate deviance residuals for include:
- Bernoulli
- Beta-binomial
- Gamma
- Gamma-Poisson
- Zero-inflated gamma-Poisson
- Log-Normal
- Negative Binomial
- Normal
- Poisson
- Zero-inflated Poisson
- Skew Normal
- Student's t### R translations
The package also provides R translations of `BUGS` (and `JAGS`) functions such as `pow()` and `log<-`.
```{r}
pow(10, 2)mu <- NULL
log(mu) <- 1
mu
```### Numericise R Objects
Atomic vectors, matrices, arrays and data.frames of appropriate classes can be converted to numeric objects suitable for Bayesian analysis using the `numericise()` (and `numericize()`) function.
```{r}
numericise(
data.frame(
logical = c(TRUE, FALSE),
factor = factor(c("blue", "green")),
Date = as.Date(c("2000-01-01", "2000-01-02")),
hms = hms::as_hms(c("00:00:02", "00:01:01"))
)
)
```## References
Greenland, S. 2019. Valid P-Values Behave Exactly as They Should: Some Misleading Criticisms of P-Values and Their Resolution With S-Values. The American Statistician 73(sup1): 106–114.
## Contribution
Please report any [issues](https://github.com/poissonconsulting/extras/issues).
[Pull requests](https://github.com/poissonconsulting/extras/pulls) are always welcome.
## Code of Conduct
Please note that the extras 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.