Learn R Programming

DTEAssurance (version 1.1.0)

add_recruitment_time: Add recruitment time to a survival dataset

Description

Simulates recruitment timing for each patient in a survival dataset using either a power model or a piecewise constant (PWC) model. The function appends recruitment times and pseudo survival times (time from recruitment to event or censoring).

Usage

add_recruitment_time(
  data,
  rec_method,
  rec_period = NULL,
  rec_power = NULL,
  rec_rate = NULL,
  rec_duration = NULL
)

Value

A dataframe with two additional columns:

rec_time

Simulated recruitment time for each patient

pseudo_time

Time from recruitment to event or censoring

Class: data.frame

Arguments

data

A dataframe containing survival data with columns: time, status, and group

rec_method

Recruitment method: "power" for power model or "PWC" for piecewise constant model

rec_period

Period length for the power model

rec_power

Power parameter for the power model

rec_rate

Comma-separated string of recruitment rates for the PWC model

rec_duration

Comma-separated string of durations corresponding to each rate in the PWC model

Examples

Run this code
set.seed(123)
df <- data.frame(
  time = rexp(20, rate = 0.1),
  status = rbinom(20, 1, 0.8),
  group = rep(c("Control", "Treatment"), each = 10)
)
recruited <- add_recruitment_time(df, rec_method = "power", rec_period = 12, rec_power = 1)
head(recruited)

Run the code above in your browser using DataLab