plot_prior: Visualise Distributions

View source: R/ggdmcPrior.R

plot_priorR Documentation

Visualise Distributions

Description

Plots density curves for specified distributions to help visualise their shape and domain.

Usage

plot_prior(p_prior, font_size = 5, cex = 5, return_data = FALSE)

Arguments

p_prior

A list of distribution specifications. Each element should be a list containing:

dist

A character string specifying the distribution type. Supported values include: "tnorm", "beta", "gamma", "lnorm", "cauchy", "unif", and "norm".

p0

The first parameter of the distribution.

p1

The second parameter of the distribution (if applicable).

lower

Optional lower bound (used for truncated distributions).

upper

Optional upper bound (used for truncated distributions).

log_p

Logical indicating whether to compute log-densities.

font_size

Numeric. Base font size for plot labels. Defaults to 5.

cex

Numeric. Scaling factor for plot elements. Defaults to 5.

return_data

Logical. If TRUE, returns the computed density data instead of plotting. Defaults to FALSE.

Details

This function:

  • Automatically determines appropriate x-axis ranges based on each distribution's properties.

  • Handles both truncated and unbounded distributions.

  • Supports all distribution types implemented in the package.

For truncated distributions, the density is plotted only within the specified bounds. A heuristic is used to generate axis limits and labels using the internal generate_x_value function.

Value

If return_data = FALSE (default), a lattice plot object is returned displaying the density curves for each prior. If return_data = TRUE, a data frame is returned with the following columns:

  • x: Numeric vector of x-values generated for each prior using a heuristic.

  • y: Corresponding density (or log-density) values.

  • gp: Group label or parameter name for each distribution.

Examples

# Define a joint distribution
p_prior <- BuildPrior(
    p0 = c(A = 0.15, B = 0.45, mean_v = 2.25, sd_v = 0.15, t0 = 0.2),
    p1 = rep(0.1, 5),
    lower = rep(NA, 5),
    upper = rep(NA, 5),
    dist = rep("tnorm", 5),
    log_p = rep(FALSE, 5)
)

plot_prior(p_prior)


ggdmcPrior documentation built on Aug. 8, 2025, 7:13 p.m.