pa_simulate_fine_gray: Simulate data from a two-cause Fine-Gray model

pa_simulate_fine_grayR Documentation

Simulate data from a two-cause Fine-Gray model

Description

This function generates a simulated dataset for a competing risks model with two causes, following a Fine-Gray-like model specification.

Usage

pa_simulate_fine_gray(
  n,
  v,
  beta1,
  beta2,
  lambda1 = 1,
  X = NULL,
  mu = 0,
  p = 0.7,
  c_scale = 1,
  censor = 0,
  sd.time = NULL,
  mu.c.time = NULL,
  independent_c = TRUE,
  report.mu_and_sd = FALSE,
  seed = NULL
)

Arguments

n

An integer specifying the number of subjects to simulate.

v

A numeric value for the Weibull shape parameter.

beta1

A numeric vector of coefficients for cause 1.

beta2

A numeric vector of coefficients for cause 2.

lambda1

A numeric value for the Weibull scale parameter for cause 1.

X

A matrix of covariates, if not provided, covariates are generated from a standard normal distribution.

mu

A numeric value for the mean of the generated covariates.

p

A numeric value for the marginal probability of a cause 1 event.

c_scale

A numeric value to scale the standard deviation of censoring times.

censor

A numeric value representing the desired censoring proportion.

sd.time

A numeric value for the standard deviation of censoring times. If NULL, it's calculated based on event times.

mu.c.time

A numeric value for the mean of censoring times. If NULL and 'censor > 0', it is calculated using 'uniroot' to achieve the desired censoring.

independent_c

A logical value. If TRUE, censoring times are independent of covariates.

report.mu_and_sd

A logical value. If TRUE, a summary of censoring parameters and event time quantiles is returned instead of the full dataset.

seed

Optional integer. If supplied, the random number generator is seeded with it for reproducibility. The default NULL uses the current random number stream without resetting it; random draws advance its state.

Value

A data frame containing the simulated data with columns 'obs.times', 'obs.event', and the covariates 'X'. Alternatively, if 'report.mu_and_sd' is TRUE, it returns a data frame with censoring parameters and event time quantiles.

Examples

# Simulate a dataset with 100 subjects
sim_data <- pa_simulate_fine_gray(
  n = 100, v = 1, beta1 = c(0.5, -0.2), beta2 = c(-0.3, 0.4)
)
head(sim_data)

# Simulate with a specific censoring proportion and report parameters
params_summary <- pa_simulate_fine_gray(
  n = 1000, v = 1, beta1 = c(0.5, -0.2), beta2 = c(-0.3, 0.4),
  censor = 0.2, report.mu_and_sd = TRUE
)
params_summary

PAmeasures documentation built on Oct. 29, 2026, 1:08 a.m.