% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plots.R
\name{plot.ShrinkageTrees}
\alias{plot.ShrinkageTrees}
\title{Plot diagnostics for a ShrinkageTrees model}
\usage{
\method{plot}{ShrinkageTrees}(
  x,
  type = c("trace", "density", "vi", "survival"),
  n_vi = 10,
  obs = NULL,
  t_grid = NULL,
  level = 0.95,
  km = FALSE,
  ...
)
}
\arguments{
\item{x}{A \code{ShrinkageTrees} object.}

\item{type}{Character; one of:
\describe{
\item{\code{"trace"}}{Sigma traceplot across MCMC iterations (one line
per chain). Useful for assessing chain mixing.}
\item{\code{"density"}}{Overlaid posterior density of sigma, one curve
per chain.}
\item{\code{"vi"}}{Posterior credible intervals for variable inclusion
probabilities (top \code{n_vi} predictors). Only available for
Dirichlet prior models.}
\item{\code{"survival"}}{Posterior survival curves
\eqn{S(t | x_i) = 1 - \Phi((\log t - \mu_i) / \sigma)} with pointwise
credible bands, derived from the AFT log-normal model. Only available
for survival outcome types (\code{"right-censored"} or
\code{"interval-censored"}).
\strong{Population-averaged curve} (default, \code{obs = NULL}):
computes \eqn{\bar{S}(t) = n^{-1} \sum_i S(t | x_i)} at each MCMC
iteration. The credible band reflects posterior uncertainty in both
\eqn{\mu_i} and \eqn{\sigma} when \code{store_posterior_sample = TRUE},
or sigma-only uncertainty otherwise.
\strong{Individual curves} (\code{obs = c(1, 5, ...)}):
one curve per selected training observation with its own credible band.
Set \code{km = TRUE} to overlay the Kaplan--Meier estimate as a
non-parametric reference (population-averaged plot only).}
}}

\item{n_vi}{Integer; number of top variables to display when
\code{type = "vi"}. Default \code{10}.}

\item{obs}{Integer vector of training-set observation indices for
individual survival curves, or \code{NULL} (default) for the
population-averaged curve. Indices must be between 1 and the number
of training observations. Used only when \code{type = "survival"}.}

\item{t_grid}{Optional numeric vector of time points (on the original
time scale) at which to evaluate the survival function. If \code{NULL}
(default), a grid of 200 equally spaced points is generated from the
range of observed training times. Used only when
\code{type = "survival"}.}

\item{level}{Width of the pointwise credible band for
\code{type = "survival"}. Default \code{0.95} (a 95 percent credible
interval at each time point).}

\item{km}{Logical; if \code{TRUE} and \code{type = "survival"}
with \code{obs = NULL}, overlay the Kaplan--Meier curve (dashed black
step function) as a non-parametric reference. Default \code{FALSE}.
Requires the \pkg{survival} package. Ignored with a message when
\code{obs} is not \code{NULL}.}

\item{...}{Additional arguments (currently unused).}
}
\value{
A \pkg{ggplot2} object.
}
\description{
Visualises posterior draws using \pkg{ggplot2}.
Requires the suggested package \pkg{ggplot2}.
}
\examples{
\donttest{
if (requireNamespace("ggplot2", quietly = TRUE)) {
  set.seed(1)
  n <- 50; p <- 5
  X <- matrix(rnorm(n * p), ncol = p)
  y <- X[, 1] + rnorm(n)

  # Fit a small continuous model
  fit <- ShrinkageTrees(
    y = y, X_train = X,
    prior_type = "horseshoe",
    local_hp = 0.1, global_hp = 0.1,
    number_of_trees = 5,
    N_post = 50, N_burn = 25,
    verbose = FALSE
  )

  # Sigma traceplot -- check chain mixing
  plot(fit, type = "trace")

  # Overlaid posterior densities of sigma per chain
  plot(fit, type = "density")
}
}
}
