Creates diagnostic plots for a fitted jmcs object. The function
always produces a longitudinal biomarker trajectory plot and an event curve.
Optionally, it can also produce a log residual variance plot.
a longitudinal biomarker trajectory plot, and
a plot of log residual variance over follow-up time (optional).
It also produces one event plot based on object$CompetingRisk:
if object$CompetingRisk = FALSE, a Kaplan-Meier plot is shown;
if object$CompetingRisk = TRUE, a cumulative incidence plot is shown.
The event time and status variables are inferred from
object$SurvivalSubmodel when event_time_col and
event_status_col are not supplied.
timeplot(
object,
biomarker,
id_col,
time_col,
visit_col = NULL,
n.obs = 100,
seed = 100,
window_days = 50,
time_bin_width = 180,
show_logvar = FALSE,
biomarker_y_lab = NULL,
logvar_y_lab = "Log Residual Variance",
event_x_lab = NULL,
event_y_lab = NULL,
x_lab = NULL,
x_break_by = NULL,
ylim_mean = NULL,
ylim_logvar = NULL,
event_time_col = NULL,
event_status_col = NULL,
fail_code = NULL,
cr_code = NULL,
censor_code = 0,
primary_event_label = "Primary event",
competing_event_label = NULL,
km_title = NULL,
cif_title = NULL,
center_event_plot = TRUE
)Invisibly returns a list with components:
combinedThe combined plot object.
p1The biomarker trajectory plot.
p2The log residual variance plot.
p_cifThe cumulative incidence plot if
object$CompetingRisk = TRUE; otherwise NULL.
p_kmThe Kaplan-Meier plot if
object$CompetingRisk = FALSE; otherwise NULL.
cif_fitThe fitted cumulative incidence object if applicable;
otherwise NULL.
km_fitThe fitted Kaplan-Meier object if applicable; otherwise
NULL.
event_time_colThe event-time column used.
event_status_colThe event-status column used.
fail_codeThe primary event code used.
cr_codeThe competing event code used, or NULL for
single-failure models.
censor_codeThe censoring code used.
summary_dataA data frame of visit- or bin-level longitudinal summary statistics.
obs_per_subject_visitA data frame giving the number of observations per subject and visit/bin after window-based filtering.
grouping_usedA character string indicating whether summaries were based on an observed visit variable or derived time bins.
show_logvara logic value to indicate whether a log residual variance plot is presented.
A fitted object of class jmcs.
Unquoted name of the longitudinal biomarker variable in
object$ydata.
Unquoted name of the subject identifier variable in
object$ydata.
Unquoted name of the longitudinal follow-up time variable in
object$ydata. This variable is used on the x-axis for the
biomarker trajectory and log residual variance plots.
Optional unquoted name of a visit variable in
object$ydata. If supplied and found, visit-level summaries are
used for the longitudinal diagnostic plots. If omitted, or if the supplied
column is not found, derived time bins are used instead.
Numeric value specifying the number of subjects randomly selected
for the longitudinal biomarker trajectory plot. Default is 100.
Optional integer random seed used for reproducible subject
sampling in the longitudinal biomarker trajectory plot. Default is
100. If NULL, no seed is set.
Numeric value giving the half-width of the time window used
when selecting observations around each visit- or bin-level mean time.
Default is 50.
Numeric value giving the width of derived time bins when
visit_col is not supplied or not found. Default is 180. For
small-scale time variables, such as time ranging from 0 to 5, use a smaller
value such as 0.5 or 1.
Logical; if TRUE, produces an additional plot of
log residual variance over follow-up time. Default is FALSE.
Optional character string for the y-axis label of the
biomarker trajectory plot. If NULL, the name of biomarker
is used.
Character string for the y-axis label of the log residual
variance plot. Default is "Log Residual Variance".
Optional character string for the x-axis label of the event
plot. If NULL, the name of the event-time variable is used.
Optional character string for the y-axis label of the event
plot. If NULL, the default label from the Kaplan-Meier or cumulative
incidence plotting function is used.
Optional character string for the x-axis label of the longitudinal
plots. If NULL, the name of time_col is used.
Numeric value controlling spacing of x-axis tick marks in
the longitudinal plots. Default is NULL.
Optional numeric vector of length 2 giving y-axis limits for the biomarker trajectory plot.
Optional numeric vector of length 2 giving y-axis limits for the log residual variance plot.
Optional character string giving the event-time variable
in object$cdata. If NULL, the function attempts to infer
it as the first variable in object$SurvivalSubmodel, i.e. the
first argument of Surv(time, status).
Optional character string giving the event-status
variable in object$cdata. If NULL, the function attempts
to infer it as the second variable in object$SurvivalSubmodel,
i.e. the second argument of Surv(time, status).
Numeric or integer code in event_status_col denoting
the event of interest. For single-failure models, this is the event code used
for the Kaplan-Meier plot. For competing-risk models, this is the primary
event code used in the cumulative incidence plot. If the model is
single-failure and there is exactly one non-censoring status code,
fail_code can be inferred.
Numeric or integer code in event_status_col denoting the
competing event. Required for competing-risk models unless there is exactly
one other non-censoring status code besides fail_code, in which case
it can be inferred. Ignored for single-failure Kaplan-Meier plots.
Numeric or integer code in event_status_col denoting
censoring. Default is 0.
Character string used in event plot labels for the
primary event. Default is "Primary event".
Character string used in cumulative incidence plot
labels for the competing event. Required for informative competing-risk
labeling. Ignored for single-failure Kaplan-Meier plots. Default is
NULL.
Optional character string for the Kaplan-Meier plot title. If
NULL, a default title is constructed from primary_event_label.
Optional character string for the cumulative incidence plot
title. If NULL, a default title is constructed from
primary_event_label and competing_event_label.
Logical; if TRUE, the three-plot layout places
the two longitudinal diagnostic plots on the first row and centers the event
plot on the second row. If FALSE, the three plots are stacked in one
column. Default is TRUE.
Shanpeng Li lishanpeng0913@ucla.edu
The longitudinal trajectory plot displays individual biomarker trajectories for
a random subset of subjects, along with a summary mean curve. If
visit_col is supplied and found in object$ydata, summaries
are calculated by observed visit. Otherwise, the function creates derived
time bins using floor(time_col / time_bin_width).
The residual variance plot displays the log residual variance over visit- or
bin-level follow-up time. Subject-level fitted values are obtained using
fitted(object, type = "Subject", process = "Longitudinal").
The event plot is chosen automatically from the fitted model:
For CompetingRisk = FALSE, the function creates a Kaplan-Meier
plot using fail_code as the event code and censor_code as the
censoring code.
For CompetingRisk = TRUE, the function creates a cumulative
incidence plot using fail_code as the primary event and
cr_code as the competing event.
In competing-risk settings, the model identifies event codes, but it does not
determine which event is scientifically "primary." The user should choose
fail_code based on the scientific question. For example, if
status = 1 is heart failure and status = 2 is death, then
fail_code = 1 and cr_code = 2 answer the question: "What is the
cumulative incidence of heart failure over time, accounting for death before
heart failure?"
jmcs
# \donttest{
library(FastJM)
data(ydata)
data(cdata)
# Single-failure example:
# Treat failure_type == 1 as the only event and all other observations as censored.
cdata_single <- cdata
cdata_single$event_single <- as.integer(cdata_single$failure_type == 1)
fit_single <- jmcs(
ydata = ydata,
cdata = cdata_single,
long.formula = response ~ time + gender + x1 + race,
surv.formula = Surv(surv, event_single) ~ x1 + gender + x2 + race,
random = ~ time | ID
)
singleplot <- timeplot(
object = fit_single,
biomarker = response,
id_col = ID,
time_col = time,
time_bin_width = 0.5,
primary_event_label = "Event type 1"
)
singleplot$combined
singleplot$p_km
# Competing-risk example using FastJM simulated data.
fit_cr <- jmcs(
ydata = ydata,
cdata = cdata,
long.formula = response ~ time + gender + x1 + race,
surv.formula = Surv(surv, failure_type) ~ x1 + gender + x2 + race,
random = ~ time | ID
)
crplot <- timeplot(
object = fit_cr,
biomarker = response,
id_col = ID,
time_col = time,
time_bin_width = 0.5,
fail_code = 1,
cr_code = 2,
censor_code = 0,
primary_event_label = "Event type 1",
competing_event_label = "Event type 2"
)
crplot$combined
crplot$p_cif
# }
Run the code above in your browser using DataLab