Creates density, histogram, ECDF, or Q–Q plots for a selected trial-level quantity. The estimand argument selects an arm parameter, a reconstructed TOST statistic, a continuous comparison, a count rate ratio, or endpoint correlations.

plot_distribution(x, estimand = "mu", arms = NULL, endpoints = NULL, ...)

Arguments

x

A result returned by sampleSize() or simPower() with keep_sim_data = TRUE.

estimand

Quantity to display: "mu" (or "mean"), "sigma", "dispersion", "rate", "t_value", "DOM", "ROM", "RR", or "correlation". "mean" and "sigma" display arm-specific simulation parameters; "DOM" and "ROM" display continuous comparison estimates; "RR" displays count rate ratios; and "correlation" displays endpoint correlations.

arms

Optional character vector of arm names. For mean and sigma, these are the arms to facet. For comparison estimands, these select comparator panels containing at least one supplied arm. If NULL, all are shown.

endpoints

Optional character vector of endpoint names. If NULL, all endpoints are displayed.

...

Optional plotting controls, including type, show_reference, n_trials, seed, and max_points. Legacy selector names are accepted for backward compatibility.

type

Plot type: "density", "histogram", "ecdf", or "qq".

show_reference

Logical. If TRUE, overlay the user-specified outcome distribution or the true estimand value. Defaults to TRUE.

n_trials

Optional number of randomly selected simulated trials to display. This is useful for illustrating the empirical distribution without plotting every retained observation.

seed

Seed used when selecting n_trials.

max_points

Maximum number of observations plotted after filtering.

Value

A ggplot object.

Details

Every comparator follows the package convention c(test, reference). For t_value, the lower and upper TOST statistics are reconstructed from the retained outcomes using the same continuous parallel formulas as the test. The dashed lines are the corresponding one-sided critical values. The plotted DOM is test - reference and the plotted ROM is test / reference; reversing the comparator reverses the displayed estimand. The plotted RR is rate_test / rate_reference.