library("matchatr")
set.seed(1)
t1 <- rexp(600, 0.05)
t2 <- rexp(600, 0.05)
tau <- 6
tt <- pmin(t1, t2, tau)
cause <- ifelse(tt >= tau, 0L, ifelse(t1 < t2, 1L, 2L))
cohort <- data.frame(
id = 1:600,
t = tt,
d1 = as.integer(cause == 1L), # primary endpoint
d2 = as.integer(cause == 2L), # secondary endpoint
x = rbinom(600, 1, 0.4)
)
ncc <- sample_ncc(cohort, time = "t", event = "d1", m = 3, incl_prob = TRUE)
# Reuse the one control set for the secondary endpoint
ncc2 <- reuse_ncc_endpoint(ncc, cohort = cohort, time = "t", event = "d2")
fit2 <- matcha(ncc2, outcome = "d2", exposure = "x",
design = nested_cc(strata = "set", time = "t"),
estimator = "ipw_cox")
contrast(fit2)