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(),
  legend = TRUE,
  legend_title = NULL,
  legend_labels = NULL,
  legend_position = NULL,
  ...,
  density_method = c("KDE", "precomputed")
)

Arguments

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 "base" or ggplot2 "ggplot" for plotting.

prior

whether prior distribution should be added to the figure. When samples were prepared with as_mixed_posteriors(..., transform_scaled = TRUE), the transformed prior samples are automatically used.

n_points

number of equally spaced points in the x_range if x_seq is unspecified

transformation

transformation to be applied to the prior distribution. Either a character specifying one of the prepared transformations:

lin

linear transformation in form of a + b*x

tanh

hyperbolic tangent transformation

exp

exponential transformation

, or a list containing the transformation function fun, inverse transformation function inv, and derivative of the transformation jac, evaluated on the original support. A custom transformation can also declare output_support = c(lower, upper). Display grids on the transformed scale are evaluated only within these bounds; a wider plotting range is retained without extending the density. Infinite inverse values at support boundaries are omitted from continuous density grids. Point masses retain their transformed locations.

transformation_arguments

a list with named arguments for the transformation

transformation_settings

boolean indicating whether the explicitly supplied x_seq or x_range is on the transformed scale. Automatically selected prior-coordinate ranges are always obtained on the source scale before the density family's existing transformation handling.

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

legend

whether factor legends should be drawn.

legend_title

optional title for factor legends.

legend_labels

optional labels for factor legend levels.

legend_position

optional legend position for factor legends.

...

additional arguments

density_method

density source for continuous posterior curves. "KDE" computes a kernel density estimate. Plot methods with exact finite prior-support bounds apply boundary reflection. "precomputed" uses valid posterior_density metadata when matching the selected parameter and condition; a missing or unusable continuous curve stops with a remedy to supply matching metadata or use "KDE". Pure-atom targets need no continuous curve. A precomputed density is the continuous part of the posterior; atoms are drawn from the declared posterior atoms with either method.

Value

plot_marginal returns either NULL or an object of class 'ggplot' if plot_type is plot_type = "ggplot".

Details

Marginal posterior vectors may carry posterior_density metadata (posterior_metadata()) with x and y coordinates. These densities are used only when density_method = "precomputed", which requires a matching valid curve for each selected continuous leaf. Pure-atom leaves need no continuous curve. Marginal plots with density_method = "KDE" use a standard KDE because marginal prior-density grids are numerical density ranges rather than true support metadata; this can intentionally differ from the support-reflected ordinate used by Savage_Dickey_BF when exact posterior-support metadata is available. A stored density describes the continuous part of the posterior; point masses are drawn from the declared posterior atoms (the atoms metadata, see posterior_atom_attribute()) with either density method. A declared continuous component that received fewer than two distinct continuous draws has its curve omitted and its point masses drawn, with a warning of class BayesTools_posterior_curve_unavailable (also BayesTools_plot_condition), as in plot_posterior(). A prior curve without an exact route whose numerical grid cannot resolve a heavy-tailed product term is omitted with a warning of class BayesTools_prior_curve_unavailable, as in plot_posterior(), and so is the prior curve of draws that declare no prior (a prior_list of prior_none()) and carry no prior density. Other draws without a prior density (e.g. from marginal_posterior() without prior samples) stop. Direct ordered factor marginal plots omit persisted zero-design reference rows and retain true non-reference point levels. They use the retained level color/label list and matching dashed prior-overlay defaults of plot_posterior(). Every non-reference continuous prior retains its finite plotting ordinates, including priors with an exact infinite density point. Unresolved raw numerical evaluations warn once per continuous route with the classes above, distinguishing partial from whole curve unavailability and retaining available points and atoms. The warning's unresolved_values field contains evaluation coordinates on the source scale, before any plotting transformation. Use prior = FALSE to draw the posterior alone. Exact infinite density and zero-density points remain valid, and finite displayed peak heights depend on the evaluation grid.