https://github.com/poissonconsulting/mcmcr
An R package to manipulate MCMC samples
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (15.5%) to scientific vocabulary
Keywords
coda
cran
mcmc
r
rstats
Keywords from Contributors
chk
hms
derived-parameters
mcmcr
fish
dbi
posixct
read
sfc
units
Last synced: 9 months ago
·
JSON representation
Repository
An R package to manipulate MCMC samples
Basic Info
- Host: GitHub
- Owner: poissonconsulting
- License: other
- Language: HTML
- Default Branch: main
- Homepage: https://poissonconsulting.github.io/mcmcr/
- Size: 6.23 MB
Statistics
- Stars: 17
- Watchers: 4
- Forks: 2
- Open Issues: 10
- Releases: 4
Topics
coda
cran
mcmc
r
rstats
Created over 9 years ago
· Last pushed about 1 year ago
Metadata Files
Readme
Changelog
Contributing
License
Code of conduct
Support
README.Rmd
---
output: github_document
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# mcmcr
[](https://lifecycle.r-lib.org/articles/stages.html#stable)
[](https://github.com/poissonconsulting/mcmcr/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/poissonconsulting/mcmcr)
[](https://cran.r-project.org/package=mcmcr)

`mcmcr` is an R package to manipulate Monte Carlo Markov Chain (MCMC) samples.
## Introduction
For the purposes of this discussion, an MCMC *sample* represents the value of a *term* from a single *iteration* of a single *chain*.
While a simple *parameter* such as an intercept corresponds to a single term, more complex parameters such as an interaction between two factors consists of multiple terms with their own inherent dimensionality - in this case a matrix.
A set of MCMC samples can be stored in different ways.
### Existing Classes
The three most common S3 classes store MCMC samples as follows:
- `coda::mcmc` stores the MCMC samples from a single chain as a matrix where each each row represents an iteration and each column represents a variable
- `coda::mcmc.list` stores multiple `mcmc` objects (with identical dimensions) as a list where each object represents a parallel chain
- `rjags::mcarray` stores the samples from a single parameter where the initial dimensions are the parameter dimensions, the second to last dimension is iterations and the last dimension is chains.
In the first two cases the terms/parameters are represented by a single dimension which means that the dimensionality inherent in the parameters is stored in the labelling of the variables, ie, `"bIntercept", "bInteraction[1,2]", "bInteraction[2,1]", ...`.
The structure of the `mcmc` and `mcmc.list` objects emphasizes the time-series nature of MCMC samples and is optimized for thining.
In contrast `mcarray` objects preserve the dimensionality of the parameters.
### New Classes
The `mcmcr` package defines three related S3 classes which also preserve the dimensionality of
the parameters:
- `mcmcr::mcmcarray` is very similar to `rjags::mcarray` except that the first dimension is the chains, the second dimension is iterations and the subsequent dimensions represent the dimensionality of the parameter (it is called `mcmcarray` to emphasize that the MCMC dimensions ie the chains and iterations come first);
- `mcmcr::mcmcr` stores multiple uniquely named `mcmcarray` objects with the same number of chains and iterations.
- `mcmcr::mcmcrs` stores multiple `mcmcr` objects with the same parameters, chains and iterations.
All five classes (`mcmc`, `mcmc.list`, `mcarray`, `mcmcarray`, `mcmcr` and `mcmcrs`) are collectively referred to as MCMC objects.
## Why mcmcr?
`mcmcarray` objects were developed to facilitate manipulation of the MCMC samples.
`mcmcr` objects were developed to allow a set of dimensionality preserving parameters from a single analysis to be manipulated as a whole.
`mcmcrs` objects were developed to allow the results of multiple analyses using the same model to be manipulated together.
The `mcmcr` package (together with the [term](https://github.com/poissonconsulting/term) and [nlist](https://github.com/poissonconsulting/nlist) packages) introduces a variety of (often) generic functions to manipulate and query `mcmcarray`, `mcmcr` and `mcmcrs` objects (and `term` and `nlist` and `nlists` objects).
In particular it provides functions to
- coerce from and to `mcarray`, `mcmc` and `mcmc.list` objects;
- extract an objects `coef` table (as a tibble);
- query an object's `nchains`, `niters`, `term::npars`, `term::nterms`, `nlist::nsims` and `nlist::nsams` as well as it's parameter dimensions (`term::pdims`) and term indices (`term::tindex`);
- `subset` objects by chains, iterations and/or parameters;
- `bind_xx` a pair of objects by their `xx_chains`, `xx_iterations`, `xx_parameters` or (parameter) `xx_dimensions`;
- combine the samples of two (or more) MCMC objects using `combine_samples` (or `combine_samples_n`) or combine the samples of a single MCMC object by reducing its dimensions using `combine_dimensions`;
- `collapse_chains` or `split_chains` an object's chains;
- `mcmc_map` over an objects values;
- transpose an objects parameter dimensions using `mcmc_aperm`;
- assess if an object has `converged` using `rhat` and `esr` (effectively sampling rate);
- and of course `thin`, `rhat`, `ess` (effective sample size), `print`, `plot` etc said objects.
The code is opinionated which has the advantage of providing a small set of stream-lined functions.
For example the only 'convergence' metric is the uncorrected, untransformed, univariate split R-hat (potential scale reduction factor).
If you can convince me that additional features are important I will add them or accept a pull request (see below).
Alternatively you might want to use the `mcmcr` package to manipulate your samples before coercing them to an `mcmc.list` to take advantage of all the summary functions in packages such as `coda`.
## Demonstration
```{r}
library(mcmcr)
mcmcr_example
coef(mcmcr_example, simplify = TRUE)
rhat(mcmcr_example, by = "term")
plot(mcmcr_example[["alpha"]])
```
## Installation
### Release
To install the release version from [CRAN](https://CRAN.R-project.org/package=mcmcr).
```r
install.packages("mcmcr")
```
The website for the release version is at .
### Development
To install the development version from [GitHub](https://github.com/poissonconsulting/mcmcr)
```r
# install.packages("remotes")
remotes::install_github("poissonconsulting/mcmcr")
```
or from [r-universe](https://poissonconsulting.r-universe.dev/mcmcr).
```r
install.packages("mcmcr", repos = c("https://poissonconsulting.r-universe.dev", "https://cloud.r-project.org"))
```
## Inspiration
[coda](https://github.com/cran/coda) and [rjags](https://github.com/cran/rjags)
## Contribution
Please report any [issues](https://github.com/poissonconsulting/mcmcr/issues).
[Pull requests](https://github.com/poissonconsulting/mcmcr/pulls) are always welcome.
## Code of Conduct
Please note that the mcmcr 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.
## References
Brooks, S., Gelman, A., Jones, G.L., and Meng, X.-L. (Editors). 2011. Handbook for Markov Chain Monte Carlo. Taylor & Francis, Boca Raton. ISBN: 978-1-4200-7941-8.
Owner
- Name: Poisson Consulting Ltd.
- Login: poissonconsulting
- Kind: organization
- Email: software@poissonconsulting.ca
- Location: Nelson, BC, Canada
- Website: http://www.poissonconsulting.ca
- Repositories: 68
- Profile: https://github.com/poissonconsulting
Computational Biology and Statistical Ecology
GitHub Events
Total
- Create event: 4
- Release event: 1
- Issues event: 1
- Delete event: 1
- Push event: 45
- Pull request event: 2
Last Year
- Create event: 4
- Release event: 1
- Issues event: 1
- Delete event: 1
- Push event: 45
- Pull request event: 2
Committers
Last synced: over 1 year ago
Top Committers
| Name | Commits | |
|---|---|---|
| Joe Thorley | j****e@p****a | 605 |
| Nadine Hussein | n****3@g****m | 7 |
| Duncan Kennedy | d****n@p****a | 5 |
| Ayla Pearson | a****3@g****m | 4 |
| Kirill Müller | k****r@m****g | 2 |
| Mowahid Latif | m****f@M****l | 1 |
| Joe Thorley | j****e@J****e | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 9 months ago
All Time
- Total issues: 50
- Total pull requests: 13
- Average time to close issues: 5 months
- Average time to close pull requests: about 3 hours
- Total issue authors: 10
- Total pull request authors: 6
- Average comments per issue: 1.44
- Average comments per pull request: 0.08
- Merged pull requests: 13
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 3
- Average time to close issues: N/A
- Average time to close pull requests: about 7 hours
- Issue authors: 0
- Pull request authors: 2
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 3
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- joethorley (39)
- sebdalgarno (2)
- bob-carpenter (2)
- Harmohit-Singh (1)
- barracuda156 (1)
- zywhy9 (1)
- hadley (1)
- EcologyTom (1)
- audrey-b (1)
- secastroal (1)
Pull Request Authors
- joethorley (6)
- nadinehussein (4)
- dunkenwg (2)
- krlmlr (2)
- aylapear (1)
- MowahidLatif (1)
Top Labels
Issue Labels
Effort: 2 Medium (2)
Priority: 1 Critical (2)
Type: Refactor (2)
Difficulty: 3 Advanced (1)
Difficulty: 2 Intermediate (1)
Pull Request Labels
CRAN release :station: (2)
Packages
- Total packages: 1
-
Total downloads:
- cran 418 last-month
- Total docker downloads: 41,971
- Total dependent packages: 2
- Total dependent repositories: 11
- Total versions: 11
- Total maintainers: 1
cran.r-project.org: mcmcr
Manipulate MCMC Samples
- Homepage: https://github.com/poissonconsulting/mcmcr
- Documentation: http://cran.r-project.org/web/packages/mcmcr/mcmcr.pdf
- License: MIT + file LICENSE
-
Latest release: 0.6.2
published over 1 year ago
Rankings
Docker downloads count: 0.6%
Dependent repos count: 8.8%
Stargazers count: 12.8%
Average: 13.4%
Dependent packages count: 13.7%
Forks count: 17.0%
Downloads: 27.3%
Maintainers (1)
Last synced:
10 months ago
Dependencies
DESCRIPTION
cran
- R >= 3.5 depends
- abind * imports
- chk >= 0.7.0 imports
- coda * imports
- extras * imports
- generics * imports
- lifecycle * imports
- nlist * imports
- purrr * imports
- stats * imports
- term * imports
- universals * imports
- utils * imports
- covr * suggests
- graphics * suggests
- readr * suggests
- rlang * suggests
- testthat * suggests
- tibble * suggests
.github/workflows/R-CMD-check.yaml
actions
- 8398a7/action-slack v3.0.0 composite
- actions/checkout v3 composite
- r-lib/actions/check-r-package v2 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pkgdown.yaml
actions
- JamesIves/github-pages-deploy-action v4.4.1 composite
- actions/checkout v3 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/test-coverage.yaml
actions
- actions/checkout v3 composite
- actions/upload-artifact v3 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite