plot.wnpmle_pred: Plot predicted cumulative incidences or marginal means

View source: R/plot_pred.R

plot.wnpmle_predR Documentation

Plot predicted cumulative incidences or marginal means

Description

Plots the result of predict() for a wnpmle fit: one curve per row of newdata, with pointwise confidence bands. For competing-risks fits (type = "cmprsk") the curves are cumulative incidences, for recurrent events marginal means.

Usage

## S3 method for class 'wnpmle_pred'
plot(
  x,
  conf_int = !add,
  add = FALSE,
  xscale = 1,
  type = c("s", "l"),
  col = NULL,
  lty = NULL,
  lwd = NULL,
  band_col = NULL,
  band_alpha = 0.15,
  labels = NULL,
  legend = if (add) FALSE else "auto",
  xlab = NULL,
  ylab = NULL,
  main = NULL,
  xlim = NULL,
  ylim = NULL,
  ...
)

Arguments

x

Result of predict() for a wnpmle fit.

conf_int

Logical; draw the pointwise confidence bands, if available (default TRUE, FALSE with add = TRUE).

add

Logical; add the curves to the current plot, e.g. to compare two models (default FALSE). Added curves are dashed by default.

xscale

The time axis is divided by xscale, e.g. xscale = 365.25 to show days in years (default 1).

type

"s" (step function, default) or "l" (lines).

col, lty, lwd

Colour, line type and line width, recycled over the curves. Default: grey shades from black, solid lines (dashed with add = TRUE).

band_col

Colour of the confidence bands (default: col).

band_alpha

Transparency of the confidence bands (default 0.15).

labels

Legend labels, one per curve. By default built from the covariates that differ between the rows of newdata.

legend

Position of the legend, e.g. "topleft"; "auto" (default) puts it in the emptiest corner, FALSE draws no legend (default with add = TRUE).

xlab, ylab, main, xlim, ylim

Axis labels, title and axis limits. The y-axis label depends on the type of prediction.

...

Further graphical parameters passed to plot() (not used with add = TRUE).

Value

x, invisibly.

Examples


library(survival)
tp <- survival::transplant
tp <- tp[tp$futime > 0 & complete.cases(tp), ]
tp$status <- ifelse(tp$event == "ltx", 1, ifelse(tp$event == "censored", 0, 2))
fit <- wnpmle_fit(Surv(futime, status) ~ age + sex + abo, data = tp,
                  type = "cmprsk", model = "boxcox", rho = 1)
nd <- data.frame(age = 50, sex = factor("m", levels = levels(tp$sex)),
                 abo = factor(c("A", "O"), levels = levels(tp$abo)))
p <- predict(fit, newdata = nd)
plot(p, xscale = 365.25, xlab = "Years on the waiting list")


wnpmle documentation built on Dec. 1, 2026, 9:06 a.m.