| pa_plot_pred | R Documentation |
Produces a quick diagnostic plot visualizing predicted survival or event probabilities (e.g., from a Weibull AFT model) against the subject-specific linear predictors (risk scores). The plot combines a smoothed line of predicted values and points representing observed times, using shape to indicate censoring status. This visualization provides a simple check of how predicted risks correspond to observed outcomes.
pa_plot_pred(
data,
title = NULL,
xlab = "Risk Score",
ylab = "Days",
label_name = c("censored", "event"),
levels = NULL,
shape_style = NULL,
legend_name = "status",
invert_linear = TRUE,
sample_index = NULL,
restrict_time = NULL
)
data |
A data frame (or list-like object) containing at least the following columns:
|
title |
Optional plot title (default = |
xlab, ylab |
Character strings specifying the axis labels
(defaults are |
label_name |
Character vector of labels corresponding to event
status codes (e.g., |
levels |
Numeric or character vector giving the ordering of status
levels; defaults inferred from the length of |
shape_style |
Numeric vector of plotting symbols (pch values)
corresponding to the levels of |
legend_name |
Character string for the legend title (default = "status"). |
invert_linear |
Logical; if |
sample_index |
Optional integer vector selecting which subjects to
plot, e.g. |
restrict_time |
Optional numeric. If supplied, observed times above this value are capped at it and a dashed horizontal reference line is drawn, which keeps a few long follow-up times from compressing the plot. |
The function is primarily designed for quick visual diagnostics in survival
model development. The line (pred vs linear.pred) shows the
fitted or predicted trend, while the overlaid points (times vs
linear.pred) illustrate observed event times, distinguished by
censoring status. For more elaborate visualization (e.g., confidence bands,
multiple models), use faceting or combine plots with patchwork.
A ggplot object that can be further customized.
d <- pa_sim_cox_weibull(n = 150, pi_c = 0.3, v = 2,
beta = c(0.5, -0.5), seed = 2025)
d <- d[, c("time", "status", "x1", "x2")]
fit <- survival::coxph(survival::Surv(time, status) ~ x1 + x2,
data = d, x = TRUE, y = TRUE)
pred <- pa_predict_coxph(model = fit, covs = c("x1", "x2"), new_data = d)
# observed time against predicted risk score, shaped by event status
pa_plot_pred(pred, title = "Cox model")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.