Creates a 2D density plot for two correlated parameters from a Stan model fit. Axis limits are computed independently for X and Y using quantiles for a tight data-driven window, with optional padding. Ellipses mark specified probability levels under a bivariate normal approximation.
Arguments
- x
A list-like object that contains a
stanfitatx$stan_fit. The fit must have parametersbeta_cure_armandbeta_surv_arm.- n_grid
Integer. Number of grid points per axis for the 2D kernel density estimation passed to
MASS::kde2d. Default is100.- level_ellipses
Numeric vector of probability levels for confidence ellipses (bivariate normal contours). Default
c(0.5, 0.8, 0.95).- quantile_range
Numeric vector of length 2 with lower and upper tail probabilities used to set axis limits independently. Defaults to the central 99.8%:
c(0.001, 0.999).- padding
Numeric scalar (>= 0). Fractional padding to expand each axis range beyond the selected quantiles. Default
0.05(5%).- correlation_method
Character. The method to use: 'pearson' (default), 'spearman', or 'kendall'. Passed to
stats::cor.
Details
This helper expects a list-like object x that contains a fitted Stan
object under x$stan_fit. The Stan fit must expose posterior draws for
two parameters named beta_cure_arm and beta_surv_arm. These are
interpreted as:
beta_cure_arm: log(OR) for the cure component.beta_surv_arm: log(TR) for the survival component among the uncured.
The function:
extracts posterior samples with
rstan::extract(),computes Pearson, Spearman, or Kendall correlation,
sets independent axis limits via
stats::quantile(),estimates a 2D KDE via
MASS::kde2d(),builds a
ggplot2heatmap with contours and confidence ellipses.