plot.rfmstate_pred: Plot RF Multistate Predictions

View source: R/plot.R

plot.rfmstate_predR Documentation

Plot RF Multistate Predictions

Description

Visualizes predicted state occupation probabilities and transition probabilities for individual patients.

Usage

## S3 method for class 'rfmstate_pred'
plot(
  x,
  type = c("state_occupation", "transition_prob"),
  subject = 1L,
  col = NULL,
  main = NULL,
  states = NULL,
  xlab = "Elapsed duration",
  ylab = NULL,
  ...
)

Arguments

x

An rfmstate_pred object.

type

Character, one of "state_occupation" (default), "transition_prob".

subject

Integer, which subject to plot (default 1). Use 0 for mean across all subjects.

col

One or more state colors. Values are recycled when necessary; NULL uses the package palette.

main

Title.

states

Occupied states to display.

xlab, ylab

Axis labels.

...

Additional arguments passed to plot.

Value

The input x object, returned invisibly. Called for its side effect of producing a plot.

Limitations

Curves are entry-conditioned on fresh entry into the fitted start_state; they are not general Markov P(s,t) curves and have no confidence bands. subject = 0 is an arithmetic mean of profile predictions, not a population-standardized estimator. The historical "transition_prob" plot type displays the occupied-state components conditional on the selected fresh-entry state.

Examples


ms <- define_multistate(c("A", "B"), "B", list(A = "B"))
dat <- data.frame(id = 1:60, x = seq(-1, 1, length.out = 60),
                  time_B = 1:60, censor = NA_real_)
long <- prepare_data(dat, "id", ms, list(B = "time_B"), "censor", "x")
fit <- rfmstate(long, num.trees = 20, min.node.size = 3,
                min_events = 3, sparse_warning = Inf, seed = 42)
pred <- predict(fit, data.frame(x = 0), times = c(0, 5, 10),
                target_grid_points = 64, max_grid_points = 1025)
plot(pred, states = c("A", "B"), xlab = "Elapsed day")
plot(pred, type = "transition_prob", states = "B")



RFmstate documentation built on Sept. 10, 2026, 1:09 a.m.