Skip to contents

Maps visit-scale SOP output from sops() or avg_sops() to a real elapsed time scale and linearly interpolates probabilities within patient, state, draw, treatment, and strata groups.

Usage

interpolate_sops(
  x,
  time_map,
  target_times = NULL,
  baseline_time = 0,
  normalize = TRUE
)

Arguments

x

A markov_sops or markov_avg_sops object.

time_map

A named numeric vector mapping visit labels to real times, or a data frame with visit and real-time columns. Data frames may use columns visit and real_time, visit and time, or their first two columns.

target_times

Optional numeric real-time grid. If NULL, uses the mapped visit times plus baseline_time when the baseline anchor is enabled.

baseline_time

Real time of the observed baseline state. The default 0 adds a fixed anchor from the stored previous-state values. Set to NULL to disable baseline anchoring.

normalize

Logical. If TRUE, normalize interpolated estimates so state probabilities sum to one within each time and group.

Value

An interpolated data frame with the same core columns as x, where time is on the real-time scale.

Details

The recommended workflow for irregular assessment schedules is:

  1. Recode assessment days to visit indices, for example day 3, 7, 14, and 28 to visit 1:4.

  2. Fit the Markov model with the visit index as a factor.

  3. Compute visit-scale SOPs with sops() or avg_sops().

  4. Use interpolate_sops() or time_in_state(..., time_map = ...) for real-day summaries.

With RCT standardization from avg_sops(), the empirical baseline anchor is shared across treatment counterfactual groups. When variables in avg_sops() sets the previous-state variable (for example yprev), every patient starts in the set state, so the anchor for that scenario gives probability 1 to that state and 0 to the others.

If x contains stored simulation, bootstrap, or posterior draws, the draws are interpolated too. Interval columns are then recomputed from the interpolated draws. Coefficient-only draws treat the empirical baseline anchor as fixed; empirical score-bootstrap, FWB, and refit-bootstrap draws use the corresponding draw-specific patient weights or resampled cohort. If interval columns are present but stored draws are unavailable, interpolate_sops() warns and falls back to interpolating interval endpoints. Each numeric series is interpolated only within its own finite source-time support. Targets before its first or after its last available value return NA; the function never extrapolates a series from another group's wider support.

Examples

if (FALSE) { # \dontrun{
avg <- avg_sops(
  fit,
  newdata = baseline,
  variables = list(tx = c(0, 1)),
  times = NULL
)
interpolate_sops(
  avg,
  time_map = c("1" = 3, "2" = 7, "3" = 14, "4" = 28),
  target_times = 0:28,
  baseline_time = 0
)
} # }