| Title: | Tools for Bayesian Analyses |
|---|---|
| Description: | Provides tools for conducting Bayesian analyses and Bayesian model averaging (Kass and Raftery, 1995, <doi:10.1080/01621459.1995.10476572>, Hoeting et al., 1999, <doi:10.1214/ss/1009212519>). The package contains functions for creating a wide range of prior distribution objects, mixing posterior samples from 'JAGS' and 'Stan' models, plotting posterior distributions, and etc... The tools for working with prior distribution span from visualization, generating 'JAGS' and 'bridgesampling' syntax to basic functions such as rng, quantile, and distribution functions. |
| Authors: | František Bartoš [aut, cre] (ORCID: <https://orcid.org/0000-0002-0018-5573>) |
| Maintainer: | František Bartoš <[email protected]> |
| License: | GPL-3 |
| Version: | 0.3.0 |
| Built: | 2026-06-04 11:17:15 UTC |
| Source: | https://github.com/fbartos/bayestools |
Adds column to a BayesTools table while not breaking formatting, attributes, etc...
add_column( table, column_title, column_values, column_position = NULL, column_type = NULL )add_column( table, column_title, column_values, column_position = NULL, column_type = NULL )
table |
BayesTools table |
column_title |
title of the new column |
column_values |
values of the new column |
column_position |
position of the new column (defaults to |
column_type |
type of values of the new column table (important for formatting,
defaults to |
returns an object of 'BayesTools_table' class.
marginal_inference
Creates marginal model-averaged and conditional posterior distributions based on a BayesTools JAGS model, vector of parameters, formula, and a list of conditional specifications for each parameter. Computes inclusion Bayes factors for each marginal estimate via a Savage-Dickey density approximation.
as_marginal_inference( model, marginal_parameters, parameters, conditional_list, conditional_rule, formula, null_hypothesis = 0, normal_approximation = FALSE, n_samples = 10000, silent = FALSE, force_plots = FALSE )as_marginal_inference( model, marginal_parameters, parameters, conditional_list, conditional_rule, formula, null_hypothesis = 0, normal_approximation = FALSE, n_samples = 10000, silent = FALSE, force_plots = FALSE )
model |
model fit via the JAGS_fit function |
marginal_parameters |
parameters for which the the marginal summary should be created |
parameters |
all parameters included in the model_list that are
relevant for the formula (all of which need to have specification of
|
conditional_list |
list of conditional parameters for each marginal parameter |
conditional_rule |
a character string specifying the rule for conditioning. Either "AND" or "OR". Defaults to "AND". |
formula |
model formula (needs to be specified if |
null_hypothesis |
point null hypothesis to test. Defaults to |
normal_approximation |
whether the height of prior and posterior density should be
approximated via a normal distribution (rather than kernel density). Defaults to |
n_samples |
controls the numerical grid used for model-averaged prior densities |
silent |
whether warnings should be returned silently. Defaults to |
force_plots |
temporal argument allowing to generate conditional posterior samples suitable for prior and posterior plots. Only available when conditioning on a single parameter. |
as_marginal_inference returns an object of class 'marginal_inference'.
marginal_inference as_mixed_posteriors
mix_posteriors
Creates a model-averages posterior distributions on a single model that allows mimicking the mix_posteriors functionality. This function is useful when the model-averaged ensemble is based on prior_spike_and_slab or prior_mixture priors - the model-averaging is done within the model.
as_mixed_posteriors( model, parameters, conditional = NULL, conditional_rule = "AND", force_plots = FALSE, transform_scaled = FALSE, n_prior_samples = 10000 )as_mixed_posteriors( model, parameters, conditional = NULL, conditional_rule = "AND", force_plots = FALSE, transform_scaled = FALSE, n_prior_samples = 10000 )
model |
model fit via the JAGS_fit function |
parameters |
vector of parameters names for which inference should be drawn |
conditional |
a character vector of parameters to be conditioned on |
conditional_rule |
a character string specifying the rule for conditioning. Either "AND" or "OR". Defaults to "AND". |
force_plots |
temporal argument allowing to generate conditional posterior samples suitable for prior and posterior plots. Only available when conditioning on a single parameter. |
transform_scaled |
whether to transform samples from standardized (scaled) to
original (unscaled) scale. When |
n_prior_samples |
controls the numerical grid used for transformed
prior densities when |
as_mix_posteriors returns a named list of mixed posterior
distributions (either a vector of matrix).
BayesTools: Provides tools for conducting Bayesian analyses. The package contains functions for creating a wide range of prior distribution objects, mixing posterior samples from JAGS and Stan models, plotting posterior distributions, and etc... The tools for working with prior distribution span from visualization, generating JAGS and bridgesampling syntax to basic functions such as rng, quantile, and distribution functions.
František Bartoš [email protected]
Useful links:
Creates estimate summaries based on posterior distributions created by mix_posteriors, inference summaries based on inference created by ensemble_inference, or ensemble summary/diagnostics based on a list of models_inference models (or marginal_inference in case of marginal_estimates_table).
ensemble_estimates_table( samples, parameters, probs = c(0.025, 0.975), title = NULL, footnotes = NULL, warnings = NULL, transform_factors = FALSE, transform_orthonormal = FALSE, formula_prefix = TRUE, transform_scaled = FALSE, formula_scale = NULL ) ensemble_inference_table( inference, parameters, logBF = FALSE, BF01 = FALSE, title = NULL, footnotes = NULL, warnings = NULL ) ensemble_summary_table( models, parameters, logBF = FALSE, BF01 = FALSE, title = NULL, footnotes = NULL, warnings = NULL, remove_spike_0 = TRUE, short_name = FALSE ) ensemble_diagnostics_table( models, parameters, title = NULL, footnotes = NULL, warnings = NULL, remove_spike_0 = TRUE, short_name = FALSE ) ensemble_estimates_empty_table( probs = c(0.025, 0.975), title = NULL, footnotes = NULL, warnings = NULL ) ensemble_inference_empty_table(title = NULL, footnotes = NULL, warnings = NULL) ensemble_summary_empty_table(title = NULL, footnotes = NULL, warnings = NULL) ensemble_diagnostics_empty_table( title = NULL, footnotes = NULL, warnings = NULL ) marginal_estimates_table( samples, inference, parameters, probs = c(0.025, 0.5, 0.975), logBF = FALSE, BF01 = FALSE, title = NULL, footnotes = NULL, warnings = NULL, formula_prefix = TRUE, transform_scaled = FALSE, formula_scale = NULL )ensemble_estimates_table( samples, parameters, probs = c(0.025, 0.975), title = NULL, footnotes = NULL, warnings = NULL, transform_factors = FALSE, transform_orthonormal = FALSE, formula_prefix = TRUE, transform_scaled = FALSE, formula_scale = NULL ) ensemble_inference_table( inference, parameters, logBF = FALSE, BF01 = FALSE, title = NULL, footnotes = NULL, warnings = NULL ) ensemble_summary_table( models, parameters, logBF = FALSE, BF01 = FALSE, title = NULL, footnotes = NULL, warnings = NULL, remove_spike_0 = TRUE, short_name = FALSE ) ensemble_diagnostics_table( models, parameters, title = NULL, footnotes = NULL, warnings = NULL, remove_spike_0 = TRUE, short_name = FALSE ) ensemble_estimates_empty_table( probs = c(0.025, 0.975), title = NULL, footnotes = NULL, warnings = NULL ) ensemble_inference_empty_table(title = NULL, footnotes = NULL, warnings = NULL) ensemble_summary_empty_table(title = NULL, footnotes = NULL, warnings = NULL) ensemble_diagnostics_empty_table( title = NULL, footnotes = NULL, warnings = NULL ) marginal_estimates_table( samples, inference, parameters, probs = c(0.025, 0.5, 0.975), logBF = FALSE, BF01 = FALSE, title = NULL, footnotes = NULL, warnings = NULL, formula_prefix = TRUE, transform_scaled = FALSE, formula_scale = NULL )
samples |
posterior samples created by mix_posteriors |
parameters |
character vector of parameters (or a named list with of character vectors for summary and diagnostics tables) specifying the parameters (and their grouping) for the summary table |
probs |
quantiles for parameter estimates |
title |
title to be added to the table |
footnotes |
footnotes to be added to the table |
warnings |
warnings to be added to the table |
transform_factors |
whether factors with orthonormal/meandif prior distribution should be transformed to differences from the grand mean |
transform_orthonormal |
(to be depreciated) whether factors with orthonormal prior distributions should be transformed to differences from the grand mean |
formula_prefix |
whether the parameter prefix from formula should
be printed. Defaults to |
transform_scaled |
whether coefficients from standardized
continuous predictors should be transformed back to the original
scale. Defaults to |
formula_scale |
named list containing standardization information
(mean and sd) for each standardized predictor. Required when
|
inference |
model inference created by ensemble_inference |
logBF |
whether the Bayes factor should be on log scale |
BF01 |
whether the Bayes factor should be inverted |
models |
list of models_inference model objects,
each of which containing a list of |
remove_spike_0 |
whether prior distributions equal to spike
at 0 should be removed from the |
short_name |
whether the prior distribution names should be
shortened. Defaults to |
ensemble_estimates_table returns a table with the
model-averaged estimates, ensemble_inference_table returns
a table with the prior and posterior probabilities and inclusion
Bayes factors, ensemble_summary_table returns a table with
overview of the models included in the ensemble, and
ensemble_diagnostics_table returns an overview of the MCMC
diagnostics for the models included in the ensemble. All of the
tables are objects of class 'BayesTools_table'.
ensemble_inference mix_posteriors BayesTools_model_tables
Creates model summary based on a model objects or provides estimates table for a runjags fit.
model_summary_table( model, model_description = NULL, title = NULL, footnotes = NULL, warnings = NULL, remove_spike_0 = TRUE, short_name = FALSE, formula_prefix = TRUE, remove_parameters = NULL ) runjags_estimates_table( fit, transformations = NULL, title = NULL, footnotes = NULL, warnings = NULL, conditional = FALSE, probs = c(0.025, 0.5, 0.975), remove_spike_0 = TRUE, transform_factors = FALSE, transform_orthonormal = FALSE, formula_prefix = TRUE, remove_inclusion = FALSE, remove_parameters = NULL, remove_formulas = NULL, keep_parameters = NULL, keep_formulas = NULL, return_samples = FALSE, transform_scaled = FALSE, remove_diagnostics = FALSE, diagnostic_columns = getOption("BayesTools.JAGS_estimates_diagnostic_columns", if (remove_diagnostics) "none" else "all") ) runjags_inference_table( fit, title = NULL, footnotes = NULL, warnings = NULL, formula_prefix = TRUE, logBF = FALSE, BF01 = FALSE, BF_diagnostics = FALSE, BF_diagnostic_columns = getOption("BayesTools.JAGS_BF_diagnostic_columns", if (BF_diagnostics) "all" else "none") ) JAGS_estimates_table( fit, transformations = NULL, title = NULL, footnotes = NULL, warnings = NULL, conditional = FALSE, probs = c(0.025, 0.5, 0.975), remove_spike_0 = TRUE, transform_factors = FALSE, transform_orthonormal = FALSE, formula_prefix = TRUE, remove_inclusion = FALSE, remove_parameters = NULL, remove_formulas = NULL, keep_parameters = NULL, keep_formulas = NULL, return_samples = FALSE, transform_scaled = FALSE, remove_diagnostics = FALSE, diagnostic_columns = getOption("BayesTools.JAGS_estimates_diagnostic_columns", if (remove_diagnostics) "none" else "all") ) JAGS_inference_table( fit, title = NULL, footnotes = NULL, warnings = NULL, formula_prefix = TRUE, logBF = FALSE, BF01 = FALSE, BF_diagnostics = FALSE, BF_diagnostic_columns = getOption("BayesTools.JAGS_BF_diagnostic_columns", if (BF_diagnostics) "all" else "none") ) JAGS_summary_table( model, model_description = NULL, title = NULL, footnotes = NULL, warnings = NULL, remove_spike_0 = TRUE, short_name = FALSE, formula_prefix = TRUE, remove_parameters = NULL ) model_summary_empty_table( model_description = NULL, title = NULL, footnotes = NULL, warnings = NULL ) runjags_estimates_empty_table( probs = c(0.025, 0.5, 0.975), title = NULL, footnotes = NULL, warnings = NULL, remove_diagnostics = FALSE, diagnostic_columns = getOption("BayesTools.JAGS_estimates_diagnostic_columns", if (remove_diagnostics) "none" else "all") ) runjags_inference_empty_table( title = NULL, footnotes = NULL, warnings = NULL, logBF = FALSE, BF01 = FALSE, BF_diagnostics = FALSE, BF_diagnostic_columns = getOption("BayesTools.JAGS_BF_diagnostic_columns", if (BF_diagnostics) "all" else "none") ) JAGS_estimates_empty_table( probs = c(0.025, 0.5, 0.975), title = NULL, footnotes = NULL, warnings = NULL, remove_diagnostics = FALSE, diagnostic_columns = getOption("BayesTools.JAGS_estimates_diagnostic_columns", if (remove_diagnostics) "none" else "all") ) JAGS_inference_empty_table( title = NULL, footnotes = NULL, warnings = NULL, logBF = FALSE, BF01 = FALSE, BF_diagnostics = FALSE, BF_diagnostic_columns = getOption("BayesTools.JAGS_BF_diagnostic_columns", if (BF_diagnostics) "all" else "none") ) stan_estimates_table( fit, transformations = NULL, title = NULL, footnotes = NULL, warnings = NULL )model_summary_table( model, model_description = NULL, title = NULL, footnotes = NULL, warnings = NULL, remove_spike_0 = TRUE, short_name = FALSE, formula_prefix = TRUE, remove_parameters = NULL ) runjags_estimates_table( fit, transformations = NULL, title = NULL, footnotes = NULL, warnings = NULL, conditional = FALSE, probs = c(0.025, 0.5, 0.975), remove_spike_0 = TRUE, transform_factors = FALSE, transform_orthonormal = FALSE, formula_prefix = TRUE, remove_inclusion = FALSE, remove_parameters = NULL, remove_formulas = NULL, keep_parameters = NULL, keep_formulas = NULL, return_samples = FALSE, transform_scaled = FALSE, remove_diagnostics = FALSE, diagnostic_columns = getOption("BayesTools.JAGS_estimates_diagnostic_columns", if (remove_diagnostics) "none" else "all") ) runjags_inference_table( fit, title = NULL, footnotes = NULL, warnings = NULL, formula_prefix = TRUE, logBF = FALSE, BF01 = FALSE, BF_diagnostics = FALSE, BF_diagnostic_columns = getOption("BayesTools.JAGS_BF_diagnostic_columns", if (BF_diagnostics) "all" else "none") ) JAGS_estimates_table( fit, transformations = NULL, title = NULL, footnotes = NULL, warnings = NULL, conditional = FALSE, probs = c(0.025, 0.5, 0.975), remove_spike_0 = TRUE, transform_factors = FALSE, transform_orthonormal = FALSE, formula_prefix = TRUE, remove_inclusion = FALSE, remove_parameters = NULL, remove_formulas = NULL, keep_parameters = NULL, keep_formulas = NULL, return_samples = FALSE, transform_scaled = FALSE, remove_diagnostics = FALSE, diagnostic_columns = getOption("BayesTools.JAGS_estimates_diagnostic_columns", if (remove_diagnostics) "none" else "all") ) JAGS_inference_table( fit, title = NULL, footnotes = NULL, warnings = NULL, formula_prefix = TRUE, logBF = FALSE, BF01 = FALSE, BF_diagnostics = FALSE, BF_diagnostic_columns = getOption("BayesTools.JAGS_BF_diagnostic_columns", if (BF_diagnostics) "all" else "none") ) JAGS_summary_table( model, model_description = NULL, title = NULL, footnotes = NULL, warnings = NULL, remove_spike_0 = TRUE, short_name = FALSE, formula_prefix = TRUE, remove_parameters = NULL ) model_summary_empty_table( model_description = NULL, title = NULL, footnotes = NULL, warnings = NULL ) runjags_estimates_empty_table( probs = c(0.025, 0.5, 0.975), title = NULL, footnotes = NULL, warnings = NULL, remove_diagnostics = FALSE, diagnostic_columns = getOption("BayesTools.JAGS_estimates_diagnostic_columns", if (remove_diagnostics) "none" else "all") ) runjags_inference_empty_table( title = NULL, footnotes = NULL, warnings = NULL, logBF = FALSE, BF01 = FALSE, BF_diagnostics = FALSE, BF_diagnostic_columns = getOption("BayesTools.JAGS_BF_diagnostic_columns", if (BF_diagnostics) "all" else "none") ) JAGS_estimates_empty_table( probs = c(0.025, 0.5, 0.975), title = NULL, footnotes = NULL, warnings = NULL, remove_diagnostics = FALSE, diagnostic_columns = getOption("BayesTools.JAGS_estimates_diagnostic_columns", if (remove_diagnostics) "none" else "all") ) JAGS_inference_empty_table( title = NULL, footnotes = NULL, warnings = NULL, logBF = FALSE, BF01 = FALSE, BF_diagnostics = FALSE, BF_diagnostic_columns = getOption("BayesTools.JAGS_BF_diagnostic_columns", if (BF_diagnostics) "all" else "none") ) stan_estimates_table( fit, transformations = NULL, title = NULL, footnotes = NULL, warnings = NULL )
model |
model object containing a list of |
model_description |
named list with additional description to be added to the table |
title |
title to be added to the table |
footnotes |
footnotes to be added to the table |
warnings |
warnings to be added to the table |
remove_spike_0 |
whether prior distributions equal to spike
at 0 should be removed from the |
short_name |
whether the prior distribution names should be
shortened. Defaults to |
formula_prefix |
whether the parameter prefix from formula should
be printed. Defaults to |
remove_parameters |
parameters to be removed from the summary.
Can be |
fit |
runjags model fit |
transformations |
named list of transformations to be applied to specific parameters |
conditional |
summarizes estimates conditional on being included
in the model for spike and slab priors. Defaults to |
probs |
quantiles for parameter estimates |
transform_factors |
whether factors with orthonormal/meandif prior distribution should be transformed to differences from the grand mean |
transform_orthonormal |
(to be depreciated) whether factors with orthonormal prior distributions should be transformed to differences from the grand mean |
remove_inclusion |
whether estimates of the inclusion probabilities
should be excluded from the summary table. Defaults to |
remove_formulas |
character vector of formula names whose parameters
should be removed from the summary. Defaults to |
keep_parameters |
character vector of parameter names to keep.
All other parameters will be removed unless they belong to formulas
specified in |
keep_formulas |
character vector of formula names whose parameters
should be kept. All other parameters will be removed unless they are
specified in |
return_samples |
whether to return the transoformed and formated samples
instead of the table. Defaults to |
transform_scaled |
whether coefficients from standardized
continuous predictors should be transformed back to the original
scale. Defaults to |
remove_diagnostics |
whether to exclude MCMC diagnostics (MCMC error,
ESS, R-hat) from the output table. Defaults to |
diagnostic_columns |
MCMC diagnostic columns to display in JAGS
estimates tables. Can be |
logBF |
whether the Bayes factor should be on log scale |
BF01 |
whether the Bayes factor should be inverted |
BF_diagnostics |
whether to add MCMC diagnostics for Bayes factors
computed from model indicator frequencies. The Bayes factor error is
reported as a relative Monte Carlo standard error percentage. Defaults to
|
BF_diagnostic_columns |
MCMC diagnostic columns to display in JAGS
inclusion Bayes factor tables. Can be |
For product-space JAGS inclusion Bayes factors, posterior inclusion
probabilities of exactly 0 or 1 cannot produce a finite point estimate of
the model odds ratio. In that case, inclusion BFs marked with "<" or
">" are finite-sample bounds: posterior inclusion probabilities of
0 or 1 were replaced by 1/S or (S - 1)/S, where S is
the number of posterior samples. This is a reporting convention, not an
unbiased finite Bayes-factor estimate. If the prior inclusion probability
is exactly 0 or 1, the inclusion Bayes factor is undefined and reported as
NA, because the corresponding inclusion/exclusion comparison was not
tested.
model_summary_table returns a table with
overview of the fitted model, runjags_estimates_table returns
a table with MCMC estimates, and runjags_estimates_empty_table
returns an empty estimates table. All of the tables are objects of
class 'BayesTools_table'.
prepares a 'bridgesampling' object with a given log marginal likelihood.
bridgesampling_object(logml = -Inf)bridgesampling_object(logml = -Inf)
logml |
log marginal likelihood. Defaults to |
JAGS_bridgesampling returns an object of class 'bridge'.
A set of convenience functions for checking objects/arguments to a function passed by a user.
check_bool( x, name = deparse(substitute(x)), check_length = 1, allow_NULL = FALSE, allow_NA = TRUE, call = "" ) check_char( x, name = deparse(substitute(x)), check_length = 1, allow_values = NULL, allow_NULL = FALSE, allow_NA = TRUE, call = "" ) check_real( x, name = deparse(substitute(x)), lower = -Inf, upper = Inf, allow_bound = TRUE, check_length = 1, allow_NULL = FALSE, allow_NA = TRUE, call = "" ) check_int( x, name = deparse(substitute(x)), lower = -Inf, upper = Inf, allow_bound = TRUE, check_length = 1, allow_NULL = FALSE, allow_NA = TRUE, call = "" ) check_list( x, name = deparse(substitute(x)), check_length = 0, check_names = NULL, all_objects = FALSE, allow_other = FALSE, allow_NULL = FALSE, call = "" )check_bool( x, name = deparse(substitute(x)), check_length = 1, allow_NULL = FALSE, allow_NA = TRUE, call = "" ) check_char( x, name = deparse(substitute(x)), check_length = 1, allow_values = NULL, allow_NULL = FALSE, allow_NA = TRUE, call = "" ) check_real( x, name = deparse(substitute(x)), lower = -Inf, upper = Inf, allow_bound = TRUE, check_length = 1, allow_NULL = FALSE, allow_NA = TRUE, call = "" ) check_int( x, name = deparse(substitute(x)), lower = -Inf, upper = Inf, allow_bound = TRUE, check_length = 1, allow_NULL = FALSE, allow_NA = TRUE, call = "" ) check_list( x, name = deparse(substitute(x)), check_length = 0, check_names = NULL, all_objects = FALSE, allow_other = FALSE, allow_NULL = FALSE, call = "" )
x |
object to be checked |
name |
name of the object that will be print in the error message. |
check_length |
length of the object to be checked. Defaults to
|
allow_NULL |
whether the object can be |
allow_NA |
whether the object can contain |
call |
string to be placed as a prefix to the error call. |
allow_values |
names of values allowed in a character vector.
Defaults to |
lower |
lower bound of allowed values.
Defaults to |
upper |
upper bound of allowed values.
Defaults to |
allow_bound |
whether the values at the boundary are allowed.
Defaults to |
check_names |
names of entries allowed in a list. Defaults to
|
all_objects |
whether all entries in |
allow_other |
whether additional entries then the specified in
|
returns NULL, called for the input check.
# check whether the object is logical check_bool(TRUE, name = "input") # will throw an error on any other type ## Not run: check_bool("TRUE", name = "input") ## End(Not run)# check whether the object is logical check_bool(TRUE, name = "input") # will throw an error on any other type ## Not run: check_bool("TRUE", name = "input") ## End(Not run)
BayesTools provides several contrast matrix functions for Bayesian factor analysis. These functions create different types of contrast matrices that can be used with factor variables in Bayesian models.
contr.orthonormal(n, contrasts = TRUE) contr.meandif(n, contrasts = TRUE) contr.independent(n, contrasts = TRUE)contr.orthonormal(n, contrasts = TRUE) contr.meandif(n, contrasts = TRUE) contr.independent(n, contrasts = TRUE)
n |
a vector of levels for a factor, or the number of levels |
contrasts |
logical indicating whether contrasts should be computed |
The package includes the following contrast functions:
contr.orthonormalReturn a matrix of orthonormal contrasts.
Code is based on stanova::contr.bayes and corresponding to description
by Rouder et al. (2012). Returns a matrix with n rows and
k columns, with k = n - 1 if contrasts = TRUE and k = n if contrasts = FALSE.
contr.meandifReturn a matrix of mean difference contrasts.
This is an adjustment to the contr.orthonormal that ascertains that the prior
distributions on difference between the gran mean and factor level are identical independent
of the number of factor levels (which does not hold for the orthonormal contrast). Furthermore,
the contrast is re-scaled so the specified prior distribution exactly corresponds to the prior
distribution on difference between each factor level and the grand mean – this is approximately
twice the scale of contr.orthonormal. Returns a matrix with n rows and k columns,
with k = n - 1 if contrasts = TRUE and k = n if contrasts = FALSE.
contr.independentReturn a matrix of independent contrasts – a level for each term.
Returns a matrix with n rows and k columns, with k = n if contrasts = TRUE and k = n
if contrasts = FALSE.
Rouder JN, Morey RD, Speckman PL, Province JM (2012). “Default Bayes factors for ANOVA designs.” Journal of Mathematical Psychology, 56(5), 356–374. doi:10.1016/j.jmp.2012.08.001.
# Orthonormal contrasts contr.orthonormal(c(1, 2)) contr.orthonormal(c(1, 2, 3)) # Mean difference contrasts contr.meandif(c(1, 2)) contr.meandif(c(1, 2, 3)) # Independent contrasts contr.independent(c(1, 2)) contr.independent(c(1, 2, 3))# Orthonormal contrasts contr.orthonormal(c(1, 2)) contr.orthonormal(c(1, 2, 3)) # Mean difference contrasts contr.meandif(c(1, 2)) contr.meandif(c(1, 2, 3)) # Independent contrasts contr.independent(c(1, 2)) contr.independent(c(1, 2, 3))
Computes density of a prior distribution across a range of values.
## S3 method for class 'prior' density( x, x_seq = NULL, x_range = NULL, x_range_quant = NULL, n_points = 1000, n_samples = 10000, force_samples = FALSE, individual = FALSE, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, truncate_end = TRUE, ... )## S3 method for class 'prior' density( x, x_seq = NULL, x_range = NULL, x_range_quant = NULL, n_points = 1000, n_samples = 10000, force_samples = FALSE, individual = FALSE, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, truncate_end = TRUE, ... )
x |
a prior |
x_seq |
sequence of x coordinates |
x_range |
vector of length two with
lower and upper range for the support
(used if |
x_range_quant |
quantile used for
automatically obtaining |
n_points |
number of equally spaced points
in the |
n_samples |
number of samples from the prior
distribution if the density cannot be obtained
analytically (or if samples are forced with
|
force_samples |
should prior be sampled instead of obtaining analytic solution whenever possible |
individual |
should individual densities be returned (e.g., in case of weightfunction) |
transformation |
transformation to be applied to the prior distribution. Either a character specifying one of the prepared transformations:
, or a list containing the transformation function |
transformation_arguments |
a list with named arguments for
the |
transformation_settings |
boolean indicating whether the
settings the |
truncate_end |
whether the density should be set to zero in for the endpoints of truncated distributions |
... |
additional arguments |
density.prior returns an object of class 'density'.
Computes prior probabilities, posterior probabilities, and inclusion Bayes factors based either on (1) a list of models, vector of parameters, and a list of indicators the models represent the null or alternative hypothesis for each parameter, (2) on prior model odds, marginal likelihoods, and indicator whether the models represent the null or alternative hypothesis, or (3) list of models for each model.
compute_inference(prior_weights, margliks, is_null = NULL, conditional = FALSE) ensemble_inference(model_list, parameters, is_null_list, conditional = FALSE) models_inference(model_list)compute_inference(prior_weights, margliks, is_null = NULL, conditional = FALSE) ensemble_inference(model_list, parameters, is_null_list, conditional = FALSE) models_inference(model_list)
prior_weights |
vector of prior model odds |
margliks |
vector of marginal likelihoods |
is_null |
logical vector of indicators specifying whether the model corresponds to the null or alternative hypothesis (or an integer vector indexing models corresponding to the null hypothesis) |
conditional |
whether prior and posterior model probabilities should
be returned only for the conditional model. Defaults to |
model_list |
list of models, each of which contains marginal
likelihood estimated with bridge sampling |
parameters |
vector of parameters names for which inference should be drawn |
is_null_list |
list with entries for each parameter carrying either logical vector of indicators specifying whether the model corresponds to the null or alternative hypothesis (or an integer vector indexing models corresponding to the null hypothesis) |
compute_inference returns a named list of prior probabilities,
posterior probabilities, and Bayes factors, ppoint gives the
distribution function, ensemble_inference gives a list of named lists of
inferences for each parameter, and models_inference returns a list of
models, each expanded by the inference list.
mix_posteriors BayesTools_ensemble_tables
Formats Bayes factor
format_BF(BF, logBF = FALSE, BF01 = FALSE, inclusion = FALSE)format_BF(BF, logBF = FALSE, BF01 = FALSE, inclusion = FALSE)
BF |
Bayes factor(s) |
logBF |
log(BF) |
BF01 |
1/BF |
inclusion |
whether the Bayes factor is an inclusion BF (for naming purposes) |
format_BF returns a formatted Bayes factor.
Converts a no-intercept formula to the corresponding formula
with an intercept while preserving the formula environment. Top-level
no-intercept encodings such as - 1, + 0, and 0 + are
removed without editing transformed calls such as I(x - 1) or
offset(x - 1).
formula_add_intercept(formula)formula_add_intercept(formula)
formula |
a formula object. |
A formula object with an intercept.
Add prior object to a ggplot
geom_prior( x, xlim = NULL, x_seq = NULL, x_range_quant = NULL, n_points = 1000, n_samples = 10000, force_samples = FALSE, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, show_parameter = if (individual) 1 else NULL, individual = FALSE, rescale_x = FALSE, scale_y2 = 1, ... )geom_prior( x, xlim = NULL, x_seq = NULL, x_range_quant = NULL, n_points = 1000, n_samples = 10000, force_samples = FALSE, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, show_parameter = if (individual) 1 else NULL, individual = FALSE, rescale_x = FALSE, scale_y2 = 1, ... )
x |
a prior |
xlim |
plotting range of the prior |
x_seq |
sequence of x coordinates |
x_range_quant |
quantile used for
automatically obtaining |
n_points |
number of equally spaced points
in the |
n_samples |
number of samples from the prior
distribution if the density cannot be obtained
analytically (or if samples are forced with
|
force_samples |
should prior be sampled instead of obtaining analytic solution whenever possible |
transformation |
transformation to be applied to the prior distribution. Either a character specifying one of the prepared transformations:
, or a list containing the transformation function |
transformation_arguments |
a list with named arguments for
the |
transformation_settings |
boolean indicating whether the
settings the |
show_parameter |
which parameter should be returned in case of
multiple parameters per prior. Useful when priors for the omega
parameter are plotted and |
individual |
should individual densities be returned (e.g., in case of weightfunction) |
rescale_x |
allows to rescale x-axis in case a weightfunction is plotted. |
scale_y2 |
scaling factor for a secondary axis |
... |
additional arguments |
geom_prior_list returns an object of class 'ggplot'.
Add list of prior objects to a plot
geom_prior_list( prior_list, xlim = NULL, x_seq = NULL, x_range_quant = NULL, n_points = 500, n_samples = 10000, force_samples = FALSE, individual = FALSE, show_figures = if (individual) 1 else NULL, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, rescale_x = FALSE, scale_y2 = NULL, prior_list_mu = NULL, effect_direction = "positive", ... )geom_prior_list( prior_list, xlim = NULL, x_seq = NULL, x_range_quant = NULL, n_points = 500, n_samples = 10000, force_samples = FALSE, individual = FALSE, show_figures = if (individual) 1 else NULL, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, rescale_x = FALSE, scale_y2 = NULL, prior_list_mu = NULL, effect_direction = "positive", ... )
prior_list |
list of prior distributions |
xlim |
x plotting range |
x_seq |
sequence of x coordinates |
x_range_quant |
quantile used for
automatically obtaining |
n_points |
number of equally spaced points
in the |
n_samples |
number of samples from the prior
distribution if the density cannot be obtained
analytically (or if samples are forced with
|
force_samples |
should prior be sampled instead of obtaining analytic solution whenever possible |
individual |
should individual densities be returned (e.g., in case of weightfunction) |
show_figures |
which figures should be returned in case of
multiple plots are generated. Useful when priors for the omega
parameter are plotted and |
transformation |
transformation to be applied to the prior distribution. Either a character specifying one of the prepared transformations:
, or a list containing the transformation function |
transformation_arguments |
a list with named arguments for
the |
transformation_settings |
boolean indicating whether the
settings the |
rescale_x |
allows to rescale x-axis in case a weightfunction is plotted. |
scale_y2 |
scaling factor for a secondary axis |
prior_list_mu |
list of priors for the mu parameter required when plotting PET-PEESE |
effect_direction |
direction of the effect for PET-PEESE
regression. Use |
... |
additional arguments |
geom_prior_list returns an object of class 'ggplot'.
plot_prior_list() lines_prior_list()
Computes inclusion Bayes factors based on prior model probabilities, posterior model probabilities (or marginal likelihoods), and indicator whether the models represent the null or alternative hypothesis.
inclusion_BF(prior_probs, post_probs, margliks, is_null)inclusion_BF(prior_probs, post_probs, margliks, is_null)
prior_probs |
vector of prior model probabilities |
post_probs |
vector of posterior model probabilities |
margliks |
vector of marginal likelihoods. |
is_null |
logical vector of indicators whether the model corresponds to the null or alternative hypothesis (or an integer vector indexing models corresponding to the null hypothesis) |
Supplying margliks as the input is preferred since it is better at dealing with
under/overflow (posterior probabilities are very close to either 0 or 1). In case that both the
post_probs and margliks are supplied, the results are based on margliks.
If the prior probability of either the null or alternative hypothesis is
zero, the Bayes factor is undefined and NA is returned.
inclusion_BF returns a Bayes factor.
Provides textual summary for posterior distributions created by mix_posteriors and ensemble inference created by ensemble_inference.
interpret(inference, samples, specification, method) interpret2(specification, method = NULL)interpret(inference, samples, specification, method) interpret2(specification, method = NULL)
inference |
model inference created by ensemble_inference |
samples |
posterior samples created by mix_posteriors |
specification |
list of lists specifying the generated text.
Each inner list carries: (1) |
method |
character specifying name of the method to be appended at the beginning of each sentence. |
interpret returns character.
ensemble_inference mix_posteriors BayesTools_model_tables BayesTools_ensemble_tables
interpret_records normalizes interpretation inputs from
one or more structured sources into traceable evidence, estimate, header,
note, prior, and footnote records. It is intended for downstream packages
that already own the domain-specific ordering and wording of an
interpretation, but want BayesTools to consistently extract table rows,
preserve Bayes-factor metadata, and carry traceability information.
interpret_records( sources, plan, output = c("records", "text"), missing = c("error", "skip", "warn"), method = NULL, digits = 3 ) interpret_tables(sources, spec, ...)interpret_records( sources, plan, output = c("records", "text"), missing = c("error", "skip", "warn"), method = NULL, digits = 3 ) interpret_tables(sources, spec, ...)
sources |
named list of interpretation sources. Each source can be a
|
plan |
ordered list specifying which records to create. Plan items can
have |
output |
whether to return normalized |
missing |
how missing optional sources or rows should be handled. |
method |
optional method name used only by the generic text renderer. |
digits |
number of digits used only by the generic text renderer. |
spec |
alias for |
... |
additional arguments passed from |
interpret_records returns a data frame with class
"BayesTools_interpret_records" when output = "records", or a
character vector when output = "text". interpret_tables is a
convenience wrapper around interpret_records.
Reports whether x is a composed publication-bias prior
is_prior_bias(x)is_prior_bias(x)
x |
object to test. |
A logical value.
Reports whether x is a p-hacking prior
is_prior_phacking(x)is_prior_phacking(x)
x |
object to test. |
A logical value.
Reports whether x is a a prior object. Note that point priors inherit the prior.simple property
is.prior(x) is.prior.point(x) is.prior.none(x) is.prior.simple(x) is.prior.discrete(x) is.prior.vector(x) is.prior.PET(x) is.prior.PEESE(x) is.prior.weightfunction(x) is.prior.factor(x) is.prior.orthonormal(x) is.prior.treatment(x) is.prior.independent(x) is.prior.spike_and_slab(x) is.prior.meandif(x) is.prior.mixture(x)is.prior(x) is.prior.point(x) is.prior.none(x) is.prior.simple(x) is.prior.discrete(x) is.prior.vector(x) is.prior.PET(x) is.prior.PEESE(x) is.prior.weightfunction(x) is.prior.factor(x) is.prior.orthonormal(x) is.prior.treatment(x) is.prior.independent(x) is.prior.spike_and_slab(x) is.prior.meandif(x) is.prior.mixture(x)
x |
an object of test |
returns a boolean indicating whether the test object is a prior (of specific type).
# create some prior distributions p0 <- prior(distribution = "point", parameters = list(location = 0)) p1 <- prior_PET(distribution = "normal", parameters = list(mean = 0, sd = 1)) is.prior(p0) is.prior.simple(p0) is.prior.point(p0) is.prior.PET(p0) is.prior(p1) is.prior.simple(p1) is.prior.point(p1) is.prior.PET(p1)# create some prior distributions p0 <- prior(distribution = "point", parameters = list(location = 0)) p1 <- prior_PET(distribution = "normal", parameters = list(mean = 0, sd = 1)) is.prior(p0) is.prior.simple(p0) is.prior.point(p0) is.prior.PET(p0) is.prior(p1) is.prior.simple(p1) is.prior.point(p1) is.prior.PET(p1)
Adds priors to a 'JAGS' syntax.
JAGS_add_priors(syntax, prior_list)JAGS_add_priors(syntax, prior_list)
syntax |
JAGS model syntax |
prior_list |
named list of prior distribution (names correspond to the parameter names) |
JAGS_add_priors returns a JAGS syntax.
A wrapper around
bridge_sampler that automatically
computes likelihood part dependent on the prior distribution
and prepares parameter samples. log_posterior must
specify a function that takes two arguments - a named list
of samples from the prior distributions and the data, and returns
log likelihood of the model part.
JAGS_bridgesampling( fit, log_posterior, data = NULL, prior_list = NULL, formula_list = NULL, formula_data_list = NULL, formula_prior_list = NULL, formula_scale_list = NULL, add_parameters = NULL, add_bounds = NULL, maxiter = 10000, silent = TRUE, ... )JAGS_bridgesampling( fit, log_posterior, data = NULL, prior_list = NULL, formula_list = NULL, formula_data_list = NULL, formula_prior_list = NULL, formula_scale_list = NULL, add_parameters = NULL, add_bounds = NULL, maxiter = 10000, silent = TRUE, ... )
fit |
model fitted with either runjags posterior samples obtained with rjags-package |
log_posterior |
function that takes a named list of samples, the data,
and additional list of parameters passed as |
data |
list containing data to fit the model (not including data for the formulas) |
prior_list |
named list of prior distribution
(names correspond to the parameter names) of parameters not specified within the
|
formula_list |
named list of formulas to be added to the model (names correspond to the parameter name created by each of the formula) |
formula_data_list |
named list of data frames containing data for each formula (names of the lists correspond to the parameter name created by each of the formula) |
formula_prior_list |
named list of named lists of prior distributions
(names of the lists correspond to the parameter name created by each of the formula and
the names of the prior distribution correspond to the parameter names) of parameters specified
within the |
formula_scale_list |
named list of named lists for standardizing continuous predictors
(names of the lists correspond to the parameter name created by each of the formula).
Each entry should be a named list where continuous predictors with |
add_parameters |
vector of additional parameter names that should be used
in bridgesampling but were not specified in the |
add_bounds |
list with two name vectors ( |
maxiter |
maximum number of iterations for the bridge_sampler |
silent |
whether the progress should be printed, defaults to |
... |
additional argument to the bridge_sampler
and |
JAGS_bridgesampling returns an object of class 'bridge'.
## Not run: # simulate data set.seed(1) data <- list( x = rnorm(10), N = 10 ) data$x # define priors priors_list <- list(mu = prior("normal", list(0, 1))) # define likelihood for the data model_syntax <- "model{ for(i in 1:N){ x[i] ~ dnorm(mu, 1) } }" # fit the models fit <- JAGS_fit(model_syntax, data, priors_list) # define log posterior for bridge sampling log_posterior <- function(parameters, data){ sum(dnorm(data$x, parameters$mu, 1, log = TRUE)) } # get marginal likelihoods marglik <- JAGS_bridgesampling(fit, log_posterior, data, priors_list) ## End(Not run)## Not run: # simulate data set.seed(1) data <- list( x = rnorm(10), N = 10 ) data$x # define priors priors_list <- list(mu = prior("normal", list(0, 1))) # define likelihood for the data model_syntax <- "model{ for(i in 1:N){ x[i] ~ dnorm(mu, 1) } }" # fit the models fit <- JAGS_fit(model_syntax, data, priors_list) # define log posterior for bridge sampling log_posterior <- function(parameters, data){ sum(dnorm(data$x, parameters$mu, 1, log = TRUE)) } # get marginal likelihoods marglik <- JAGS_bridgesampling(fit, log_posterior, data, priors_list) ## End(Not run)
prepares posterior distribution for 'bridgesampling' by removing unnecessary parameters and attaching lower and upper bounds of parameters based on a list of prior distributions.
JAGS_bridgesampling_posterior( posterior, prior_list, add_parameters = NULL, add_bounds = NULL )JAGS_bridgesampling_posterior( posterior, prior_list, add_parameters = NULL, add_bounds = NULL )
posterior |
matrix of mcmc samples from the posterior distribution |
prior_list |
named list of prior distribution
(names correspond to the parameter names) of parameters not specified within the
|
add_parameters |
vector of additional parameter names that should be used
in bridgesampling but were not specified in the |
add_bounds |
list with two name vectors ( |
JAGS_bridgesampling_posterior returns a matrix of
posterior samples with 'lb' and 'ub' attributes carrying the
lower and upper boundaries.
Checks and lists settings for the JAGS_fit function.
JAGS_check_and_list_fit_settings( chains, adapt, burnin, sample, thin, autofit, parallel, cores, silent, seed, check_mins = list(chains = 1, adapt = 50, burnin = 50, sample = 100, thin = 1), call = "" ) JAGS_check_and_list_autofit_settings( autofit_control, skip_sample_extend = FALSE, call = "" )JAGS_check_and_list_fit_settings( chains, adapt, burnin, sample, thin, autofit, parallel, cores, silent, seed, check_mins = list(chains = 1, adapt = 50, burnin = 50, sample = 100, thin = 1), call = "" ) JAGS_check_and_list_autofit_settings( autofit_control, skip_sample_extend = FALSE, call = "" )
chains |
number of chains to be run, defaults to |
adapt |
number of samples used for adapting the MCMC chains, defaults to |
burnin |
number of burnin iterations of the MCMC chains, defaults to |
sample |
number of sampling iterations of the MCMC chains, defaults to |
thin |
thinning interval for the MCMC samples, defaults to |
autofit |
whether the models should be refitted until convergence criteria
specified in |
parallel |
whether the chains should be run in parallel |
cores |
number of cores used for multithreading if |
silent |
whether the function should proceed silently, defaults to |
seed |
seed for random number generation |
check_mins |
named list of minimal values for which should some input be checked. Defaults to:
|
call |
string to be placed as a prefix to the error call. |
autofit_control |
a list of arguments controlling the autofit function. Possible options are:
|
skip_sample_extend |
whether |
JAGS_check_and_list_fit_settings invisibly returns a
list of checked fit settings. JAGS_check_and_list_autofit_settings
invisibly returns a list of checked autofit settings.
parameter names.
Checks whether the supplied runjags-package model satisfied convergence criteria.
JAGS_check_convergence( fit, prior_list, max_Rhat = 1.05, min_ESS = 500, max_error = 0.01, max_SD_error = 0.05, add_parameters = NULL, fail_fast = FALSE, check_indicators = FALSE )JAGS_check_convergence( fit, prior_list, max_Rhat = 1.05, min_ESS = 500, max_error = 0.01, max_SD_error = 0.05, add_parameters = NULL, fail_fast = FALSE, check_indicators = FALSE )
fit |
a runjags model |
prior_list |
named list of prior distribution (names correspond to the parameter names) |
max_Rhat |
maximum R-hat error for the autofit function.
Defaults to |
min_ESS |
minimum effective sample size. Defaults to |
max_error |
maximum MCMC error. Defaults to |
max_SD_error |
maximum MCMC error as the proportion of standard
deviation of the parameters. Defaults to |
add_parameters |
vector of additional parameter names that should be used (only allows removing last, fixed, omega element if omega is tracked manually). |
fail_fast |
whether the function should stop after the first failed convergence check. |
check_indicators |
whether model indicator variables should be included
in convergence checks. Defaults to |
JAGS_check_convergence returns a boolean
indicating whether the model converged or not, with an
attribute 'errors' carrying the failed convergence checks (if any).
## Not run: # simulate data set.seed(1) data <- list( x = rnorm(10), N = 10 ) data$x # define priors priors_list <- list(mu = prior("normal", list(0, 1))) # define likelihood for the data model_syntax <- "model{ for(i in 1:N){ x[i] ~ dnorm(mu, 1) } }" # fit the models fit <- JAGS_fit(model_syntax, data, priors_list) JAGS_check_convergence(fit, priors_list) ## End(Not run)## Not run: # simulate data set.seed(1) data <- list( x = rnorm(10), N = 10 ) data$x # define priors priors_list <- list(mu = prior("normal", list(0, 1))) # define likelihood for the data model_syntax <- "model{ for(i in 1:N){ x[i] ~ dnorm(mu, 1) } }" # fit the models fit <- JAGS_fit(model_syntax, data, priors_list) JAGS_check_convergence(fit, priors_list) ## End(Not run)
Creates density plots, trace plots, and autocorrelation plots for a given parameter of a JAGS model.
JAGS_diagnostics( fit, parameter, type, plot_type = "base", xlim = NULL, ylim = NULL, lags = 30, n_points = 1000, transformations = NULL, transform_factors = FALSE, transform_orthonormal = FALSE, short_name = FALSE, parameter_names = FALSE, formula_prefix = TRUE, ... ) JAGS_diagnostics_density( fit, parameter, plot_type = "base", xlim = NULL, n_points = 1000, transformations = NULL, transform_factors = FALSE, transform_orthonormal = FALSE, short_name = FALSE, parameter_names = FALSE, formula_prefix = TRUE, ... ) JAGS_diagnostics_trace( fit, parameter, plot_type = "base", ylim = NULL, transformations = NULL, transform_factors = FALSE, transform_orthonormal = FALSE, short_name = FALSE, parameter_names = FALSE, formula_prefix = TRUE, ... ) JAGS_diagnostics_autocorrelation( fit, parameter, plot_type = "base", lags = 30, transformations = NULL, transform_factors = FALSE, transform_orthonormal = FALSE, short_name = FALSE, parameter_names = FALSE, formula_prefix = TRUE, ... )JAGS_diagnostics( fit, parameter, type, plot_type = "base", xlim = NULL, ylim = NULL, lags = 30, n_points = 1000, transformations = NULL, transform_factors = FALSE, transform_orthonormal = FALSE, short_name = FALSE, parameter_names = FALSE, formula_prefix = TRUE, ... ) JAGS_diagnostics_density( fit, parameter, plot_type = "base", xlim = NULL, n_points = 1000, transformations = NULL, transform_factors = FALSE, transform_orthonormal = FALSE, short_name = FALSE, parameter_names = FALSE, formula_prefix = TRUE, ... ) JAGS_diagnostics_trace( fit, parameter, plot_type = "base", ylim = NULL, transformations = NULL, transform_factors = FALSE, transform_orthonormal = FALSE, short_name = FALSE, parameter_names = FALSE, formula_prefix = TRUE, ... ) JAGS_diagnostics_autocorrelation( fit, parameter, plot_type = "base", lags = 30, transformations = NULL, transform_factors = FALSE, transform_orthonormal = FALSE, short_name = FALSE, parameter_names = FALSE, formula_prefix = TRUE, ... )
fit |
a JAGS model fitted via |
parameter |
parameter to be plotted |
type |
what type of model diagnostic should be plotted. The available
options are |
plot_type |
whether to use a base plot |
xlim |
x plotting range |
ylim |
y plotting range |
lags |
number of lags to be shown for the autocorrelation plot.
Defaults to |
n_points |
number of equally spaced points
in the |
transformations |
named list of transformations to be applied to specific parameters |
transform_factors |
whether factors with orthonormal/meandif prior distribution should be transformed to differences from the grand mean |
transform_orthonormal |
(to be depreciated) whether factors with orthonormal prior distributions should be transformed to differences from the grand mean |
short_name |
whether prior distribution names should be shorted |
parameter_names |
whether parameter names should be printed |
formula_prefix |
whether the parameter prefix from formula should
be printed. Defaults to |
... |
additional arguments |
diagnostics returns either NULL if plot_type = "base"
or an object/list of objects (depending on the number of parameters to be plotted)
of class 'ggplot2' if plot_type = "ggplot2".
JAGS_fit() JAGS_check_convergence()
Evaluates a JAGS formula on a posterior distribution obtained from a fitted model.
JAGS_evaluate_formula(fit, formula, parameter, data, prior_list)JAGS_evaluate_formula(fit, formula, parameter, data, prior_list)
fit |
model fitted with either runjags posterior samples obtained with rjags-package |
formula |
formula specifying the right hand side of the assignment (the
left hand side is ignored). If the formula has a |
parameter |
name of the parameter created with the formula |
data |
data.frame containing predictors included in the formula |
prior_list |
named list of prior distribution of parameters specified within
the |
JAGS_evaluate_formula returns a matrix of the evaluated posterior samples on
the supplied data.
A wrapper around run.jags that simplifies fitting 'JAGS' models with usage with pre-specified model part of the 'JAGS' syntax, data and list of prior distributions.
JAGS_fit( model_syntax, data = NULL, prior_list = NULL, formula_list = NULL, formula_data_list = NULL, formula_prior_list = NULL, formula_scale_list = NULL, chains = 4, adapt = 500, burnin = 1000, sample = 4000, thin = 1, autofit = FALSE, autofit_control = list(max_Rhat = 1.05, min_ESS = 500, max_error = 0.01, max_SD_error = 0.05, max_time = list(time = 60, unit = "mins"), sample_extend = 1000, restarts = 10, max_extend = 10, check_indicators = FALSE), parallel = FALSE, cores = chains, silent = TRUE, seed = NULL, add_parameters = NULL, required_packages = NULL, ... ) JAGS_extend( fit, autofit_control = list(max_Rhat = 1.05, min_ESS = 500, max_error = 0.01, max_SD_error = 0.05, max_time = list(time = 60, unit = "mins"), sample_extend = 1000, restarts = 10, max_extend = 10, check_indicators = FALSE), parallel = FALSE, cores = NULL, silent = TRUE, seed = NULL )JAGS_fit( model_syntax, data = NULL, prior_list = NULL, formula_list = NULL, formula_data_list = NULL, formula_prior_list = NULL, formula_scale_list = NULL, chains = 4, adapt = 500, burnin = 1000, sample = 4000, thin = 1, autofit = FALSE, autofit_control = list(max_Rhat = 1.05, min_ESS = 500, max_error = 0.01, max_SD_error = 0.05, max_time = list(time = 60, unit = "mins"), sample_extend = 1000, restarts = 10, max_extend = 10, check_indicators = FALSE), parallel = FALSE, cores = chains, silent = TRUE, seed = NULL, add_parameters = NULL, required_packages = NULL, ... ) JAGS_extend( fit, autofit_control = list(max_Rhat = 1.05, min_ESS = 500, max_error = 0.01, max_SD_error = 0.05, max_time = list(time = 60, unit = "mins"), sample_extend = 1000, restarts = 10, max_extend = 10, check_indicators = FALSE), parallel = FALSE, cores = NULL, silent = TRUE, seed = NULL )
model_syntax |
jags syntax for the model part |
data |
list containing data to fit the model (not including data for the formulas) |
prior_list |
named list of prior distribution
(names correspond to the parameter names) of parameters not specified within the
|
formula_list |
named list of formulas to be added to the model (names correspond to the parameter name created by each of the formula) |
formula_data_list |
named list of data frames containing data for each formula (names of the lists correspond to the parameter name created by each of the formula) |
formula_prior_list |
named list of named lists of prior distributions
(names of the lists correspond to the parameter name created by each of the formula and
the names of the prior distribution correspond to the parameter names) of parameters specified
within the |
formula_scale_list |
named list of named lists for standardizing continuous predictors
(names of the lists correspond to the parameter name created by each of the formula).
Each entry should be a named list where continuous predictors with |
chains |
number of chains to be run, defaults to |
adapt |
number of samples used for adapting the MCMC chains, defaults to |
burnin |
number of burnin iterations of the MCMC chains, defaults to |
sample |
number of sampling iterations of the MCMC chains, defaults to |
thin |
thinning interval for the MCMC samples, defaults to |
autofit |
whether the models should be refitted until convergence criteria
specified in |
autofit_control |
a list of arguments controlling the autofit function. Possible options are:
|
parallel |
whether the chains should be run in parallel |
cores |
number of cores used for multithreading if |
silent |
whether the function should proceed silently, defaults to |
seed |
seed for random number generation |
add_parameters |
vector of additional parameter names that should be used
monitored but were not specified in the |
required_packages |
character vector specifying list of packages containing
JAGS models required for sampling (in case that the function is run in parallel or in
detached R session). Defaults to |
... |
additional hidden arguments |
fit |
a 'BayesTools_fit' object (created by |
JAGS_fit returns an object of class 'runjags' and 'BayesTools_fit'.
## Not run: # simulate data set.seed(1) data <- list( x = rnorm(10), N = 10 ) data$x # define priors priors_list <- list(mu = prior("normal", list(0, 1))) # define likelihood for the data model_syntax <- "model{ for(i in 1:N){ x[i] ~ dnorm(mu, 1) } }" # fit the models fit <- JAGS_fit(model_syntax, data, priors_list) ## End(Not run)## Not run: # simulate data set.seed(1) data <- list( x = rnorm(10), N = 10 ) data$x # define priors priors_list <- list(mu = prior("normal", list(0, 1))) # define likelihood for the data model_syntax <- "model{ for(i in 1:N){ x[i] ~ dnorm(mu, 1) } }" # fit the models fit <- JAGS_fit(model_syntax, data, priors_list) ## End(Not run)
Creates a JAGS formula syntax, prepares data input, and
returns modified prior list for further processing in the JAGS_fit
function.
JAGS_formula(formula, parameter, data, prior_list, formula_scale = NULL)JAGS_formula(formula, parameter, data, prior_list, formula_scale = NULL)
formula |
formula specifying the right hand side of the assignment (the
left hand side is ignored). If the formula contains |
parameter |
name of the parameter to be created with the formula |
data |
data.frame containing predictors included in the formula |
prior_list |
named list of prior distribution of parameters specified within
the |
formula_scale |
named list specifying whether to standardize continuous predictors.
If
These default priors allow for more concise specification when many predictors share the same prior distribution. |
When a formula with -1 (no intercept) is specified, the
function automatically removes the -1, adds an intercept back to the
formula, and includes a spike(0) prior for the intercept to ensure equivalent
model behavior while maintaining consistent formula parsing.
When using default priors ("__default_continuous" or "__default_factor"),
explicitly specified priors for individual terms take precedence over the defaults.
The defaults are only applied to terms that are not already in the prior list.
JAGS_formula returns a list containing the formula JAGS syntax,
JAGS data object, modified prior_list, and (if standardization was applied) a
formula_scale list with standardization information for back-transformation.
# simulate data set.seed(1) df <- data.frame( y = rnorm(60), x_cont = rnorm(60), x_bin = rbinom(60, 1, .5), x_fac3 = factor(rep(c("A", "B", "C"), 20), levels = c("A", "B", "C")), x_fac4 = factor(rep(c("A", "B", "C", "D"), 15), levels = c("A", "B", "C", "D")) ) # specify priors with intercept prior_list <- list( "intercept" = prior("normal", list(0, 1)), "x_cont" = prior("normal", list(0, .5)), "x_fac3" = prior_factor("normal", list(0, 1), contrast = "treatment"), "x_fac4" = prior_factor("mnormal", list(0, 1), contrast = "orthonormal"), "x_fac3:x_fac4" = prior_factor("mnormal", list(0, .5), contrast = "orthonormal") ) # create the formula object formula_obj <- JAGS_formula( formula = ~ x_cont + x_fac3 * x_fac4, parameter = "mu", data = df, prior_list = prior_list) # using -1 notation (automatically adds spike(0) intercept) prior_list_no_intercept <- list( "x_fac3" = prior_factor("normal", list(0, 1), contrast = "treatment") ) formula_no_intercept <- JAGS_formula( formula = ~ x_fac3 - 1, parameter = "mu", data = df, prior_list = prior_list_no_intercept) # Equivalent to specifying intercept = prior("spike", list(0)) # using default priors for simpler specification prior_list_defaults <- list( "__default_continuous" = prior("normal", list(0, 1)), "__default_factor" = prior_factor("normal", list(0, 0.5), contrast = "treatment") ) formula_defaults <- JAGS_formula( formula = ~ x_cont + x_fac3, parameter = "mu", data = df, prior_list = prior_list_defaults) # intercept and x_cont get the default continuous prior # x_fac3 gets the default factor prior# simulate data set.seed(1) df <- data.frame( y = rnorm(60), x_cont = rnorm(60), x_bin = rbinom(60, 1, .5), x_fac3 = factor(rep(c("A", "B", "C"), 20), levels = c("A", "B", "C")), x_fac4 = factor(rep(c("A", "B", "C", "D"), 15), levels = c("A", "B", "C", "D")) ) # specify priors with intercept prior_list <- list( "intercept" = prior("normal", list(0, 1)), "x_cont" = prior("normal", list(0, .5)), "x_fac3" = prior_factor("normal", list(0, 1), contrast = "treatment"), "x_fac4" = prior_factor("mnormal", list(0, 1), contrast = "orthonormal"), "x_fac3:x_fac4" = prior_factor("mnormal", list(0, .5), contrast = "orthonormal") ) # create the formula object formula_obj <- JAGS_formula( formula = ~ x_cont + x_fac3 * x_fac4, parameter = "mu", data = df, prior_list = prior_list) # using -1 notation (automatically adds spike(0) intercept) prior_list_no_intercept <- list( "x_fac3" = prior_factor("normal", list(0, 1), contrast = "treatment") ) formula_no_intercept <- JAGS_formula( formula = ~ x_fac3 - 1, parameter = "mu", data = df, prior_list = prior_list_no_intercept) # Equivalent to specifying intercept = prior("spike", list(0)) # using default priors for simpler specification prior_list_defaults <- list( "__default_continuous" = prior("normal", list(0, 1)), "__default_factor" = prior_factor("normal", list(0, 0.5), contrast = "treatment") ) formula_defaults <- JAGS_formula( formula = ~ x_cont + x_fac3, parameter = "mu", data = df, prior_list = prior_list_defaults) # intercept and x_cont get the default continuous prior # x_fac3 gets the default factor prior
Returns the fitted formula design metadata stored by
JAGS_fit(). The design contains the processed formula, fitted model frame,
exact model matrix used for JAGS data construction, JAGS-safe coefficient
names, contrast and factor-level metadata, rank diagnostics, prior metadata,
and formula-scale information.
JAGS_formula_design(fit, parameter = NULL)JAGS_formula_design(fit, parameter = NULL)
fit |
a fitted object returned by |
parameter |
optional formula parameter name. If |
A named list of formula designs, or one formula design when
parameter is supplied. Returns NULL when no formula design
metadata is stored on fit.
Creates initial values for priors in a 'JAGS' model.
JAGS_get_inits(prior_list, chains, seed)JAGS_get_inits(prior_list, chains, seed)
prior_list |
named list of prior distribution (names correspond to the parameter names) |
chains |
number of chains |
seed |
seed for random number generation |
JAGS_add_priors returns a list of JAGS
initial values.
Extracts transformed parameters from the prior part of a 'JAGS' model inside of a 'bridgesampling' function (returns them as a named list)
JAGS_marglik_parameters(samples, prior_list) JAGS_marglik_parameters_formula( samples, formula_list, formula_data_list, formula_prior_list, prior_list_parameters )JAGS_marglik_parameters(samples, prior_list) JAGS_marglik_parameters_formula( samples, formula_list, formula_data_list, formula_prior_list, prior_list_parameters )
samples |
samples provided by bridgesampling function |
prior_list |
named list of prior distribution
(names correspond to the parameter names) of parameters not specified within the
|
formula_list |
named list of formulas to be added to the model (names correspond to the parameter name created by each of the formula) |
formula_data_list |
named list of data frames containing data for each formula (names of the lists correspond to the parameter name created by each of the formula) |
formula_prior_list |
named list of named lists of prior distributions
(names of the lists correspond to the parameter name created by each of the formula and
the names of the prior distribution correspond to the parameter names) of parameters specified
within the |
prior_list_parameters |
named list of prior distributions on model parameters (not specified within the formula but that might scale the formula parameters) |
JAGS_marglik_parameters returns a named list
of (transformed) posterior samples.
Computes marginal likelihood for the prior part of a 'JAGS' model within 'bridgesampling' function
JAGS_marglik_priors(samples, prior_list) JAGS_marglik_priors_formula(samples, formula_prior_list)JAGS_marglik_priors(samples, prior_list) JAGS_marglik_priors_formula(samples, formula_prior_list)
samples |
samples provided by bridgesampling function |
prior_list |
named list of prior distribution
(names correspond to the parameter names) of parameters not specified within the
|
formula_prior_list |
named list of named lists of prior distributions
(names of the lists correspond to the parameter name created by each of the formula and
the names of the prior distribution correspond to the parameter names) of parameters specified
within the |
JAGS_marglik_priors returns a numeric value
of likelihood evaluated at the current posterior sample.
Creates a vector of parameter names to be monitored in a 'JAGS' model.
JAGS_to_monitor(prior_list)JAGS_to_monitor(prior_list)
prior_list |
named list of prior distribution (names correspond to the parameter names) |
JAGS_to_monitor returns a character vector of
parameter names.
The data set contains mean NEO PI-R scores for two groups of students. Each of them filled a personality questionnaire while rotating a kitchen roll either clock or counter-clock wise. See Wagenmakers et al. (2015) for more details about the replication study and the https://osf.io/uszvx/ for the original data.
kitchen_rollskitchen_rolls
A data.frame with 2 columns and 102 observations.
a data.frame.
Wagenmakers E, Beek TF, Rotteveel M, Gierholz A, Matzke D, Steingroever H, Ly A, Verhagen J, Selker R, Sasiadek A, others (2015). “Turning the hands of time again: a purely confirmatory replication study and a Bayesian analysis.” Frontiers in Psychology, 6, 1–6. doi:10.3389/fpsyg.2015.00494.
Add list of prior objects to a plot
lines_prior_list( prior_list, xlim = NULL, x_seq = NULL, x_range_quant = NULL, n_points = 500, n_samples = 10000, force_samples = FALSE, individual = FALSE, show_figures = if (individual) 1 else NULL, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, rescale_x = FALSE, scale_y2 = NULL, prior_list_mu = NULL, effect_direction = "positive", ... )lines_prior_list( prior_list, xlim = NULL, x_seq = NULL, x_range_quant = NULL, n_points = 500, n_samples = 10000, force_samples = FALSE, individual = FALSE, show_figures = if (individual) 1 else NULL, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, rescale_x = FALSE, scale_y2 = NULL, prior_list_mu = NULL, effect_direction = "positive", ... )
prior_list |
list of prior distributions |
xlim |
x plotting range |
x_seq |
sequence of x coordinates |
x_range_quant |
quantile used for
automatically obtaining |
n_points |
number of equally spaced points
in the |
n_samples |
number of samples from the prior
distribution if the density cannot be obtained
analytically (or if samples are forced with
|
force_samples |
should prior be sampled instead of obtaining analytic solution whenever possible |
individual |
should individual densities be returned (e.g., in case of weightfunction) |
show_figures |
which figures should be returned in case of
multiple plots are generated. Useful when priors for the omega
parameter are plotted and |
transformation |
transformation to be applied to the prior distribution. Either a character specifying one of the prepared transformations:
, or a list containing the transformation function |
transformation_arguments |
a list with named arguments for
the |
transformation_settings |
boolean indicating whether the
settings the |
rescale_x |
allows to rescale x-axis in case a weightfunction is plotted. |
scale_y2 |
scaling factor for a secondary axis |
prior_list_mu |
list of priors for the mu parameter required when plotting PET-PEESE |
effect_direction |
direction of the effect for PET-PEESE
regression. Use |
... |
additional arguments |
lines_prior_list returns NULL.
plot_prior_list() geom_prior_list()
Add prior object to a plot
## S3 method for class 'prior' lines( x, xlim = NULL, x_seq = NULL, x_range_quant = NULL, n_points = 1000, n_samples = 10000, force_samples = FALSE, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, show_parameter = if (individual) 1 else NULL, individual = FALSE, rescale_x = FALSE, scale_y2 = 1, ... )## S3 method for class 'prior' lines( x, xlim = NULL, x_seq = NULL, x_range_quant = NULL, n_points = 1000, n_samples = 10000, force_samples = FALSE, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, show_parameter = if (individual) 1 else NULL, individual = FALSE, rescale_x = FALSE, scale_y2 = 1, ... )
x |
a prior |
xlim |
plotting range of the prior |
x_seq |
sequence of x coordinates |
x_range_quant |
quantile used for
automatically obtaining |
n_points |
number of equally spaced points
in the |
n_samples |
number of samples from the prior
distribution if the density cannot be obtained
analytically (or if samples are forced with
|
force_samples |
should prior be sampled instead of obtaining analytic solution whenever possible |
transformation |
transformation to be applied to the prior distribution. Either a character specifying one of the prepared transformations:
, or a list containing the transformation function |
transformation_arguments |
a list with named arguments for
the |
transformation_settings |
boolean indicating whether the
settings the |
show_parameter |
which parameter should be returned in case of
multiple parameters per prior. Useful when priors for the omega
parameter are plotted and |
individual |
should individual densities be returned (e.g., in case of weightfunction) |
rescale_x |
allows to rescale x-axis in case a weightfunction is plotted. |
scale_y2 |
scaling factor for a secondary axis |
... |
additional arguments |
lines.prior returns NULL.
Creates marginal model-averaged and conditional posterior distributions based on a list of models, vector of parameters, formula, and a list of indicators of the null or alternative hypothesis models for each parameter. Computes inclusion Bayes factors for each marginal estimate via a Savage-Dickey density approximation.
marginal_inference( model_list, marginal_parameters, parameters, is_null_list, formula, null_hypothesis = 0, normal_approximation = FALSE, n_samples = 10000, seed = NULL, silent = FALSE )marginal_inference( model_list, marginal_parameters, parameters, is_null_list, formula, null_hypothesis = 0, normal_approximation = FALSE, n_samples = 10000, seed = NULL, silent = FALSE )
model_list |
list of models, each of which contains marginal
likelihood estimated with bridge sampling |
marginal_parameters |
parameters for which the the marginal summary should be created |
parameters |
all parameters included in the model_list that are
relevant for the formula (all of which need to have specification of
|
is_null_list |
list with entries for each parameter carrying either logical vector of indicators specifying whether the model corresponds to the null or alternative hypothesis (or an integer vector indexing models corresponding to the null hypothesis) |
formula |
model formula (needs to be specified if |
null_hypothesis |
point null hypothesis to test. Defaults to |
normal_approximation |
whether the height of prior and posterior density should be
approximated via a normal distribution (rather than kernel density). Defaults to |
n_samples |
controls the numerical grid used for model-averaged prior densities |
seed |
seed for random number generation |
silent |
whether warnings should be returned silently. Defaults to |
marginal_inference returns an object of class 'marginal_inference'.
ensemble_inference mix_posteriors BayesTools_ensemble_tables
Creates marginal model-averages posterior distributions for a given parameter based on model-averaged posterior samples and parameter name (and formula with at specification).
marginal_posterior( samples, parameter, formula = NULL, at = NULL, prior_samples = FALSE, use_formula = TRUE, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, n_samples = 10000, ... )marginal_posterior( samples, parameter, formula = NULL, at = NULL, prior_samples = FALSE, use_formula = TRUE, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, n_samples = 10000, ... )
samples |
model-averaged posterior samples created by |
parameter |
parameter of interest |
formula |
model formula (needs to be specified if |
at |
named list with predictor levels of the formula for which marginalization
should be performed. If a predictor level is missing, |
prior_samples |
whether marginal prior distributions should be generated
|
use_formula |
whether the parameter should be evaluated as a part of supplied formula |
transformation |
transformation to be applied to the prior distribution. Either a character specifying one of the prepared transformations:
, or a list containing the transformation function |
transformation_arguments |
a list with named arguments for
the |
transformation_settings |
boolean indicating whether the
settings the |
n_samples |
controls the numerical grid used for model-averaged prior densities |
... |
additional arguments |
marginal_posterior returns a named list of mixed marginal posterior
distributions (either a vector of matrix).
#'
Computes mean of a prior distribution. (In case of orthonormal prior distributions for factors, the mean of for the deviations from intercept is returned.)
## S3 method for class 'prior' mean(x, ...)## S3 method for class 'prior' mean(x, ...)
x |
a prior |
... |
unused |
a mean of an object of class 'prior'.
# create a standard normal prior distribution p1 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1)) # compute mean of the prior distribution mean(p1)# create a standard normal prior distribution p1 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1)) # compute mean of the prior distribution mean(p1)
Model-averages posterior distributions based on a list of models, vector of parameters, and a list of indicators of the null or alternative hypothesis models for each parameter.
mix_posteriors( model_list, parameters, is_null_list, conditional = FALSE, seed = NULL, n_samples = 10000 )mix_posteriors( model_list, parameters, is_null_list, conditional = FALSE, seed = NULL, n_samples = 10000 )
model_list |
list of models, each of which contains marginal
likelihood estimated with bridge sampling |
parameters |
vector of parameters names for which inference should be drawn |
is_null_list |
list with entries for each parameter carrying either logical vector of indicators specifying whether the model corresponds to the null or alternative hypothesis (or an integer vector indexing models corresponding to the null hypothesis) |
conditional |
whether prior and posterior model probabilities should
be returned only for the conditional model. Defaults to |
seed |
integer specifying seed for sampling posteriors for
model averaging. Defaults to |
n_samples |
number of samples to be drawn for the model-averaged posterior distribution |
mix_posteriors returns a named list of mixed posterior
distributions (either a vector of matrix).
ensemble_inference BayesTools_ensemble_tables as_mixed_posteriors
Density, distribution function, quantile function and random generation for multivariate point distribution.
dmpoint(x, location, log = FALSE) rmpoint(n, location) pmpoint(q, location, lower.tail = TRUE, log.p = FALSE) qmpoint(p, location, lower.tail = TRUE, log.p = FALSE)dmpoint(x, location, log = FALSE) rmpoint(n, location) pmpoint(q, location, lower.tail = TRUE, log.p = FALSE) qmpoint(p, location, lower.tail = TRUE, log.p = FALSE)
x, q
|
vector or matrix of quantiles. |
location |
vector of locations corresponding to the location of individual points. Alternatively, a matrix with rows corresponding to the location of individual samples and columns correspond to the location of individual points. |
log, log.p
|
logical; if |
n |
number of observations. |
lower.tail |
logical; if |
p |
vector of probabilities. |
dpoint gives the density, ppoint gives the
distribution function, qpoint gives the quantile function,
and rpoint generates random deviates.
# draw samples from a multivariate point distribution rmpoint(10, location = c(0, 1))# draw samples from a multivariate point distribution rmpoint(10, location = c(0, 1))
Removes additional formatting from parameter names outputted from JAGS.
format_parameter_names( parameters, formula_parameters = NULL, formula_random = NULL, formula_prefix = TRUE, formula_scale = NULL ) JAGS_parameter_names(parameters, formula_parameter = NULL)format_parameter_names( parameters, formula_parameters = NULL, formula_random = NULL, formula_prefix = TRUE, formula_scale = NULL ) JAGS_parameter_names(parameters, formula_parameter = NULL)
parameters |
a vector of parameter names |
formula_parameters |
a vector of formula parameter prefix names |
formula_random |
a vector of random effects grouping factors |
formula_prefix |
whether the |
formula_scale |
optional nested list containing scaling info. When provided,
intercepts from parameters with |
formula_parameter |
a formula parameter prefix name |
A character vector with reformatted parameter names.
format_parameter_names(c("mu_x_cont", "mu_x_fac3t", "mu_x_fac3t__xXx__x_cont"), formula_parameters = "mu")format_parameter_names(c("mu_x_cont", "mu_x_fac3t", "mu_x_fac3t__xXx__x_cont"), formula_parameters = "mu")
phack_pi_null() converts the sampled severity
alpha to the amount of null probability mass depleted from the source
interval. phack_alpha_from_pi_null() applies the inverse calibration.
phack_backend_constants() returns the z-scale constants used by the
backend.
phack_pi_null(alpha, form, source, destination, target = 0.025) phack_alpha_from_pi_null(pi_null, form, source, destination, target = 0.025) phack_backend_constants(form, source, destination, target = 0.025)phack_pi_null(alpha, form, source, destination, target = 0.025) phack_alpha_from_pi_null(pi_null, form, source, destination, target = 0.025) phack_backend_constants(form, source, destination, target = 0.025)
alpha |
p-hacking severity parameter. |
form |
power depletion form, either |
source |
source p-value cut point. |
destination |
destination p-value cut point. |
target |
target p-value cut point. |
pi_null |
null probability mass depleted from the source interval. |
Numeric vector for the calibration helpers and a named list for
phack_backend_constants().
Plot samples from the marginal posterior distributions
plot_marginal( samples, parameter, plot_type = "base", prior = FALSE, n_points = 1000, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, rescale_x = FALSE, par_name = NULL, dots_prior = list(), legend = TRUE, legend_title = NULL, legend_labels = NULL, legend_position = NULL, ... )plot_marginal( samples, parameter, plot_type = "base", prior = FALSE, n_points = 1000, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, rescale_x = FALSE, par_name = NULL, dots_prior = list(), legend = TRUE, legend_title = NULL, legend_labels = NULL, legend_position = NULL, ... )
samples |
samples from a posterior distribution for a parameter generated by marginal_inference. |
parameter |
parameter name to be plotted. |
plot_type |
whether to use a base plot |
prior |
whether prior distribution should be added to the figure.
When samples were prepared with |
n_points |
number of equally spaced points
in the |
transformation |
transformation to be applied to the prior distribution. Either a character specifying one of the prepared transformations:
, or a list containing the transformation function |
transformation_arguments |
a list with named arguments for
the |
transformation_settings |
boolean indicating whether the
settings the |
rescale_x |
allows to rescale x-axis in case a weightfunction is plotted. |
par_name |
a type of parameter for which the prior is specified. Only relevant if the prior corresponds to a mu parameter that needs to be transformed. |
dots_prior |
additional arguments for the prior distribution plot |
legend |
whether factor legends should be drawn. |
legend_title |
optional title for factor legends. |
legend_labels |
optional labels for factor legend levels. |
legend_position |
optional legend position for factor legends. |
... |
additional arguments |
plot_marginal returns either NULL or
an object of class 'ggplot' if plot_type is plot_type = "ggplot".
prior() marginal_inference() plot_posterior()
Plot estimates from models
plot_models( model_list, samples, inference, parameter, plot_type = "base", prior = FALSE, conditional = FALSE, order = NULL, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, par_name = NULL, formula_prefix = TRUE, ... )plot_models( model_list, samples, inference, parameter, plot_type = "base", prior = FALSE, conditional = FALSE, order = NULL, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, par_name = NULL, formula_prefix = TRUE, ... )
model_list |
list of models, each of which contains marginal
likelihood estimated with bridge sampling |
samples |
samples from a posterior distribution for a parameter generated by mix_posteriors or as_mixed_posteriors. |
inference |
object created by ensemble_inference function |
parameter |
parameter name to be plotted. Does not support PET-PEESE and weightfunction. |
plot_type |
whether to use a base plot |
prior |
whether prior distribution should be added to the figure.
When samples were prepared with |
conditional |
whether conditional models should be displayed |
order |
list specifying ordering of the models. The first
element describes whether the ordering should be |
transformation |
transformation to be applied to the prior distribution. Either a character specifying one of the prepared transformations:
, or a list containing the transformation function |
transformation_arguments |
a list with named arguments for
the |
transformation_settings |
boolean indicating whether the
settings the |
par_name |
a type of parameter for which the prior is specified. Only relevant if the prior corresponds to a mu parameter that needs to be transformed. |
formula_prefix |
whether the |
... |
additional arguments. E.g.:
|
Plots prior and posterior estimates of the same parameter across multiple models (prior distributions with orthonormal/meandif contrast are always plotted as differences from the grand mean).
plot_models returns either NULL or
an object of class 'ggplot' if plot_type is plot_type = "ggplot".
prior() lines_prior_list() geom_prior_list()
Plot samples from the mixed posterior distributions
plot_posterior( samples, parameter, plot_type = "base", prior = FALSE, n_points = 1000, n_samples = 10000, force_samples = FALSE, individual = FALSE, show_figures = NULL, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, rescale_x = FALSE, par_name = NULL, effect_direction = "positive", dots_prior = list(), data = NULL, show_data = FALSE, dots_data = list(), legend = TRUE, legend_title = NULL, legend_labels = NULL, legend_position = NULL, ... )plot_posterior( samples, parameter, plot_type = "base", prior = FALSE, n_points = 1000, n_samples = 10000, force_samples = FALSE, individual = FALSE, show_figures = NULL, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, rescale_x = FALSE, par_name = NULL, effect_direction = "positive", dots_prior = list(), data = NULL, show_data = FALSE, dots_data = list(), legend = TRUE, legend_title = NULL, legend_labels = NULL, legend_position = NULL, ... )
samples |
samples from a posterior distribution for a parameter generated by mix_posteriors or as_mixed_posteriors. |
parameter |
parameter name to be plotted. Use |
plot_type |
whether to use a base plot |
prior |
whether prior distribution should be added to the figure.
When samples were prepared with |
n_points |
number of equally spaced points
in the |
n_samples |
number of samples from the prior
distribution if the density cannot be obtained
analytically (or if samples are forced with
|
force_samples |
should prior be sampled instead of obtaining analytic solution whenever possible |
individual |
should individual densities be returned (e.g., in case of weightfunction) |
show_figures |
which figures should be returned in case of
multiple plots are generated. Useful when priors for the omega
parameter are plotted and |
transformation |
transformation to be applied to the prior distribution. Either a character specifying one of the prepared transformations:
, or a list containing the transformation function |
transformation_arguments |
a list with named arguments for
the |
transformation_settings |
boolean indicating whether the
settings the |
rescale_x |
allows to rescale x-axis in case a weightfunction is plotted. |
par_name |
a type of parameter for which the prior is specified. Only relevant if the prior corresponds to a mu parameter that needs to be transformed. |
effect_direction |
direction of the effect for PET-PEESE
regression. Use |
dots_prior |
additional arguments for the prior distribution plot |
data |
optional numeric vector of observed p-values in |
show_data |
whether observed p-values should be shown as rug marks on the weightfunction x-axis. |
dots_data |
additional styling arguments for observed p-value rug marks.
Supports |
legend |
whether factor legends should be drawn. |
legend_title |
optional title for factor legends. |
legend_labels |
optional labels for factor legend levels. |
legend_position |
optional legend position for factor legends. |
... |
additional arguments |
When using scaled predictors (via formula_scale_list in JAGS_fit),
you can plot posteriors on the original (unscaled) scale by preparing samples with
as_mixed_posteriors(..., transform_scaled = TRUE). The function automatically
detects this and uses the pre-computed transformed prior samples when prior = TRUE.
plot_posterior returns either NULL or
an object of class 'ggplot' if plot_type is plot_type = "ggplot".
prior() lines_prior_list() geom_prior_list()
Plot a list of prior distributions
plot_prior_list( prior_list, plot_type = "base", x_seq = NULL, xlim = NULL, x_range_quant = NULL, n_points = 500, n_samples = 10000, force_samples = FALSE, individual = FALSE, show_figures = if (individual) 1 else NULL, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, rescale_x = FALSE, par_name = NULL, prior_list_mu = NULL, effect_direction = "positive", legend = TRUE, legend_title = NULL, legend_labels = NULL, legend_position = NULL, ... )plot_prior_list( prior_list, plot_type = "base", x_seq = NULL, xlim = NULL, x_range_quant = NULL, n_points = 500, n_samples = 10000, force_samples = FALSE, individual = FALSE, show_figures = if (individual) 1 else NULL, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, rescale_x = FALSE, par_name = NULL, prior_list_mu = NULL, effect_direction = "positive", legend = TRUE, legend_title = NULL, legend_labels = NULL, legend_position = NULL, ... )
prior_list |
list of prior distributions |
plot_type |
whether to use a base plot |
x_seq |
sequence of x coordinates |
xlim |
x plotting range |
x_range_quant |
quantile used for
automatically obtaining |
n_points |
number of equally spaced points
in the |
n_samples |
number of samples from the prior
distribution if the density cannot be obtained
analytically (or if samples are forced with
|
force_samples |
should prior be sampled instead of obtaining analytic solution whenever possible |
individual |
should individual densities be returned (e.g., in case of weightfunction) |
show_figures |
which figures should be returned in case of
multiple plots are generated. Useful when priors for the omega
parameter are plotted and |
transformation |
transformation to be applied to the prior distribution. Either a character specifying one of the prepared transformations:
, or a list containing the transformation function |
transformation_arguments |
a list with named arguments for
the |
transformation_settings |
boolean indicating whether the
settings the |
rescale_x |
allows to rescale x-axis in case a weightfunction is plotted. |
par_name |
a type of parameter for which the prior is specified. Only relevant if the prior corresponds to a mu parameter that needs to be transformed. |
prior_list_mu |
list of priors for the mu parameter required when plotting PET-PEESE |
effect_direction |
direction of the effect for PET-PEESE
regression. Use |
legend |
whether factor legends should be drawn. |
legend_title |
optional title for factor legends. |
legend_labels |
optional labels for factor legend levels. |
legend_position |
optional legend position for factor legends. |
... |
additional arguments |
plot_prior_list returns either NULL or
an object of class 'ggplot' if plot_type is plot_type = "ggplot".
prior() lines_prior_list() geom_prior_list()
Plots a prior density after applying the same deterministic coefficient transformation used for formula-scale back-transforms. The helper supports continuous densities and point-mass priors in the same plot.
plot_transformed_prior( prior_list, column_names, formula_scale = NULL, parameter, n_points = 1000, x_range = NULL, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, plot_type = c("base", "ggplot"), par_name = NULL, ... )plot_transformed_prior( prior_list, column_names, formula_scale = NULL, parameter, n_points = 1000, x_range = NULL, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, plot_type = c("base", "ggplot"), par_name = NULL, ... )
prior_list |
named list of prior distributions. |
column_names |
character vector of coefficient column names defining the fitted parameter space. |
formula_scale |
optional nested formula-scale metadata, in the same shape
as |
parameter |
coefficient name to plot. |
n_points |
number of plotting points. |
x_range |
optional plotting range on the untransformed scale. |
transformation |
optional output transformation passed to the prior plotting machinery. |
transformation_arguments |
optional list of transformation arguments. |
transformation_settings |
whether |
plot_type |
either |
par_name |
optional plotting label. |
... |
additional plotting arguments. |
For plot_type = "base", invisibly returns base-plot metadata.
For plot_type = "ggplot", returns a ggplot object. Returns
NULL when the requested parameter is an identity transform and no
output transformation was requested.
plot_prior_list() transform_scale_samples()
Plots a prior object
## S3 method for class 'prior' plot( x, plot_type = "base", x_seq = NULL, xlim = NULL, x_range_quant = NULL, n_points = 1000, n_samples = 10000, force_samples = FALSE, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, show_figures = if (individual) -1 else NULL, individual = FALSE, rescale_x = FALSE, par_name = NULL, ... )## S3 method for class 'prior' plot( x, plot_type = "base", x_seq = NULL, xlim = NULL, x_range_quant = NULL, n_points = 1000, n_samples = 10000, force_samples = FALSE, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, show_figures = if (individual) -1 else NULL, individual = FALSE, rescale_x = FALSE, par_name = NULL, ... )
x |
a prior |
plot_type |
whether to use a base plot |
x_seq |
sequence of x coordinates |
xlim |
x plotting range |
x_range_quant |
quantile used for
automatically obtaining |
n_points |
number of equally spaced points
in the |
n_samples |
number of samples from the prior
distribution if the density cannot be obtained
analytically (or if samples are forced with
|
force_samples |
should prior be sampled instead of obtaining analytic solution whenever possible |
transformation |
transformation to be applied to the prior distribution. Either a character specifying one of the prepared transformations:
, or a list containing the transformation function |
transformation_arguments |
a list with named arguments for
the |
transformation_settings |
boolean indicating whether the
settings the |
show_figures |
which figures should be returned in case of
multiple plots are generated. Useful when priors for the omega
parameter are plotted and |
individual |
should individual densities be returned (e.g., in case of weightfunction) |
rescale_x |
allows to rescale x-axis in case a weightfunction is plotted. |
par_name |
a type of parameter for which the prior is specified. Only relevant if the prior corresponds to a mu parameter that needs to be transformed. |
... |
additional arguments |
plot.prior returns either NULL or
an object of class 'ggplot' if plot_type is plot_type = "ggplot".
prior() lines.prior() geom_prior()
# create some prior distributions p0 <- prior(distribution = "point", parameters = list(location = 0)) p1 <- prior(distribution = "normal", parameters = list(mean = 0, sd = 1)) p2 <- prior(distribution = "normal", parameters = list(mean = 0, sd = 1), truncation = list(0, Inf)) # a default plot plot(p0) # manipulate line thickness and color, change the parameter name plot(p1, lwd = 2, col = "blue", par_name = bquote(mu)) # use ggplot plot(p2, plot_type = "ggplot") # utilize the ggplot prior geom plot(p2, plot_type = "ggplot", xlim = c(-2, 2)) + geom_prior(p1, col = "red", lty = 2) # apply transformation plot(p1, transformation = "exp")# create some prior distributions p0 <- prior(distribution = "point", parameters = list(location = 0)) p1 <- prior(distribution = "normal", parameters = list(mean = 0, sd = 1)) p2 <- prior(distribution = "normal", parameters = list(mean = 0, sd = 1), truncation = list(0, Inf)) # a default plot plot(p0) # manipulate line thickness and color, change the parameter name plot(p1, lwd = 2, col = "blue", par_name = bquote(mu)) # use ggplot plot(p2, plot_type = "ggplot") # utilize the ggplot prior geom plot(p2, plot_type = "ggplot", xlim = c(-2, 2)) + geom_prior(p1, col = "red", lty = 2) # apply transformation plot(p1, transformation = "exp")
Density, distribution function, quantile function and random generation for point distribution.
dpoint(x, location, log = FALSE) rpoint(n, location) ppoint(q, location, lower.tail = TRUE, log.p = FALSE) qpoint(p, location, lower.tail = TRUE, log.p = FALSE)dpoint(x, location, log = FALSE) rpoint(n, location) ppoint(q, location, lower.tail = TRUE, log.p = FALSE) qpoint(p, location, lower.tail = TRUE, log.p = FALSE)
x, q
|
vector or matrix of quantiles. |
location |
vector of locations. |
log, log.p
|
logical; if |
n |
number of observations. |
lower.tail |
logical; if |
p |
vector of probabilities. |
dpoint gives the density, ppoint gives the
distribution function, qpoint gives the quantile function,
and rpoint generates random deviates.
# draw samples from a point distribution rpoint(10, location = 1)# draw samples from a point distribution rpoint(10, location = 1)
Print a BayesTools table
## S3 method for class 'BayesTools_table' print(x, ...)## S3 method for class 'BayesTools_table' print(x, ...)
x |
a BayesTools_values_tables |
... |
additional arguments. |
print.BayesTools_table returns NULL.
Prints a prior object
## S3 method for class 'prior' print( x, short_name = FALSE, parameter_names = FALSE, plot = FALSE, digits_estimates = 2, silent = FALSE, ... )## S3 method for class 'prior' print( x, short_name = FALSE, parameter_names = FALSE, plot = FALSE, digits_estimates = 2, silent = FALSE, ... )
x |
a prior |
short_name |
whether prior distribution names should be shorted |
parameter_names |
whether parameter names should be printed |
plot |
to return bquote formatted prior name for plotting. |
digits_estimates |
number of decimals to be displayed for printed parameters. |
silent |
to silently return the print message. |
... |
additional arguments |
print.prior invisibly returns the print statement.
# create some prior distributions p0 <- prior(distribution = "point", parameters = list(location = 0)) p1 <- prior(distribution = "normal", parameters = list(mean = 0, sd = 1)) # print them p0 p1 # use short names print(p1, short_name = TRUE) # print parameter names print(p1, parameter_names = TRUE) # generate bquote plotting syntax plot(0, main = print(p1, plot = TRUE))# create some prior distributions p0 <- prior(distribution = "point", parameters = list(location = 0)) p1 <- prior(distribution = "normal", parameters = list(mean = 0, sd = 1)) # print them p0 p1 # use short names print(p1, short_name = TRUE) # print parameter names print(p1, parameter_names = TRUE) # generate bquote plotting syntax plot(0, main = print(p1, plot = TRUE))
prior creates a prior distribution.
The prior can be visualized by the plot function.
prior( distribution, parameters, truncation = list(lower = -Inf, upper = Inf), prior_weights = 1 ) prior_none(prior_weights = 1)prior( distribution, parameters, truncation = list(lower = -Inf, upper = Inf), prior_weights = 1 ) prior_none(prior_weights = 1)
distribution |
name of the prior distribution. The possible options are
|
parameters |
list of appropriate parameters for a given
|
truncation |
list with two elements, |
prior_weights |
prior odds associated with a given distribution. The value is passed into the model fitting function, which creates models corresponding to all combinations of prior distributions for each of the model parameters and sets the model priors odds to the product of its prior distributions. |
prior and prior_none return an object of class 'prior'.
A named list containing the distribution name, parameters, and prior weights.
plot.prior(), Normal, Lognormal, Cauchy,
Beta, Exponential,
LocationScaleT, InvGamma.
# create a standard normal prior distribution p1 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1)) # create a half-normal standard normal prior distribution p2 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1), truncation = list(lower = 0, upper = Inf)) # the prior distribution can be visualized using the plot function # (see ?plot.prior for all options) plot(p1)# create a standard normal prior distribution p1 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1)) # create a half-normal standard normal prior distribution p2 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1), truncation = list(lower = 0, upper = Inf)) # the prior distribution can be visualized using the plot function # (see ?plot.prior for all options) plot(p1)
prior_bias() composes a step-selection
prior_weightfunction() and/or a prior_phacking() object. It does
not introduce new math; the backend compiler treats the composition as the
product of both kernels.
prior_bias(selection = NULL, phacking = NULL, prior_weights = 1)prior_bias(selection = NULL, phacking = NULL, prior_weights = 1)
selection |
optional |
phacking |
optional |
prior_weights |
prior odds associated with a given distribution. |
prior_bias() returns an object of class "prior".
prior_factor creates a prior distribution for fitting
models with factor predictors. (Note that results across different operating
systems might vary due to differences in JAGS numerical precision.)
prior_factor( distribution, parameters, truncation = list(lower = -Inf, upper = Inf), prior_weights = 1, contrast = "meandif" )prior_factor( distribution, parameters, truncation = list(lower = -Inf, upper = Inf), prior_weights = 1, contrast = "meandif" )
distribution |
name of the prior distribution. The possible options are
|
parameters |
list of appropriate parameters for a given
|
truncation |
list with two elements, |
prior_weights |
prior odds associated with a given distribution. The value is passed into the model fitting function, which creates models corresponding to all combinations of prior distributions for each of the model parameters and sets the model priors odds to the product of its prior distributions. |
contrast |
type of contrast for the prior distribution. The possible options are
|
return an object of class 'prior'.
# create an orthonormal prior distribution p1 <- prior_factor(distribution = "mnormal", contrast = "orthonormal", parameters = list(mean = 0, sd = 1))# create an orthonormal prior distribution p1 <- prior_factor(distribution = "mnormal", contrast = "orthonormal", parameters = list(mean = 0, sd = 1))
Density (pdf / lpdf), distribution function (cdf / ccdf), quantile function (quant), random generation (rng), mean, standard deviation (sd), and marginal variants of the functions (mpdf, mlpf, mcdf, mccdf, mquant) for prior distributions.
## S3 method for class 'prior' rng(x, n, ...) ## S3 method for class 'prior' cdf(x, q, ...) ## S3 method for class 'prior' ccdf(x, q, ...) ## S3 method for class 'prior' lpdf(x, y, ...) ## S3 method for class 'prior' pdf(x, y, ...) ## S3 method for class 'prior' quant(x, p, ...) ## S3 method for class 'prior' mcdf(x, q, ...) ## S3 method for class 'prior' mccdf(x, q, ...) ## S3 method for class 'prior' mlpdf(x, y, ...) ## S3 method for class 'prior' mpdf(x, y, ...) ## S3 method for class 'prior' mquant(x, p, ...)## S3 method for class 'prior' rng(x, n, ...) ## S3 method for class 'prior' cdf(x, q, ...) ## S3 method for class 'prior' ccdf(x, q, ...) ## S3 method for class 'prior' lpdf(x, y, ...) ## S3 method for class 'prior' pdf(x, y, ...) ## S3 method for class 'prior' quant(x, p, ...) ## S3 method for class 'prior' mcdf(x, q, ...) ## S3 method for class 'prior' mccdf(x, q, ...) ## S3 method for class 'prior' mlpdf(x, y, ...) ## S3 method for class 'prior' mpdf(x, y, ...) ## S3 method for class 'prior' mquant(x, p, ...)
x |
prior distribution |
n |
number of observations |
... |
unused arguments |
q |
vector or matrix of quantiles |
y |
vector of observations |
p |
vector of probabilities |
pdf (mpdf) and lpdf (mlpdf) give
the (marginal) density and the log of (marginal) density,
cdf (mcdf) and ccdf (mccdf) give the
(marginal) distribution and the complement of (marginal) distribution function,
quant (mquant) give the (marginal) quantile function,
and rng generates random deviates for an object of class 'prior'.
# create a standard normal prior distribution p1 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1)) # generate a random sample from the prior rng(p1, 10) # compute cumulative density function cdf(p1, 0) # obtain quantile quant(p1, .5) # compute probability density pdf(p1, c(0, 1, 2))# create a standard normal prior distribution p1 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1)) # generate a random sample from the prior rng(p1, 10) # compute cumulative density function cdf(p1, 0) # obtain quantile quant(p1, .5) # compute probability density pdf(p1, c(0, 1, 2))
Density (pdf / lpdf), distribution function (cdf / ccdf), quantile function (quant), random generation (rng), mean, standard deviation (sd), and marginal variants of the functions (mpdf, mlpf, mcdf, mccdf, mquant).
rng(x, ...) cdf(x, ...) ccdf(x, ...) quant(x, ...) lpdf(x, ...) pdf(x, ...) mcdf(x, ...) mccdf(x, ...) mquant(x, ...) mlpdf(x, ...) mpdf(x, ...)rng(x, ...) cdf(x, ...) ccdf(x, ...) quant(x, ...) lpdf(x, ...) pdf(x, ...) mcdf(x, ...) mccdf(x, ...) mquant(x, ...) mlpdf(x, ...) mpdf(x, ...)
x |
main argument |
... |
unused arguments |
pdf (mpdf) and lpdf (mlpdf) give
the (marginal) density and the log of (marginal) density,
cdf (mcdf) and ccdf (mccdf) give the
(marginal) distribution and the complement of (marginal) distribution function,
quant (mquant) give the (marginal) quantile function,
and rng generates random deviates for an object of class 'prior'.
The pdf function proceeds to PDF graphics device if x is a character.
prior_informed creates an informed prior distribution based on past
research. The prior can be visualized by the plot function.
prior_informed(name, parameter = NULL, type = "smd")prior_informed(name, parameter = NULL, type = "smd")
name |
name of the prior distribution. There are many options based on prior psychological or medical research. For psychology, the possible options are
For medicine, the possible options are based on Bartoš et al. (2021)
and Bartoš et al. (2023)
who developed empirical prior distributions for the effect size and heterogeneity parameters of the
continuous outcomes (standardized mean differences), dichotomous outcomes (logOR, logRR, and risk differences),
and time to event outcomes (logHR) based on the Cochrane database of systematic reviews.
Use |
parameter |
parameter name describing what prior distribution is supposed to be produced in cases
where the |
type |
prior type describing what prior distribution is supposed to be produced in cases
where the
|
prior_informed returns an object of class 'prior'.
Bartoš F, Gronau QF, Timmers B, Otte WM, Ly A, Wagenmakers E (2021).
“Bayesian model-averaged meta-analysis in medicine.”
Statistics in Medicine, 40(30), 6743–6761.
doi:10.1002/sim.9170.
Bartoš F, Otte WM, Gronau QF, Timmers B, Ly A, Wagenmakers E (2023).
“Empirical prior distributions for Bayesian meta-analyses of binary and time-to-event outcomes.”
doi:10.48550/arXiv.2306.11468.
preprint at https://doi.org/10.48550/arXiv.2306.11468.
Gronau QF, Van Erp S, Heck DW, Cesario J, Jonas KJ, Wagenmakers E (2017).
“A Bayesian model-averaged meta-analysis of the power pose effect with informed and default priors: The case of felt power.”
Comprehensive Results in Social Psychology, 2(1), 123–138.
doi:10.1080/23743603.2017.1326760.
van Erp S, Verhagen J, Grasman RP, Wagenmakers E (2017).
“Estimates of between-study heterogeneity for 705 meta-analyses reported in Psychological Bulletin from 1990–2013.”
Journal of Open Psychology Data, 5(1).
doi:10.5334/jopd.33.
prior(), prior_informed_medicine_names
# prior distribution representing expected effect sizes in social psychology # based on prior elicitation with dr. Oosterwijk p1 <- prior_informed("Oosterwijk") # the prior distribution can be visualized using the plot function # (see ?plot.prior for all options) plot(p1) # empirical prior distribution for the standardized mean differences from the oral health # medical subfield based on meta-analytic effect size estimates from the # Cochrane database of systematic reviews p2 <- prior_informed("Oral Health", parameter ="effect", type ="smd") print(p2)# prior distribution representing expected effect sizes in social psychology # based on prior elicitation with dr. Oosterwijk p1 <- prior_informed("Oosterwijk") # the prior distribution can be visualized using the plot function # (see ?plot.prior for all options) plot(p1) # empirical prior distribution for the standardized mean differences from the oral health # medical subfield based on meta-analytic effect size estimates from the # Cochrane database of systematic reviews p2 <- prior_informed("Oral Health", parameter ="effect", type ="smd") print(p2)
Contains the union of names identifying the individual subfields from
the Cochrane database of systematic reviews. Type-specific availability depends on
the type argument passed to prior_informed().
prior_informed_medicine_namesprior_informed_medicine_names
An object of class character of length 57.
returns a character vector with names of medical subfields from Cochrane database of systematic reviews.
print(prior_informed_medicine_names)print(prior_informed_medicine_names)
prior_mixture creates a mixture of prior distributions.
This is a more generic version of the prior_spike_and_slab function.
prior_mixture( prior_list, is_null = rep(FALSE, length(prior_list)), components = NULL )prior_mixture( prior_list, is_null = rep(FALSE, length(prior_list)), components = NULL )
prior_list |
a list of prior distributions to be mixed. |
is_null |
a logical vector indicating which of the prior distributions
should be considered as a null distribution. Defaults to |
components |
a character vector indicating which of the prior distributions
belong to the same mixture component (this is an alternative specification to the |
prior_phacking() creates a prior distribution for a
mass-preserving p-hacking redistribution kernel. The initial backend supports
linear and quadratic power depletion between source and
target, with depleted probability mass redistributed between
target and destination.
prior_phacking( side = "one-sided", target = 0.025, source = 0.25, destination = 0.005, form = c("linear", "quadratic"), alpha = prior("beta", list(1, 1)), report_scale = "pi_null", prior_weights = 1 )prior_phacking( side = "one-sided", target = 0.025, source = 0.25, destination = 0.005, form = c("linear", "quadratic"), alpha = prior("beta", list(1, 1)), report_scale = "pi_null", prior_weights = 1 )
side |
side geometry. Currently only |
target |
target p-value cut point. |
source |
source p-value cut point. Must be larger than |
destination |
destination p-value cut point. Must be smaller than
|
form |
power depletion form, either |
alpha |
prior distribution for the p-hacking severity parameter. |
report_scale |
reporting scale for deterministic summaries. |
prior_weights |
prior odds associated with a given distribution. |
prior_phacking() returns an object of class "prior".
prior creates a prior distribution for fitting a PET or
PEESE style models in RoBMA. The prior distribution can be visualized
by the plot function.
prior_PET( distribution, parameters, truncation = list(lower = 0, upper = Inf), prior_weights = 1 ) prior_PEESE( distribution, parameters, truncation = list(lower = 0, upper = Inf), prior_weights = 1 )prior_PET( distribution, parameters, truncation = list(lower = 0, upper = Inf), prior_weights = 1 ) prior_PEESE( distribution, parameters, truncation = list(lower = 0, upper = Inf), prior_weights = 1 )
distribution |
name of the prior distribution. The possible options are
|
parameters |
list of appropriate parameters for a given
|
truncation |
list with two elements, |
prior_weights |
prior odds associated with a given distribution. The value is passed into the model fitting function, which creates models corresponding to all combinations of prior distributions for each of the model parameters and sets the model priors odds to the product of its prior distributions. |
prior_PET and prior_PEESE return an object of class 'prior'.
# create a half-Cauchy prior distribution # (PET and PEESE specific functions automatically set lower truncation at 0) p1 <- prior_PET(distribution = "Cauchy", parameters = list(location = 0, scale = 1)) plot(p1)# create a half-Cauchy prior distribution # (PET and PEESE specific functions automatically set lower truncation at 0) p1 <- prior_PET(distribution = "Cauchy", parameters = list(location = 0, scale = 1)) plot(p1)
prior_spike_and_slab creates a spike and slab prior
distribution corresponding to the specification in
Kuo and Mallick (1998) (see
O'Hara and Sillanpää (2009) for further details). I.e.,
a prior distribution is multiplied by an independent indicator with values
either zero or one.
prior_spike_and_slab( prior_parameter, prior_inclusion = prior(distribution = "spike", parameters = list(location = 0.5)), prior_weights = 1 )prior_spike_and_slab( prior_parameter, prior_inclusion = prior(distribution = "spike", parameters = list(location = 0.5)), prior_weights = 1 )
prior_parameter |
a prior distribution for the parameter |
prior_inclusion |
a prior distribution for the inclusion probability. The
inclusion probability must be bounded within 0 and 1 range. Defaults to
|
prior_weights |
prior odds associated with a given distribution. The value is passed into the model fitting function, which creates models corresponding to all combinations of prior distributions for each of the model parameters and sets the model priors odds to the product of its prior distributions. |
return an object of class 'prior'.
# create a spike and slab prior distribution p1 <- prior_spike_and_slab( prior(distribution = "normal", parameters = list(mean = 0, sd = 1)), prior_inclusion = prior(distribution = "beta", parameters = list(alpha = 1, beta = 1)) )# create a spike and slab prior distribution p1 <- prior_spike_and_slab( prior(distribution = "normal", parameters = list(mean = 0, sd = 1)), prior_inclusion = prior(distribution = "beta", parameters = list(alpha = 1, beta = 1)) )
prior_weightfunction creates a prior distribution for
fitting a RoBMA selection model. The side and steps arguments
define the p-value bins, and the weights argument defines the prior on
the publication weights in those bins.
prior_weightfunction( side = "one-sided", steps = c(0.025, 0.05), weights = wf_cumulative(), reference = "most_significant", prior_weights = 1 ) wf_cumulative(alpha = NULL) wf_fixed(omega) wf_independent(prior, scale = "omega")prior_weightfunction( side = "one-sided", steps = c(0.025, 0.05), weights = wf_cumulative(), reference = "most_significant", prior_weights = 1 ) wf_cumulative(alpha = NULL) wf_fixed(omega) wf_independent(prior, scale = "omega")
side |
side geometry. Either |
steps |
increasing p-value cut points between 0 and 1. |
weights |
a weight-prior object created by |
reference |
reference bin. Currently only |
prior_weights |
prior odds associated with a given distribution. |
alpha |
positive cumulative-Dirichlet concentration parameters. If omitted, a flat Dirichlet prior is used with one concentration parameter per bin. |
omega |
fixed non-negative relative publication weights, one per bin. The reference-bin weight must be exactly 1. |
prior |
prior distribution for each non-reference weight. |
scale |
latent scale for independent weights. |
prior_weightfunction returns an object of class 'prior'.
p1 <- prior_weightfunction( side = "one-sided", steps = c(.05, .10), weights = wf_cumulative(alpha = c(1, 1, 1)) ) p2 <- prior_weightfunction( side = "one-sided", steps = c(.05), weights = wf_independent(prior("beta", list(1, 1))) )p1 <- prior_weightfunction( side = "one-sided", steps = c(.05, .10), weights = wf_cumulative(alpha = c(1, 1, 1)) ) p2 <- prior_weightfunction( side = "one-sided", steps = c(.05), weights = wf_independent(prior("beta", list(1, 1))) )
Computes range of a prior
distribution (if the prior distribution is
unbounded range from quantiles to
1 -quantiles) is returned.
## S3 method for class 'prior' range(x, quantiles = NULL, ..., na.rm = FALSE)## S3 method for class 'prior' range(x, quantiles = NULL, ..., na.rm = FALSE)
x |
a prior |
quantiles |
quantile to be returned in case of unbounded distribution. |
... |
additional arguments |
na.rm |
unused |
range.prior returns a numeric vector of
length with a plotting range of a prior distribution.
Removes column to a BayesTools table while not breaking formatting, attributes, etc...
remove_column(table, column_position = NULL)remove_column(table, column_position = NULL)
table |
BayesTools table |
column_position |
position of the to be removed column (defaults to |
returns an object of 'BayesTools_table' class.
Computes Savage-Dickey (density ratio) inclusion Bayes factors based the change of height from prior to posterior distribution at the test value.
Savage_Dickey_BF( posterior, null_hypothesis = 0, normal_approximation = FALSE, silent = FALSE )Savage_Dickey_BF( posterior, null_hypothesis = 0, normal_approximation = FALSE, silent = FALSE )
posterior |
marginal posterior distribution generated via the
|
null_hypothesis |
point null hypothesis to test. Defaults to |
normal_approximation |
whether the height of prior and posterior density should be
approximated via a normal distribution (rather than kernel density). Defaults to |
silent |
whether warnings should be returned silently. Defaults to |
Savage_Dickey_BF returns a Bayes factor.
Creates generic for sd function
sd(x, ...)sd(x, ...)
x |
main argument |
... |
additional arguments |
sd returns a standard deviation
of the supplied object (if it is either a numeric vector
or an object of class 'prior').
Computes standard deviation of a prior distribution.
## S3 method for class 'prior' sd(x, ...)## S3 method for class 'prior' sd(x, ...)
x |
a prior |
... |
unused arguments |
a standard deviation of an object of class 'prior'.
# create a standard normal prior distribution p1 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1)) # compute sd of the prior distribution sd(p1)# create a standard normal prior distribution p1 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1)) # compute sd of the prior distribution sd(p1)
selection_backend_spec() compiles step-selection and
p-hacking prior objects into active backend parameters. The returned object
contains stable p/z geometry, JAGS prior/transform code, monitor names,
initial values, and data constants.
selection_backend_spec( priors, backend = "jags", names = list(omega = "omega", alpha = "alpha"), global_breaks = NULL )selection_backend_spec( priors, backend = "jags", names = list(omega = "omega", alpha = "alpha"), global_breaks = NULL )
priors |
a selection prior, p-hacking prior, composed bias prior,
|
backend |
backend target. Currently only |
names |
list of backend parameter names. |
global_breaks |
optional global p-value break grid. |
A list describing the compiled backend specification.
Transforms posterior samples from model-averaged posterior distributions based on meandif/orthonormal prior distributions into differences from the mean.
transform_factor_samples(samples)transform_factor_samples(samples)
samples |
(a list) of mixed posterior distributions created with
|
transform_meandif_samples returns a named list of mixed posterior
distributions (either a vector of matrix).
mix_posteriors transform_meandif_samples transform_meandif_samples transform_orthonormal_samples
Transforms posterior samples from model-averaged posterior distributions based on meandif prior distributions into differences from the mean.
transform_meandif_samples(samples)transform_meandif_samples(samples)
samples |
(a list) of mixed posterior distributions created with
|
transform_meandif_samples returns a named list of mixed posterior
distributions (either a vector of matrix).
Transforms posterior samples from model-averaged posterior distributions based on orthonormal prior distributions into differences from the mean.
transform_orthonormal_samples(samples)transform_orthonormal_samples(samples)
samples |
(a list) of mixed posterior distributions created with
|
transform_orthonormal_samples returns a named list of mixed posterior
distributions (either a vector of matrix).
mix_posteriors contr.orthonormal
Generate prior samples and transform them using the same matrix transformation as posterior samples. This is the correct approach for visualizing priors on the original (unscaled) scale, especially for the intercept which depends on contributions from multiple coefficient priors.
transform_prior_samples( fit, n_samples = 10000, seed = NULL, formula_scale = NULL )transform_prior_samples( fit, n_samples = 10000, seed = NULL, formula_scale = NULL )
fit |
a fitted model object with |
n_samples |
number of samples to generate (default: 10000) |
seed |
random seed for reproducibility (optional) |
formula_scale |
optional nested list containing standardization information.
If not provided, extracted from |
When models use auto-scaling (standardizing predictors), the posterior samples are on the standardized scale. To correctly visualize priors on the original scale, we cannot simply apply a linear transformation to individual priors because the intercept on the original scale is a weighted sum of multiple priors:
This function generates samples from ALL priors simultaneously and applies the same matrix transformation used for posterior samples, which correctly handles the intercept and all other parameters.
A matrix of prior samples on the original (unscaled) scale, with columns matching the structure of posterior samples.
transform_scale_samples() plot_posterior()
# With a fitted model that used formula_scale: # prior_samples <- transform_prior_samples(fit, n_samples = 10000) # This can then be used with density() or for custom plotting# With a fitted model that used formula_scale: # prior_samples <- transform_prior_samples(fit, n_samples = 10000) # This can then be used with density() or for custom plotting
Transforms posterior samples from standardized continuous
predictors back to the original scale. This function is used when predictors
were standardized during model fitting via the formula_scale parameter.
transform_scale_samples(fit, formula_scale = NULL)transform_scale_samples(fit, formula_scale = NULL)
fit |
a fitted model object with |
formula_scale |
nested list containing standardization information keyed by
parameter name. Each parameter entry contains scaling info (mean and sd) for
each standardized predictor, e.g., |
The function transforms regression coefficients and intercepts to account for predictor standardization using a combinatorial approach that correctly handles interactions of any order.
For a k-way interaction between standardized predictors, the expansion of
contributes to all lower-order terms.
The contribution to a target term T from a source term S (where T is a subset
of S's scaled components) is:
where .
transform_scale_samples returns posterior samples transformed
back to the original predictor scale.
Updates BayesTools table while not breaking formatting, attributes, etc...
## S3 method for class 'BayesTools_table' update( object, title = NULL, footnotes = NULL, warnings = NULL, remove_parameters = NULL, logBF = FALSE, BF01 = FALSE, ... )## S3 method for class 'BayesTools_table' update( object, title = NULL, footnotes = NULL, warnings = NULL, remove_parameters = NULL, logBF = FALSE, BF01 = FALSE, ... )
object |
a BayesTools table |
title |
title of the table |
footnotes |
add footnotes to the table |
warnings |
add warnings of the table |
remove_parameters |
remove parameters from the table |
logBF |
whether to format Bayes factors as log(BF) |
BF01 |
whether to format Bayes factors as 1/BF |
... |
additional arguments. |
returns an object of 'BayesTools_table' class.
Creates generic for var function
var(x, ...)var(x, ...)
x |
main argument |
... |
additional arguments |
var returns a variance
of the supplied object (if it is either a numeric vector
or an object of class 'prior').
Computes variance of a prior distribution.
## S3 method for class 'prior' var(x, ...)## S3 method for class 'prior' var(x, ...)
x |
a prior |
... |
unused arguments |
a variance of an object of class 'prior'.
# create a standard normal prior distribution p1 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1)) # compute variance of the prior distribution var(p1)# create a standard normal prior distribution p1 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1)) # compute variance of the prior distribution var(p1)
Marginal density, marginal distribution function, marginal quantile function and random generation for weight functions.
mdone.sided(x, alpha = NULL, alpha1 = NULL, alpha2 = NULL, log = FALSE) mdtwo.sided(x, alpha, log = FALSE) mdone.sided_fixed(x, omega, log = FALSE) mdtwo.sided_fixed(x, omega, log = FALSE) rone.sided(n, alpha = NULL, alpha1 = NULL, alpha2 = NULL) rtwo.sided(n, alpha) rone.sided_fixed(n, omega) rtwo.sided_fixed(n, omega) mpone.sided( q, alpha = NULL, alpha1 = NULL, alpha2 = NULL, lower.tail = TRUE, log.p = FALSE ) mptwo.sided(q, alpha, lower.tail = TRUE, log.p = FALSE) mpone.sided_fixed(q, omega, lower.tail = TRUE, log.p = FALSE) mptwo.sided_fixed(q, omega, lower.tail = TRUE, log.p = FALSE) mqone.sided( p, alpha = NULL, alpha1 = NULL, alpha2 = NULL, lower.tail = TRUE, log.p = FALSE ) mqtwo.sided(p, alpha, lower.tail = TRUE, log.p = FALSE) mqone.sided_fixed(p, omega, lower.tail = TRUE, log.p = FALSE) mqtwo.sided_fixed(p, omega, lower.tail = TRUE, log.p = FALSE)mdone.sided(x, alpha = NULL, alpha1 = NULL, alpha2 = NULL, log = FALSE) mdtwo.sided(x, alpha, log = FALSE) mdone.sided_fixed(x, omega, log = FALSE) mdtwo.sided_fixed(x, omega, log = FALSE) rone.sided(n, alpha = NULL, alpha1 = NULL, alpha2 = NULL) rtwo.sided(n, alpha) rone.sided_fixed(n, omega) rtwo.sided_fixed(n, omega) mpone.sided( q, alpha = NULL, alpha1 = NULL, alpha2 = NULL, lower.tail = TRUE, log.p = FALSE ) mptwo.sided(q, alpha, lower.tail = TRUE, log.p = FALSE) mpone.sided_fixed(q, omega, lower.tail = TRUE, log.p = FALSE) mptwo.sided_fixed(q, omega, lower.tail = TRUE, log.p = FALSE) mqone.sided( p, alpha = NULL, alpha1 = NULL, alpha2 = NULL, lower.tail = TRUE, log.p = FALSE ) mqtwo.sided(p, alpha, lower.tail = TRUE, log.p = FALSE) mqone.sided_fixed(p, omega, lower.tail = TRUE, log.p = FALSE) mqtwo.sided_fixed(p, omega, lower.tail = TRUE, log.p = FALSE)
x, q
|
vector or matrix of quantiles. |
alpha |
vector or matrix with concentration parameters for the Dirichlet distribution for a monotonic one.sided or a two.sided weight function. |
alpha1 |
vector or matrix with concentration parameters for the Dirichlet distribution for the expected direction of non-monotonic one.sided of weight function. |
alpha2 |
vector or matrix with concentration parameters for the Dirichlet distribution for the unexpected direction of non-monotonic one.sided of weight function. |
log, log.p
|
logical; if |
omega |
vector or matrix of fixed non-negative relative weights for a one.sided or a two.sided weight function. The first/reference weight must be exactly 1. |
n |
number of observations. |
lower.tail |
logical; if |
p |
vector of probabilities. |
mdone.sided, mdtwo.sided, mdone.sided_fixed,
and mdtwo.sided_fixed give the marginal density,
mpone.sided, mptwo.sided, mpone.sided_fixed,
and mptwo.sided_fixed give the marginal distribution function,
mqone.sided, mqtwo.sided, mqone.sided_fixed,
and mqtwo.sided_fixed give the marginal quantile function,
and rone.sided, rtwo.sided, rone.sided_fixed,
and rtwo.sided_fixed generate random deviates.
# draw samples from a two-sided weight function rtwo.sided(10, alpha = c(1, 1)) # draw samples from a monotone one-sided weight function rone.sided(10, alpha = c(1, 1, 1)) # draw samples from a non-monotone one-sided weight function rone.sided(10, alpha1 = c(1, 1), alpha2 = c(1, 1))# draw samples from a two-sided weight function rtwo.sided(10, alpha = c(1, 1)) # draw samples from a monotone one-sided weight function rone.sided(10, alpha = c(1, 1, 1)) # draw samples from a non-monotone one-sided weight function rone.sided(10, alpha1 = c(1, 1), alpha2 = c(1, 1))
Creates coefficients mapping between multiple weightfunctions.
weightfunctions_mapping(prior_list, cuts_only = FALSE, one_sided = FALSE)weightfunctions_mapping(prior_list, cuts_only = FALSE, one_sided = FALSE)
prior_list |
list of prior distributions |
cuts_only |
whether only p-value cuts should be returned |
one_sided |
force one-sided output |
weightfunctions_mapping returns a list of indices
mapping the publication weights omega from the individual weightfunctions
into a joint weightfunction.