JAGS_bridgesampling {BayesTools} | R Documentation |
Compute marginal likelihood of a 'JAGS' model
Description
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.
Usage
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,
...
)
Arguments
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 |
Value
JAGS_bridgesampling
returns an object of class 'bridge'.
Examples
## 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)