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] |
Maintainer: | František Bartoš <[email protected]> |
License: | GPL-3 |
Version: | 0.2.17 |
Built: | 2024-11-16 05:22:18 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.
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.95), title = NULL, footnotes = NULL, warnings = NULL, transform_factors = FALSE, transform_orthonormal = FALSE, formula_prefix = TRUE ) 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.95), 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.95), logBF = FALSE, BF01 = FALSE, title = NULL, footnotes = NULL, warnings = NULL, formula_prefix = TRUE )
ensemble_estimates_table( samples, parameters, probs = c(0.025, 0.95), title = NULL, footnotes = NULL, warnings = NULL, transform_factors = FALSE, transform_orthonormal = FALSE, formula_prefix = TRUE ) 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.95), 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.95), logBF = FALSE, BF01 = FALSE, title = NULL, footnotes = NULL, warnings = NULL, formula_prefix = TRUE )
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 |
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, remove_spike_0 = TRUE, transform_factors = FALSE, transform_orthonormal = FALSE, formula_prefix = TRUE, remove_inclusion = FALSE, remove_parameters = NULL ) runjags_inference_table( fit, title = NULL, footnotes = NULL, warnings = NULL, formula_prefix = TRUE ) JAGS_estimates_table( fit, transformations = NULL, title = NULL, footnotes = NULL, warnings = NULL, conditional = FALSE, remove_spike_0 = TRUE, transform_factors = FALSE, transform_orthonormal = FALSE, formula_prefix = TRUE, remove_inclusion = FALSE, remove_parameters = NULL ) JAGS_inference_table( fit, title = NULL, footnotes = NULL, warnings = NULL, formula_prefix = TRUE ) 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(title = NULL, footnotes = NULL, warnings = NULL) runjags_inference_empty_table(title = NULL, footnotes = NULL, warnings = NULL) JAGS_estimates_empty_table(title = NULL, footnotes = NULL, warnings = NULL) JAGS_inference_empty_table(title = NULL, footnotes = NULL, warnings = NULL) 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, remove_spike_0 = TRUE, transform_factors = FALSE, transform_orthonormal = FALSE, formula_prefix = TRUE, remove_inclusion = FALSE, remove_parameters = NULL ) runjags_inference_table( fit, title = NULL, footnotes = NULL, warnings = NULL, formula_prefix = TRUE ) JAGS_estimates_table( fit, transformations = NULL, title = NULL, footnotes = NULL, warnings = NULL, conditional = FALSE, remove_spike_0 = TRUE, transform_factors = FALSE, transform_orthonormal = FALSE, formula_prefix = TRUE, remove_inclusion = FALSE, remove_parameters = NULL ) JAGS_inference_table( fit, title = NULL, footnotes = NULL, warnings = NULL, formula_prefix = TRUE ) 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(title = NULL, footnotes = NULL, warnings = NULL) runjags_inference_empty_table(title = NULL, footnotes = NULL, warnings = NULL) JAGS_estimates_empty_table(title = NULL, footnotes = NULL, warnings = NULL) JAGS_inference_empty_table(title = NULL, footnotes = NULL, warnings = NULL) 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. Defaults
to |
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 |
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 |
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, check_length = 1, allow_NULL = FALSE, allow_NA = TRUE, call = "" ) check_char( x, name, check_length = 1, allow_values = NULL, allow_NULL = FALSE, allow_NA = TRUE, call = "" ) check_real( x, name, lower = -Inf, upper = Inf, allow_bound = TRUE, check_length = 1, allow_NULL = FALSE, allow_NA = TRUE, call = "" ) check_int( x, name, lower = -Inf, upper = Inf, allow_bound = TRUE, check_length = 1, allow_NULL = FALSE, allow_NA = TRUE, call = "" ) check_list( x, name, check_length = 0, check_names = NULL, all_objects = FALSE, allow_other = FALSE, allow_NULL = FALSE, call = "" )
check_bool( x, name, check_length = 1, allow_NULL = FALSE, allow_NA = TRUE, call = "" ) check_char( x, name, check_length = 1, allow_values = NULL, allow_NULL = FALSE, allow_NA = TRUE, call = "" ) check_real( x, name, lower = -Inf, upper = Inf, allow_bound = TRUE, check_length = 1, allow_NULL = FALSE, allow_NA = TRUE, call = "" ) check_int( x, name, lower = -Inf, upper = Inf, allow_bound = TRUE, check_length = 1, allow_NULL = FALSE, allow_NA = TRUE, call = "" ) check_list( x, name, 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)
Return a matrix of independent contrasts – a level for each term.
contr.independent(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 |
A matrix with n rows and k columns, with k = n if contrasts = TRUE
and k = n
if contrasts = FALSE
.
There are no references for Rd macro \insertAllCites
on this help page.
contr.independent(c(1, 2)) contr.independent(c(1, 2, 3))
contr.independent(c(1, 2)) contr.independent(c(1, 2, 3))
Return 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
.
contr.meandif(n, contrasts = TRUE)
contr.meandif(n, contrasts = TRUE)
n |
a vector of levels for a factor, or the number of levels |
contrasts |
logical indicating whether contrasts should be computed |
A matrix with n rows and k columns, with k = n - 1 if contrasts = TRUE
and k = n
if contrasts = FALSE
.
There are no references for Rd macro \insertAllCites
on this help page.
contr.meandif(c(1, 2)) contr.meandif(c(1, 2, 3))
contr.meandif(c(1, 2)) contr.meandif(c(1, 2, 3))
Return a matrix of orthornomal contrasts.
Code is based on stanova::contr.bayes
and corresponding to description
by Rouder et al. (2012)
contr.orthonormal(n, contrasts = TRUE)
contr.orthonormal(n, contrasts = TRUE)
n |
a vector of levels for a factor, or the number of levels |
contrasts |
logical indicating whether contrasts should be computed |
A matrix with n rows and k columns, with k = n - 1 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.
contr.orthonormal(c(1, 2)) contr.orthonormal(c(1, 2, 3))
contr.orthonormal(c(1, 2)) contr.orthonormal(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.
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, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, rescale_x = FALSE, scale_y2 = NULL, prior_list_mu = NULL, ... )
geom_prior_list( prior_list, xlim = NULL, x_seq = NULL, x_range_quant = NULL, n_points = 500, n_samples = 10000, force_samples = FALSE, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, rescale_x = FALSE, scale_y2 = NULL, prior_list_mu = NULL, ... )
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 |
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 |
... |
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
.
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)
interpret(inference, samples, specification, method)
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
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(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)
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, 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, 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 |
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 )
JAGS_check_convergence( fit, prior_list, max_Rhat = 1.05, min_ESS = 500, max_error = 0.01, max_SD_error = 0.05 )
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 |
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) |
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, 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), 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), 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, 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), 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), 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 |
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 |
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)
JAGS_formula(formula, parameter, data, prior_list)
formula |
formula specifying the right hand side of the assignment (the left hand side is ignored) |
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 |
JAGS_formula
returns a list containing the formula JAGS syntax,
JAGS data object, and modified prior_list.
# 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 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 <- JAGS_formula( formula = ~ x_cont + x_fac3 * x_fac4, parameter = "mu", data = df, prior_list = prior_list)
# 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 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 <- JAGS_formula( formula = ~ x_cont + x_fac3 * x_fac4, parameter = "mu", data = df, prior_list = prior_list)
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_data_list, formula_prior_list, prior_list_parameters )
JAGS_marglik_parameters(samples, prior_list) JAGS_marglik_parameters_formula( samples, 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_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_rolls
kitchen_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, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, rescale_x = FALSE, scale_y2 = NULL, prior_list_mu = NULL, ... )
lines_prior_list( prior_list, xlim = NULL, x_seq = NULL, x_range_quant = NULL, n_points = 500, n_samples = 10000, force_samples = FALSE, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, rescale_x = FALSE, scale_y2 = NULL, prior_list_mu = NULL, ... )
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 |
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 |
... |
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 |
number of samples to be drawn for the model-averaged posterior distribution |
seed |
seed for random number generation |
silent |
whether warnings should be returned silently. Defaults to |
mix_posteriors
returns a named list of mixed posterior
distributions (either a vector of matrix).
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 |
number of samples to be drawn for the model-averaged posterior distribution |
... |
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
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_prefix = TRUE ) JAGS_parameter_names(parameters, formula_parameter = NULL)
format_parameter_names( parameters, formula_parameters = NULL, formula_prefix = TRUE ) JAGS_parameter_names(parameters, formula_parameter = NULL)
parameters |
a vector of parameter names |
formula_parameters |
a vector of formula parameter prefix names |
formula_prefix |
whether the |
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")
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(), ... )
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(), ... )
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 |
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 |
... |
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. |
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 |
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, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, rescale_x = FALSE, par_name = NULL, dots_prior = list(), ... )
plot_posterior( samples, parameter, plot_type = "base", prior = FALSE, n_points = 1000, n_samples = 10000, force_samples = FALSE, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, rescale_x = FALSE, par_name = NULL, dots_prior = list(), ... )
samples |
samples from a posterior distribution for a parameter generated by mix_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 |
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 |
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 |
... |
additional arguments |
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, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, rescale_x = FALSE, par_name = NULL, prior_list_mu = 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, transformation = NULL, transformation_arguments = NULL, transformation_settings = FALSE, rescale_x = FALSE, par_name = NULL, prior_list_mu = 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 |
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 |
... |
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 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_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)
Contain names identifying the individual subfields from the Cochrane database
of systematic reviews. The individual elements correspond to valid name
arguments
for the prior_informed()
function.
prior_informed_medicine_names
prior_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
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 prior can be visualized by the plot
function.
prior_weightfunction(distribution, parameters, prior_weights = 1)
prior_weightfunction(distribution, parameters, prior_weights = 1)
distribution |
name of the prior distribution. The possible options are
|
parameters |
list of appropriate parameters for a given
|
prior_weights |
prior odds associated with a given distribution. The model fitting function usually 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_weightfunction
returns an object of class 'prior'.
p1 <- prior_weightfunction("one-sided", parameters = list(steps = c(.05, .10), alpha = c(1, 1, 1))) # the prior distribution can be visualized using the plot function # (see ?plot.prior for all options) plot(p1)
p1 <- prior_weightfunction("one-sided", parameters = list(steps = c(.05, .10), alpha = c(1, 1, 1))) # the prior distribution can be visualized using the plot function # (see ?plot.prior for all options) plot(p1)
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)
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
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 probabilities for a one.sided or a two.sided weight function. |
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)
weightfunctions_mapping(prior_list, cuts_only = FALSE)
prior_list |
list of prior distributions |
cuts_only |
whether only p-value cuts should be returned |
weightfunctions_mapping
returns a list of indices
mapping the publication weights omega from the individual weightfunctions
into a joint weightfunction.