-
Notifications
You must be signed in to change notification settings - Fork 0
/
supplementary-material.qmd
578 lines (500 loc) · 16.5 KB
/
supplementary-material.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
---
title: "Supplement to: Multiple imputation of missing covariates when using the Fine--Gray model"
author:
- name: E. F. Bonneville
affil-id: 1
- name: J. Beyersmann
affil-id: 2
- name: R. H. Keogh
affil-id: 3
- name: J. W. Bartlett
affil-id: 3
- name: T. P. Morris
affil-id: 4
- name: N. Polverelli
affil-id: 5
- name: L. C. de Wreede
affil-id: 1,6,*
- name: and H. Putter
affil-id: 1,7,*
affiliations:
- id: 1
name: Department of Biomedical Data Sciences, Leiden University Medical Center, the Netherlands
- id: 2
name: Institute of Statistics, Ulm University, Germany
- id: 3
name: Department of Medical Statistics, London School of Hygiene and Tropical Medicine, United Kingdom
- id: 4
name: MRC Clinical Trials Unit at UCL, United Kingdom
- id: 5
name: Unit of Bone Marrow Transplantation, Division of Hematology, Fondazione IRCCS Policlinico San Matteo di Pavia, Italy
- id: 6
name: DKMS Clinical Trials Unit, Germany
- id: 7
name: Mathematical Institute, Leiden University, the Netherlands
- id: "*"
name: Shared senior authorship
format:
pdf:
documentclass: article
number-sections: true
code-block-border-left: false
papersize: a4
geometry:
- margin=1in
template-partials:
- title.tex
include-in-header:
text: |
\usepackage[noblocks]{authblk}
\renewcommand*{\Authsep}{, }
\renewcommand*{\Authand}{, }
\renewcommand*{\Authands}{, }
\renewcommand\Affilfont{\small}
\usepackage{booktabs}
\usepackage{array}
\usepackage{multirow}
\usepackage{longtable}
\renewcommand{\thesection}{S\arabic{section}}
execute:
echo: true
editor_options:
chunk_output_type: console
---
```{r}
#| label: setup
#| warning: false
#| echo: false
#| fig-cap-location: top
# Add this to quarto pipeline after
source(here::here("packages.R"))
invisible(lapply(list.files(here::here("R"), full.names = TRUE), source))
options(contrasts = rep("contr.treatment", 2))
# Theme tings
cols <- c("#CABEE9", "#7C7189", "#FAE093", "#D04E59", "#BC8E7D", "#2F3D70")
theme_set( # set base size to 14 instead of 16
theme_light(base_size = 16, base_family = "Roboto Condensed") +
theme(
strip.background = element_rect(fill = cols[2], colour = "white"),
strip.text = element_text(colour = 'white')
)
)
```
# Minimal code example
This is the minimal `R` code companion to section 3.4 of main manuscript. The parameters from the simulation study scenario with $p = 0.15$, random censoring, and correctly specified Fine--Gray were used to generate the example dataset below.
```{r}
#| echo: false
# Generate dataset
set.seed(202405)
params <- list(
"cause1" = list(
"formula" = ~ X + Z,
"betas" = c(0.75, 0.5),
"p" = 0.15,
"base_rate" = 1,
"base_shape" = 0.75
),
"cause2" = list(
"formula" = ~ X + Z,
"betas" = c(0.75, 0.5),
"base_rate" = 1,
"base_shape" = 0.75
)
)
dat_minimal <- generate_dataset(
n = 2000,
args_event_times = list(
mechanism = "correct_FG",
params = params,
censoring_type = "exponential"
),
args_missingness = list(
mech_params = list(
"prob_missing" = 0.4,
"mechanism_expr" = "1.5 * Z"
)
)
)
dat_minimal[, ':=' (time = round(time, digits = 6), Z = round(Z, digits = 3))]
dat <- data.frame(dat_minimal[order(id), c("id", "time", "D", "X", "Z")])
rownames(dat) <- NULL
#See suppl of https://onlinelibrary.wiley.com/doi/full/10.1002/sim.8387
```
```{r loading}
#| warning: false
# Load libraries
library(data.table)
library(survival)
library(kmi)
library(mice)
library(smcfcs)
# Minimal dataset
head(dat, n = 10)
sapply(dat, class)
nrow(dat)
```
1. Add columns $\hat{H}_1(T)$ and $\hat{H}_2(T)$ to the original data, which are the marginal cause-specific cumulative hazards for each competing risk evaluated at an individual's event or censoring time (obtained using the Nelson--Aalen estimator).
```{r}
# Add cause-specific event indicators + cumulative hazards
dat$D1 <- as.numeric(dat$D == 1)
dat$D2 <- as.numeric(dat$D == 2)
dat$H1 <- mice::nelsonaalen(data = dat, timevar = "time", statusvar = "D1")
dat$H2 <- mice::nelsonaalen(data = dat, timevar = "time", statusvar = "D2")
```
2. Multiply impute the potential censoring for those failing from cause 2 using \{kmi\}, yielding $m$ censoring complete datasets (i.e. with "complete" $V$). Any completely observed covariates that are known to affect the probability of being censored should be included as predictors in the model for the censoring process. \{kmi\} imputes based on stratified Kaplan--Meier when $Z$ are categorical, and based on a Cox model when at least one of $Z$ are continuous.
<!-- Mention administrative censoring here -->
```{r}
# Multiply impute the censoring times
cens_imps <- kmi(
formula = Surv(time, D != 0) ~ 1, # Additional predictors added here
data = dat,
etype = D,
failcode = 1, # Specify event of interest
nimp = 5
)
```
3. In each censoring complete dataset, add an additional column $\hat{\Lambda}_1(V)$. This takes the value of the marginal cumulative subdistribution hazard for cause 1 at an individual's observed or imputed subdistribution time, obtained with the Nelson--Aalen estimator based on $I(D = 1)$ and imputed $V$.
```{r}
# Preparation for covariate imputation:
list_to_impute <- lapply(cens_imps$imputed.data, function(imp_dat) {
# Adjust to new ordering from kmi (cause 2 individuals appended at bottom)
dat_to_impute <- cbind(cens_imps$original.data, imp_dat)
# Compute/add Lambda_1(V) in each imputed dataset
dat_to_impute$Lambda1 <- mice::nelsonaalen(
data = dat_to_impute,
timevar = "newtimes", # kmi naming for V
statusvar = "D1" # I(D=1)
)
return(dat_to_impute)
})
# newevent is equal to I(D=1)
head(list_to_impute[[1]])
```
4. In each censoring complete dataset (each with different $V$ and $\hat{\Lambda}_1(V)$, but same $\hat{H}_1(T)$ and $\hat{H}_2(T)$), create a single imputed dataset using the desired covariate imputation method(s).
```{r}
# Prepare predictor matrices for MICE using the first censoring complete dataset
predmat_cs_approx <- predmat_fg_approx <- mice::make.predictorMatrix(list_to_impute[[1]])
predmat_cs_approx[] <- predmat_fg_approx[] <- 0
predmat_cs_approx["X", c("Z", "D1", "D2", "H1", "H2")] <- 1
predmat_fg_approx["X", c("Z", "D1", "Lambda1")] <- 1
predmat_fg_approx
# Prepare the methods:
# - Approx methods: model type for X | Z, outcome
methods_approx <- mice::make.method(list_to_impute[[1]])
# - SMC methods: proposal model for X | Z (need to use {smcfcs} naming)
methods_smcfcs <- mice::make.method(
list_to_impute[[1]],
defaultMethod = c("norm", "logreg", "mlogit", "podds")
)
methods_smcfcs
```
```{r}
#| label: step_4
#| results: false
# Impute X
# (parallelize this loop for speed improvements on larger data)
list_imps <- lapply(list_to_impute, function(imp_dat) {
m <- 1
iters <- 10
imps_cs_approx <- mice(
data = imp_dat,
m = m,
maxit = iters,
method = methods_approx,
predictorMatrix = predmat_cs_approx
)
imps_fg_approx <- mice(
data = imp_dat,
m = m,
maxit = iters,
method = methods_approx,
predictorMatrix = predmat_fg_approx
)
imps_cs_smc <- smcfcs(
originaldata = imp_dat,
smtype = "compet",
smformula = list(
"Surv(time, D == 1) ~ X + Z",
"Surv(time, D == 2) ~ X + Z"
),
method = methods_smcfcs,
m = m,
numit = iters
)
imps_fg_smc <- smcfcs(
originaldata = imp_dat,
smtype = "coxph",
smformula = "Surv(newtimes, D1) ~ X + Z",
method = methods_smcfcs,
m = m,
numit = iters
)
# Bring all the imputed datasets together
imps <- rbind.data.frame(
cbind(method = "CCA", imp_dat),
cbind(method = "cs_smc", imps_cs_smc$impDatasets[[1]]),
cbind(method = "cs_approx", complete(imps_cs_approx, action = 1L)),
cbind(method = "fg_smc", imps_fg_smc$impDatasets[[1]]),
cbind(method = "fg_approx", complete(imps_cs_approx, action = 1L))
)
return(imps)
})
```
<!-- Note about assessing convergence -->
5. Fit the Fine--Gray substantive model in each imputed dataset (using standard Cox software with $I(D = 1)$ and imputed $V$ as outcome variables), and pool the estimates using Rubin's rules.
```{r}
#| label: step_5
# Bind everything together
dat_imps <- rbindlist(list_imps, idcol = ".imp")
dat_imps
# To use the usual workflow: subset one of the methods first
imps_fg_smc <- dat_imps[method == "fg_smc"]
# Fit model in each imputed dataset
mods_fg_smc <- lapply(
X = split(x = imps_fg_smc, f = imps_fg_smc$.imp),
FUN = function(imp_dat) coxph(Surv(newtimes, D1) ~ X + Z, data = imp_dat)
)
# Pool results
summary(pool(mods_fg_smc))
# Otherwise: use (nested) data.table workflow to pool for all methods simultaneously
dat_mods <- dat_imps[, .(
mod = list(coxph(Surv(newtimes, D1) ~ X + Z, data = .SD))
), by = c("method", ".imp")]
dat_mods
dat_mods[, summary(pool(as.list(mod))), by = "method"]
```
\newpage
# Applied data example
```{r}
#| echo: false
#| results: false
# Load in the good stuff
tar_load(applied_dat, store = here::here("_targets"))
tar_load(applied_dat_pooled, store = here::here("_targets"))
dat <- applied_dat$dat
sm_predictors <- applied_dat$sm_predictors
#
preds_final <- applied_dat_pooled$pooled_cumincs
method_labs <- c(
"Compl. cases" = "CCA",
"SMC-FCS cause-spec" = "CS-SMC",
"MICE cause-spec" = "CS-Approx",
"SMC-FCS Fine-Gray" = "FG-SMC",
"MICE subdist" = "FG-Approx"
)
preds_final[, method := factor(
method, levels = names(method_labs), labels = method_labs
)]
# First make the cuminc figure
p_cuminc <- preds_final |>
ggplot(aes(times, p_pooled, group = method)) +
#geom_ribbon(aes(ymin = CI_low, ymax = CI_upp, fill = method), alpha = 0.5) +
geom_step(aes(col = method, linetype = method), linewidth = 1) +
scale_color_manual(values = cols[c(1, 2, 6, 4, 5)]) +
coord_cartesian(ylim = c(0, 0.225)) +
labs(
col = "Method",
linetype = "Method",
x = "Time since alloHCT (months)",
y = "(Pooled) Baseline cumulative incidence"
)
p_ci_width <- preds_final |>
ggplot(aes(times, CI_width, group = method)) +
geom_step(aes(col = method, linetype = method), linewidth = 1) +
scale_color_manual(values = cols[c(1, 2, 6, 4, 5)]) +
coord_cartesian(ylim = c(0, 0.225)) +
labs(
col = "Method",
linetype = "Method",
x = "Time since alloHCT (months)",
y = "(Pooled) 95% Confidence interval width"
)
p_comb <- p_cuminc + p_ci_width & xlab(NULL) & theme(legend.position = "top")
p_final <- wrap_elements(panel = p_comb + plot_layout(guides = "collect")) +
labs(tag = "Time since alloHCT (months)") +
theme(
plot.tag = element_text(size = rel(1)),
plot.tag.position = "bottom"
)
ggplot2::ggsave(
plot = p_final,
filename = here::here("analysis/figures/applied_base_cuminc.pdf"),
width = 11,
scale = 1,
height = 7,
device = cairo_pdf
)
```
## Data dictionary
```{r}
#| echo: false
#| warning: false
library(gtsummary)
library(kableExtra)
# Tbl summary
df <- applied_dat$dat
df_predz <- copy(df[, ..sm_predictors]) #|>
# Re-transform for descriptives
df_predz[, ':=' (
age_allo1_decades = (age_allo1_decades + 6) * 10,
year_allo1_decades = year_allo1_decades * 10 + 10 + 2009,
intdiagallo_decades = intdiagallo_decades * 10,
pb_allo1 = pb_allo1 * 5,
hb_allo1 = hb_allo1 * 5 + 10,
wbc_allo1 = exp(wbc_allo1 + log(15.1))
)]
# Edit some factor labels
levels(df_predz$cmv_match)[1] <- "Patient negative/Donor negative"
levels(df_predz$donrel_bin)[1] <- "HLA identical sibling"
levels(df_predz$hctci_risk) <- c(
"Low risk ($0$)", "Intermediate risk ($1-2$)", "High risk ($\\geq 3$)"
)
levels(df_predz$KARNOFSK_threecat) <- c("$\\geq 90$", "$80$", "$\\leq 70$")
levels(df_predz$ric_allo1) <- c("Standard", "Reduced")
levels(df_predz$ruxo_preallo1) <- levels(df_predz$tceldepl_bin) <- c("No", "Yes")
levels(df_predz$submps_allo1) <- c("Primary MF", "Secondary MF")
# Edit some variable labels
attr(df_predz$hctci_risk, "label") <- "HCT-CI risk category"
attr(df_predz$KARNOFSK_threecat, "label") <- "Karnosfky performance score"
attr(df_predz$tceldepl_bin, "label") <- "T-cell depletion (in- or ev-vivo)"
attr(df_predz$ruxo_preallo1, "label") <- "Ruxolitinib given"
attr(df_predz$age_allo1_decades, "label") <- "Patient age (years)"
attr(df_predz$submps_allo1, "label") <- "Disease subclassification"
attr(df_predz$cmv_match, "label") <- "Patient/donor CMV match"
attr(df_predz$intdiagallo_decades, "label") <- "Interval diagnosis-transplantation (years)"
attr(df_predz$year_allo1_decades, "label") <- "Year of transplantation"
attr(df_predz$pb_allo1, "label") <- "Peripheral blood (PB) blasts (%)"
attr(df_predz$wbc_allo1, "label") <- "White blood cell count (WBC, x$10^9$/L)"
attr(df_predz$WEIGLOSS_allo1, "label") <- ">10% Weight loss prior to transplantation"
data_dict_caption <- "Data dictionary. CMV: cytomegalovirus; HLA: human leukocyte antigen; HCT-CI: Hematopoietic stem cell transplantation-comorbidity index; MF: myelofibrosis."
tbl_test <- tbl_summary(
df_predz,
missing_text = "(Missing)",
type = all_dichotomous() ~ "categorical"
) |>
as_kable_extra(
format = "latex",
booktabs = TRUE,
longtable = TRUE,
caption = data_dict_caption,
linesep = "",
addtl_fmt = FALSE
)
gsub(tbl_test, pattern = "%", replacement = "\\\\%")
```
## Non-parametric cumulative incidence curves
```{r}
#| fig-width: 9
#| fig-height: 7
#| dev: cairo_pdf
#| echo: false
#| fig-pos: 'H'
#| fig-cap: "Stacked non-parametric cumulative incidence curves for competing relapse and non-relapse mortality, in dataset of 3982 primary and secondary myelofibrosis patients."
#| fig-cap-location: top
np_curves <- prodlim(Hist(time_ci_adm, status_ci_adm) ~ 1, data = dat)
par(family = "Roboto Condensed")
plot(
np_curves,
cause = "stacked",
col = cols[c(4, 6)],
ylab = "Stacked cumulative incidence",
lty = c(1, 2),
xlab = "Time since alloHCT (months)",
percent = FALSE,
atrisk.at = seq(0, 60, by = 10),
atrisk.col = "black",
atrisk.title = "At risk:",
legend = FALSE
)
legend(
x = 0, y = 0.95,
legend = c("Relapse", "Non-relapse mortality"),
lty = c(1, 2),
col = cols[c(4, 6)],
bty = 'n',
lwd = c(3, 3)
)
```
## Pooled regression coefficeints
```{r}
#| echo: false
pooled_mods <- applied_dat_pooled$pooled_coefs
pooled_mods[, summ := paste0(
round(estimate, 2), " [", round(conf.low, 2), ", ", round(conf.high, 2), "]"
)]
pooled_mods[, method := factor(method, levels = names(method_labs), labels = method_labs)]
df_tbl <- dcast(pooled_mods, term + method ~ mod_type, value.var = "summ")
df_tbl[, term := factor(
term,
levels = c(
"ric_allo1reduced",
"cmv_matchOther",
"vchromos_preallo1Abnormal",
"donrel_binOther",
"hb_allo1",
"hctci_riskintermediate risk (1-2)",
"hctci_riskhigh risk (>= 3)",
"intdiagallo_decades",
"KARNOFSK_threecat80",
"KARNOFSK_threecat<80",
"submps_allo1sMF",
"sweat_allo1Yes",
"age_allo1_decades",
"PATSEXMale",
"pb_allo1",
"ruxo_preallo1yes",
"tceldepl_binyes",
"wbc_allo1",
"WEIGLOSS_allo1Yes",
"year_allo1_decades"
),
labels = c(
"Conditioning: reduced",
"CMV match: other",
"Cytogenetics: abnormal",
"Donor relation: other",
"Hemoglobin (per $5$ g/dL)",
"HCT-CI ($1-2$)",
"HCT-CI ($\\geq 3$)",
"Interval diagnosis to alloHCT (decades)",
"Karnofsky ($80$)",
"Karnofsky ($\\leq 70$)",
"Disease subclassification: secondary MF",
"Night sweats: yes",
"Patient age (decades)",
"Patient sex: male",
"PB Blasts (per $5$\\%)",
"Ruxolitinib given: yes",
"T-cell depletion: yes",
"WBC count (log)",
"Weight loss: yes",
"Year of alloHCT (decades)"
)
)]
tb_breaks <- rep(5, length(levels(df_tbl$term)))
names(tb_breaks) <- levels(df_tbl$term)
pooled_coefs_caption <- "Pooled log hazard ratios [log HR, 95\\% confidence interval] for Fine--Gray model for relapse, cause-specific Cox model relapse, and cause-specific Cox model for non-relapse mortality (NRM)."
df_tbl[order(term)][, !c("term")] |>
kbl(
format = "latex",
longtable = TRUE,
booktabs = TRUE,
caption = pooled_coefs_caption,
align = c("l", "r", "r", "r"),
col.names = c(
"Term + method",
"Relapse subdist.~log HR",
"Relapse cause-spec.~log HR",
"NRM cause-spec.~log HR"
),
escape = FALSE
) |>
# Important that pack_rows() before the styling
pack_rows(index = tb_breaks, escape = FALSE) |>
kable_styling(
latex_options = c("repeat_header"),
repeat_header_continued = TRUE,
repeat_header_method = "replace",
font_size = 9
)
```