marginalPlot: Plot MCMC marginals

View source: R/plotMarginals.R View source: R/plotMarginals.R

marginalPlotR Documentation

Plot MCMC marginals

Description

Plot MCMC marginals

Usage

marginalPlot(
  x,
  prior = NULL,
  xrange = NULL,
  type = "d",
  singlePanel = FALSE,
  settings = NULL,
  nPriorDraws = 10000,
  ...
)

Arguments

x

bayesianOutput, or matrix or data.frame containing with samples as rows and parameters as columns

prior

if x is a bayesianOutput, T/F will determine if the prior is drawn (default = T). If x is matrix oder data.frame, a prior can be drawn if a matrix of prior draws with values as rows and parameters as columns can be provided here.

xrange

vector or matrix of plotting ranges for the x axis. If matrix, the rows must be parameters and the columns min and max values.

type

character determining the plot type. Either 'd' for density plot, or 'v' for violin plot

singlePanel

logical, determining whether the parameter should be plotted in a single panel or each in its own panel

settings

optional list of additional settings for marginalPlotDensity, and marginalPlotViolin, respectively

nPriorDraws

number of draws from the prior, if x is bayesianOutput

...

additional arguments passed to getSample. If you have a high number of draws from the posterior it is advised to set numSamples (to e.g. 5000) for performance reasons.

Author(s)

Tankred Ott, Florian Hartig

Examples

## Generate a test likelihood function. 
ll <- generateTestDensityMultiNormal(sigma = "no correlation")

## Create a BayesianSetup
bayesianSetup <- createBayesianSetup(likelihood = ll, lower = rep(-10, 3), upper = rep(10, 3))

## Finally we can run the sampler and have a look
settings = list(iterations = 1000, adapt = FALSE)
out <- runMCMC(bayesianSetup = bayesianSetup, sampler = "Metropolis", settings = settings)

marginalPlot(out, prior = TRUE)

## We can plot the marginals in several ways:
## violin plots
marginalPlot(out, type = 'v', singlePanel = TRUE) 
marginalPlot(out, type = 'v', singlePanel = FALSE)
marginalPlot(out, type = 'v', singlePanel = TRUE, prior = TRUE)

## density plot
marginalPlot(out, type = 'd', singlePanel = TRUE) 
marginalPlot(out, type = 'd', singlePanel = FALSE)
marginalPlot(out, type = 'd', singlePanel = TRUE, prior = TRUE)

## if you have a very wide prior you can use the xrange option to plot only
## a certain parameter range
marginalPlot(out, type = 'v', singlePanel = TRUE, xrange = matrix(rep(c(-5, 5), 3), ncol = 3))

##Further options
# We can pass arguments to getSample (check ?getSample) and to the density and violin plots
marginalPlot(out, type = 'v', singlePanel = TRUE, 
             settings = list(col = c('#FC006299','#00BBAA88')), prior = TRUE)
marginalPlot(out, type = 'v', singlePanel = TRUE, numSamples = 500)

BayesianTools documentation built on Feb. 16, 2023, 8:44 p.m.