plot.WA: Plot while-alive trajectory or a covariate's time-varying...

plot.WAR Documentation

Plot while-alive trajectory or a covariate's time-varying effect

Description

Plot while-alive trajectory or a covariate's time-varying effect

Usage

## S3 method for class 'WA'
plot(
  x,
  newdata,
  t_seq,
  id = 1,
  mode = c("wa", "cov"),
  covariate = NULL,
  ylab_wa = "While-alive loss rate",
  ylab_cov = NULL,
  xlab = "Time",
  level = 0.95,
  smooth = FALSE,
  span = 0.3,
  ...
)

Arguments

x

A "WA" object.

newdata

Data used to rebuild the RHS design (same columns as in the model).

t_seq

Times to plot over (numeric vector).

id

Row index of newdata to use for the while-alive trajectory (mode = "wa").

mode

"wa" to plot the while-alive loss rate, or "cov" to plot a specific covariate's time-varying effect.

covariate

Character; covariate name (must appear on RHS) when mode="cov".

ylab_wa

Y-axis label for while-alive plot.

ylab_cov

Y-axis label for covariate-effect plot; default "Effect of <covariate> on \u03B7(t)".

xlab

X-axis label.

level

Confidence level for ribbons (default 0.95).

smooth

Logical; if TRUE, apply LOESS smoothing to the displayed curve/CI.

span

LOESS span used when smooth=TRUE.

...

Unused.

Value

A ggplot2 object.

Examples


ex_dt <- crt_dt[crt_dt$cluster %in% c(1,2,3,4,7,10), ]
fit <- WA_fit(survival::Surv(time, status) ~ trt + Z1 + Z2,
              data = ex_dt, id="id", cluster="cluster",
              knots=seq(0, max(ex_dt$time), length.out=6),
              tau_grid=seq(0, max(ex_dt$time), length.out=6),
              basis="bz", degree=1, link="log",
              w_recur=c(1,1), w_term=2, ipcw="km")
nd <- unique(ex_dt[, c("trt","Z1","Z2")])
plot(fit, newdata = nd,
     t_seq = seq(0, max(fit$tau_grid), length.out = 200),
     id = 1, mode = "wa", smooth = TRUE)


WAreg documentation built on March 6, 2026, 5:07 p.m.

Related to plot.WA in WAreg...