% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/simulate_data.R
\name{simulate_data}
\alias{simulate_data}
\title{Simulate clustered competing risks data with shared frailty}
\usage{
simulate_data(
  G,
  Z = NULL,
  prop = 0.6,
  beta = NULL,
  theta = 0.5,
  cens = FALSE,
  pcens = 0.25,
  tau = 0.5
)
}
\arguments{
\item{G}{A vector of group or cluster identifiers (length \code{N}). Each value indicates which cluster the individual belongs to.}

\item{Z}{A matrix of covariates (dimensions \code{N x p}). Can be set to \code{NULL} if no covariates are used.}

\item{prop}{Proportion of individuals susceptible to cause 1 (default: \code{0.6}).}

\item{beta}{A numeric vector of regression coefficients, one per covariate (length \code{p}).}

\item{theta}{Variance of the shared frailty term for event times (cause 1).}

\item{cens}{Logical, indicating whether censoring should be simulated (default: \code{FALSE}).}

\item{pcens}{Target censoring proportion (default: \code{0.25}).}

\item{tau}{Variance of the shared frailty term for censoring times (default: \code{0}).}
}
\value{
A \code{data.frame} with one row per individual and at least the columns:
\describe{
\item{times}{Observed follow-up time.}
\item{status}{Event indicator: \code{0} for censoring, \code{1} for cause 1,
\code{2} for cause 2.}
\item{clusters}{Cluster identifier.}
}
If covariates are simulated, additional numeric covariate columns are included.
}
\description{
This function simulates clustered time-to-event data under a competing risks framework
with shared frailty and the possibility of random censoring. Cause 1 is modeled through
an inversion method of the subdistribution function, and cause 2 is introduced when inversion fails.
}
\examples{
\donttest{
n_cov <- 1
n_cluster <- 5
n_per_cluster <- 100
n <- n_cluster * n_per_cluster

G <- rep(1:n_cluster, each = n_per_cluster)
Z <- matrix(runif(n * n_cov), ncol = n_cov)

df <- simulate_data(
  G = G,
  Z = Z,
  prop = 0.6,
  beta = c(0.5),
  theta = 0.01,
  cens = TRUE,
  pcens = 0.25,
  tau = 0.01
)

head(df)
table(df$status)
}

}
