MyNixOS website logo
Description

Helper Functions for Bayesian Analyses.

Functions to 'numericise' 'R' objects (coerce to numeric objects), summarise 'MCMC' (Monte Carlo Markov Chain) samples 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.

extras

Lifecycle:stable R-CMD-check Codecov testcoverage License:MIT CRANstatus CRAN downloads

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

To install the developmental version from GitHub

# install.packages("remotes")
remotes::install_github("poissonconsulting/extras")

Demonstration

Summarise MCMC Samples

The extras package provides functions to summarise MCMC samples like svalue() which gives the surprisal value (Greenland, 2019)

library(extras)
#> 
#> Attaching package: 'extras'
#> The following object is masked from 'package:stats':
#> 
#>     step

set.seed(1)
x <- rnorm(100)
svalue(rnorm(100))
#> [1] 0.3183615
svalue(rnorm(100, mean = 1))
#> [1] 1.704015
svalue(rnorm(100, mean = 2))
#> [1] 3.850857
svalue(rnorm(100, mean = 3))
#> [1] 5.073249

Distributions

Implemented distributions include

R translations

The package also provides R translations of BUGS (and JAGS) functions such as pow() and log<-.

pow(10, 2)
#> [1] 100

mu <- NULL
log(mu) <- 1
mu
#> [1] 2.718282

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.

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"))
  )
)
#>      logical factor  Date hms
#> [1,]       1      1 10957   2
#> [2,]       0      2 10958  61

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. https://doi.org/10.1080/00031305.2018.1529625.

Contribution

Please report any issues.

Pull requests are always welcome.

Code of Conduct

Please note that the extras project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Metadata

Version

0.6.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows