Skip to contents

Builds a faceted ggplot2 figure comparing a named list of fitted curves against the truth, with an optional bootstrap confidence ribbon. Uses the method_colors() palette by default.

Usage

plot_curves(
  x_grid,
  truth,
  fits,
  ci = NULL,
  title = "AFT + spline dose-response",
  x_lab = "Exposure",
  y_lab = "Centred linear predictor (log time ratio)",
  colors = method_colors(),
  ci_color = NULL,
  time_ratio = FALSE,
  in_support = NULL
)

Arguments

x_grid

Numeric exposure grid.

truth

Numeric vector of truth values (already centred at the first grid point), the same length as x_grid. Pass NULL to omit the truth line (e.g. on real data where the truth is unknown).

fits

Named list of numeric vectors of length length(x_grid).

ci

Optional list with elements lower and upper, each a numeric vector of length length(x_grid).

title

Plot title.

x_lab, y_lab

Axis labels.

colors

Optional named character vector of colours; defaults to method_colors() (matching Naive, Oracle, SIMEX).

ci_color

Optional single colour for the confidence ribbon. If NULL (the default), uses colors["SIMEX"] when present (because the ribbon is typically a SIMEX bootstrap interval) and otherwise falls back to the first entry of colors.

time_ratio

Logical; if TRUE, exponentiate the curves, truth, and CI ribbon so the y-axis reads as a time ratio relative to the reference anchor, and draw a horizontal reference line at y = 1. Default FALSE.

in_support

Optional logical vector aligned to x_grid (e.g. from a simex_aft_spline() fit with support_probs set). Grid points where it is FALSE are drawn dashed with a lighter ribbon and a caption note, marking spline extrapolation beyond the exposure support.

Value

A ggplot object.

Details

Requires the suggested package ggplot2 to be installed.

Examples

if (requireNamespace("ggplot2", quietly = TRUE)) {
  x <- seq(6, 14, length.out = 50)
  truth <- f_true(x) - f_true(x[1])
  plot_curves(x, truth, list(Oracle = truth))
}