Skip to contents

This function creates a dataset of planned visit times for each patient, taking into account censoring due to dropouts or events. After a patient drops out or has an event (e.g., death), no further visits are generated.

Usage

simulate_visits(data, visit_times)

Arguments

data

A data frame of patients. If the data contains DropoutTime/Dropped and/or EventTime/EventStatus columns, these will be used to censor visits.

visit_times

Numeric vector of planned visit times (in the same time units as other simulation outputs). For example, c(0, 3, 6, 9, 12) for monthly visits over a year (if time in months). Include 0 for baseline.

Value

A data frame with one row per patient per scheduled visit (up to any censoring point). Columns:

  • ID: Patient ID (matching data$ID).

  • Time: Scheduled visit time.

Details

This function expands the patient data by visit time, but omits any visits that occur after a patient has dropped out or experienced a terminal event. If neither dropout nor event information is present, all specified visit_times will be returned for each patient.

Examples

df <- simulate_patients(3)
df$Dropped <- c(FALSE, TRUE, FALSE)
df$DropoutTime <- c(NA, 5, NA)
df$EventStatus <- c(0, 0, 1)
df$EventTime <- c(NA, NA, 5)
simulate_visits(df, visit_times = c(0, 5, 10))
#>   ID Time
#> 1  1    0
#> 2  1    5
#> 3  1   10
#> 4  2    0
#> 5  3    0