library("matchatr")
# A small cohort with event times; draw 2 controls per case.
cohort <- data.frame(
id = 1:8,
t = c(2, 5, 1, 8, 3, 9, 4, 7),
d = c(1, 0, 1, 0, 1, 0, 0, 0),
x = c(1, 0, 1, 0, 0, 1, 0, 1)
)
set.seed(1)
ncc <- sample_ncc(cohort, time = "t", event = "d", m = 2)
ncc id t d x set case risk_time
<int> <num> <num> <num> <int> <int> <num>
1: 3 1 1 1 1 1 1
2: 1 2 1 1 1 0 1
3: 5 3 1 0 1 0 1
4: 1 2 1 1 2 1 2
5: 2 5 0 0 2 0 2
6: 4 8 0 0 2 0 2
7: 5 3 1 0 3 1 3
8: 8 7 0 1 3 0 3
9: 6 9 0 1 3 0 3
# Analyse it: each sampled risk set is a stratum -> hazard ratio.
fit <- matcha(ncc, outcome = "case", exposure = "x",
design = nested_cc(strata = "set", time = "risk_time"),
estimator = "clogit")
contrast(fit)<matchatr_result>
Estimator: clogit (engine: clogit)
Estimand: hazard ratio
Contrast: Hazard ratio
CI method: model
N: 9
Contrasts:
comparison estimate se ci_lower ci_upper
<char> <num> <num> <num> <num>
1: x 1.686141 2.174996 0.1345573 21.12907