Skip to contents

Extracts the individual draws (bootstrap samples, simulated values from MVN, etc.) from an object returned by inferences() with return_draws = TRUE. This function joins the draws back to the original point estimate object, preserving all covariates, grouping variables, and summary statistics.

Usage

get_draws(x)

Arguments

x

A SOP, average-time, or average-comparison object returned with stored draws.

Value

A data frame with columns:

  • draw_id: Simulation or bootstrap iteration number

  • time, state: Time point and state for SOP results

  • state_set: State set for average-time or comparison results

  • draw: Draw-specific estimate of the requested quantity

  • estimate: The original point estimate from the model

  • conf.low, conf.high, std.error: Summary statistics from the point estimate object

  • fwb_weight or score_weight: Optional draw-specific patient weight for eligible ungrouped stored-data sops() draws

  • Additional columns from the original object (covariates, etc.)

Each row represents one draw for a specific result row.

Details

This function retrieves the draws from objects created by inferences(). It performs a join between the draws and the point estimate object to ensure that all metadata is preserved. To avoid conflict, the estimate column from the draws is renamed to draw.

Draw-specific patient weights are included only when they are meaningful for manual downstream averaging: ungrouped sops() output from FWB or score bootstrap on the stored empirical prediction cohort. They are not included for avg_sops() or grouped sops() because those draws are already averaged, and they are not included when the original SOP object used user-supplied prediction profiles. The column names fwb_weight and score_weight are reserved for these draw weights when they are attached.

Examples

if (FALSE) { # \dontrun{
# Create object with bootstrap draws
result <- avg_sops(
  model = fit,
  newdata = data,
  variables = list(tx = c(0, 1)),
  times = 1:30,
  y_levels = 1:6,
  absorb = 6,
  id_var = "id"
) |>
  inferences(method = "bootstrap", n_draws = 1000, return_draws = TRUE)

# Extract draws
draws <- get_draws(result)

# Plot distribution for state 1 at time 10 under treatment
library(ggplot2)
draws |>
  filter(time == 10, state == 1, tx == 1) |>
  ggplot(aes(x = draw)) +
  geom_histogram(bins = 30) +
  labs(title = "Distribution: P(State 1 | Time 10, Treatment)")

# Compute mean time in state 1 with bootstrap CI
library(dplyr)
time_in_state_boot <- draws |>
  filter(state == 1, tx == 1) |>
  group_by(draw_id) |>
  summarise(total_time = sum(draw))

quantile(time_in_state_boot$total_time, c(0.025, 0.5, 0.975))

# Compare treatment effect on time in state
treatment_effect <- draws |>
  filter(state == 1) |>
  group_by(draw_id, tx) |>
  summarise(total_time = sum(draw), .groups = "drop") |>
  pivot_wider(names_from = tx, values_from = total_time,
              names_prefix = "tx") |>
  mutate(effect = tx1 - tx0)

quantile(treatment_effect$effect, c(0.025, 0.5, 0.975))
} # }