Learn R Programming

⚠️There's a newer version (0.8.0) of this package.Take me there.

extras

extras provides helper functions for Bayesian analyses.

In particular it provides functions to numericise R objects and summarise MCMC samples as well as R translations of BUGS (and JAGS) functions.

Installation

To install the developmental version from GitHub

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

Demonstration

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.

library(extras)
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

Summarise MCMC Samples

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

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

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

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.

Copy Link

Version

Install

install.packages('extras')

Monthly Downloads

496

Version

0.2.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Joe Thorley

Last Published

August 5th, 2021

Functions in extras (0.2.0)

fill_all

Fill All Values
dev_norm

Normal Deviances
pow

Power
dev_pois

Poisson Deviances
pvalue

Bayesian P-Value
res_bern

Bernoulli Residuals
log_lik_bern

Bernoulli Log-Likelihood
log_lik_binom

Binomial Log-Likelihood
phi

Phi
pextreme

Extreme Probability
ran_gamma

Gamma Random Samples
ran_gamma_pois

Gamma-Poisson Random Samples
log_lik_gamma_pois

Gamma Poisson Log-Likelihood
fill_na

Fill Missing Values
log_lik_lnorm

Log-Normal Log-Likelihood
ilogit

Inverse Logistic Transformation
zscore

Z-Score
skewness

Skewness
res_binom

Binomial Residuals
svalue

Surprisal Value
invlogit

Inverse Logistic Transformation
logit

Logistic Transformation
logit<-

Logistic Transformation
lower

Lower Credible Limit
extras-package

extras: Helper Functions for Bayesian Analyses
dev_bern

Bernoulli Deviances
res_neg_binom

Negative Binomial Residuals
ran_lnorm

Log-Normal Random Samples
numericise

Numericise (or Numericize)
ran_neg_binom

Gamma-Poisson Random Samples
res_norm

Normal Residuals
log_lik_pois

Poisson Log-Likelihood
kurtosis

Kurtosis
log_odds_ratio

Log-Odds Ratio
log<-

Log Transformation
xtr_mean

Mean
odds

Odds
params

Parameter Descriptions
ran_bern

Bernoulli Random Samples
par_pattern

Parameter Pattern
odds_ratio

Odds Ratio
xtr_median

Median
xtr_sd

Standard Deviation
res_gamma_pois

Gamma Poisson Residuals
res_lnorm

Log-Normal Residuals
ran_binom

Binomial Random Samples
zeros

Zeros
log_lik_neg_binom

Negative Binomial Log-Likelihood
res_pois

Poisson Residuals
fabs

Absolute
log_lik_norm

Normal Log-Likelihood
ran_norm

Normal Random Samples
sextreme

Extreme Surprisal
upper

Upper Credible Limit
variance

Variance
ran_pois

Poisson Random Samples
as_list_unnamed

As List
as_list

As List
chk_pars

Check Parameter Names
chk_indices

Check Indices
chk_index

Check Index
dev_lnorm

Log-Normal Deviances
dev_binom

Binomial Deviances
dev_gamma_pois

Gamma-Poisson Deviances
dev_neg_binom

Negative Binomial Deviances