Learn R Programming

BayesianTools (version 0.1.7)

createPriorDensity: Fits a density function to a multivariate sample

Description

Fits a density function to a multivariate sample

Usage

createPriorDensity(sampler, method = "multivariate", eps = 1e-10,
  lower = NULL, upper = NULL, best = NULL, ...)

Arguments

sampler

an object of class BayesianOutput or a matrix

method

method to generate prior - default and currently only option is multivariate

eps

numerical precision to avoid singularity

lower

vector with lower bounds of parameter for the new prior, independent of the input sample

upper

vector with upper bounds of parameter for the new prior, independent of the input sample

best

vector with "best" values of parameter for the new prior, independent of the input sample

...

parameters to pass on to the getSample function

Details

This function fits a density estimator to a multivariate (typically a posterior) sample. The main purpose is to summarize a posterior sample as a pdf, in order to include it as a prior in a new analysis, for example when new data becomes available, or to calculate a fractional Bayes factor (see marginalLikelihood).

The limitation of this function is that we currently only implement a multivariate normal density estimator, so you will have a loss of information if your posterior is not approximately multivariate normal, which is likely the case if you have weak data. Extending the function to include more flexible density estimators (e.g. gaussian processes) is on our todo list, but it's quite tricky to get this stable, so I'm not sure when we will have this working. In general, creating reliable empirical density estimates in high-dimensional parameter spaces is extremely tricky, regardless of the software you are using.

For that reason, it is usually recommended to not update the posterior with this option, but rather:

1. If the full dataset is available, to make a single, or infrequent updates, recompute the entire model with the full / updated data

2. For frequent updates, consider using SMC instead of MCMC sampling. SMC sampling doesn't require an analytical summary of the posterior.

See Also

createPrior createBetaPrior createTruncatedNormalPrior createUniformPrior createBayesianSetup

Examples

Run this code
# NOT RUN {
# Create a BayesianSetup
ll <- generateTestDensityMultiNormal(sigma = "no correlation")
bayesianSetup = createBayesianSetup(likelihood = ll, 
                                    lower = rep(-10, 3), 
                                    upper = rep(10, 3))

settings = list(iterations = 1000)
out <- runMCMC(bayesianSetup = bayesianSetup, settings = settings)


newPrior = createPriorDensity(out, method = "multivariate",
                              eps = 1e-10, lower = rep(-10, 3),
                              upper =  rep(10, 3), best = NULL)

bayesianSetup <- createBayesianSetup(likelihood = ll, prior = newPrior)

# }
# NOT RUN {
  settings = list(iterations = 1000)
  out <- runMCMC(bayesianSetup = bayesianSetup, settings = settings)
# }
# NOT RUN {


# }

Run the code above in your browser using DataLab