plotPosteriors: Plot posterior distributions

View source: R/plotPosteriors.R

plotPosteriorsR Documentation

Plot posterior distributions

Description

For each free parameter in the posterior, this function creates a plot of the distribution of values estimated in the last generation. This function can also be used to visually compare against true (generating) parameter values in a simulation.

Usage

plotPosteriors(
  particleDataFrame,
  priorsList,
  realParam = FALSE,
  realParamValues = NA
)

Arguments

particleDataFrame

A particleDataFrame object returned by TreEvo ABC analyses, can be a single data frame or a list of data frames. If the particleDataFrame is a list of separate TreEvo runs, posteriors will be layered over each other to check for repeatability. The relative gray-scale of posterior distributions in the plot depends on their total number of runs.

priorsList

A priorList list object, returned by TreEvo doRun functions, where each element is itself a list of length two, composed of the name for the prior function (e.g. 'uniform', and a vector of the parameters for that prior distribution). Can be a single such list, or a list of priorList lists from a series of analyses (i.e. a list of depth 3). If the priorList is a list of lists (if it is found to be a list of depth 3, only the first list will be evaluated, and all other lists will be ignored. In other words, priors are expected to be identical for all runs considered by this function, such the choice of using the list of priors from the first analysis in the list is acceptable for all comparisons.

realParam

If TRUE, this function will plot line segments where real parameter values are known. (Usually only true when simulated data is analyzed.)

realParamValues

Values for real parameters, include a value for each parameter (including fixed values). Otherwise should be NA.

Value

Returns a plot for each free parameter.

Note

realParam and realParamValues should only be used with simulated data, where the true values are known.

Author(s)

Barb Banbury and Brian O'Meara

See Also

plotPrior for a set of functions for visualizing and summarizing prior and posterior distributions, including a visual comparison for single parameters.

Examples

data(simRunExample)

# make a list of particleDataFrames to plot multiple runs
resultsPDFlist <- lapply(resultsBMExample, function(x) x$particleDataFrame)

plotPosteriors(
   resultsPDFlist, 
   priorsList = resultsBMExample[[1]]$priorList, 
   realParam = TRUE, 
   realParamValues = c(ancStateExample, genRateExample)
   )


bomeara/treevo documentation built on Aug. 19, 2023, 6:52 p.m.