barg {pcvr}R Documentation

Function to help fulfill elements of the Bayesian Analysis Reporting Guidelines.

Description

The Bayesian Analysis Reporting Guidelines were put forward by Kruschke (https://www.nature.com/articles/s41562-021-01177-7) to aide in reproducibility and documentation of Bayesian statistical analyses that are sometimes unfamiliar to reviewers or scientists. The purpose of this function is to summarize goodness of fit metrics from one or more Bayesian models made by growthSS and fitGrowth. See details for explanations of those metrics and the output.

Usage

barg(fit, ss = NULL, priors = NULL)

Arguments

fit

A conjugate object, brmsfit object, or a list of brmsfit objects in the case that you split models to run on subsets of the data for computational simplicity.

ss

The growthSS output used to specify the model. If fit is a list then this can either be one growthSS list in which case the priors are assumed to be the same for each model or it can be a list of the same length as fit. Note that the only parts of this which are used are the call$start which is expected to be a call, pcvrForm, and df list elements, so if you have a list of brmsfit objects and no ss object you can specify a stand-in list. This can also be left NULL (the default) and posterior predictive plots and prior predictive plots will not be made.

priors

A list of priors similar to how they are specified in conjugate but named for the distribution you plan to use, see details and examples.

Details

The majority of the Bayesian Analysis and Reporting Guidelines are geared towards statistical methods that use MCMC or other numeric approximations. For those cases (here meaning brms models fit by fitGrowth and growthSS) the output will contain:

For analytic solutions (ie, the conjugate class) there are fewer elements.

Priors here are specified using a named list. For instance, to use 100 normal priors with means between 5 and 20 and standard deviations between 5 and 10 the prior argument would be list("rnorm" = list("mean" = c(5, 20), "sd" = c(5, 10), "n" = 100))). The priors that are used in sensitivity analysis are drawn randomly from within the ranges specified by the provided list. If you are unsure what random-generation function to use then check the conjugate docs where the distributions are listed for each method in the details section.

Value

A named list containing Rhat, ESS, NEFF, and Trace/Prior/Posterior Predictive plots. See details for interpretation.

See Also

plotPrior for visual prior predictive checks.

Examples


simdf <- growthSim("logistic",
  n = 20, t = 25,
  params = list("A" = c(200, 160), "B" = c(13, 11), "C" = c(3, 3.5))
)
ss <- growthSS(
  model = "logistic", form = y ~ time | id / group, sigma = "logistic",
  df = simdf, start = list(
    "A" = 130, "B" = 12, "C" = 3,
    "sigmaA" = 20, "sigmaB" = 10, "sigmaC" = 2
  ), type = "brms"
)
fit_test <- fitGrowth(ss,
  iter = 600, cores = 1, chains = 1, backend = "cmdstanr",
  sample_prior = "only" # only sampling from prior for speed
)
barg(fit_test, ss)
fit_2 <- fit_test
fit_list <- list(fit_test, fit_2)
x <- barg(fit_list, list(ss, ss))

x <- conjugate(
  s1 = rnorm(10, 10, 1), s2 = rnorm(10, 13, 1.5), method = "t",
  priors = list(
    list(mu = 10, sd = 2),
    list(mu = 10, sd = 2)
  ),
  plot = FALSE, rope_range = c(-8, 8), rope_ci = 0.89,
  cred.int.level = 0.89, hypothesis = "unequal",
  bayes_factor = c(50, 55)
)
b <- barg(x, priors = list("rnorm" = list("n" = 10, "mean" = c(5, 20), "sd" = c(5, 10))))



[Package pcvr version 1.2.0 Index]