-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathncc.html
More file actions
1104 lines (1064 loc) · 86 KB
/
ncc.html
File metadata and controls
1104 lines (1064 loc) · 86 KB
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
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.2.335">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>hdPS and its machine learning extensions in residual confounding control - 25 Time-dependent exposure</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1.6em;
vertical-align: middle;
}
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
div.csl-bib-body { }
div.csl-entry {
clear: both;
}
.hanging div.csl-entry {
margin-left:2em;
text-indent:-2em;
}
div.csl-left-margin {
min-width:2em;
float:left;
}
div.csl-right-inline {
margin-left:2em;
padding-left:1em;
}
div.csl-indent {
margin-left: 2em;
}
</style>
<script src="site_libs/quarto-nav/quarto-nav.js"></script>
<script src="site_libs/quarto-nav/headroom.min.js"></script>
<script src="site_libs/clipboard/clipboard.min.js"></script>
<script src="site_libs/quarto-search/autocomplete.umd.js"></script>
<script src="site_libs/quarto-search/fuse.min.js"></script>
<script src="site_libs/quarto-search/quarto-search.js"></script>
<meta name="quarto:offset" content="./">
<link href="./prediction.html" rel="next">
<link href="./survival2.html" rel="prev">
<link href="./cover.png" rel="icon" type="image/png">
<script src="site_libs/quarto-html/quarto.js"></script>
<script src="site_libs/quarto-html/popper.min.js"></script>
<script src="site_libs/quarto-html/tippy.umd.min.js"></script>
<script src="site_libs/quarto-html/anchor.min.js"></script>
<link href="site_libs/quarto-html/tippy.css" rel="stylesheet">
<link href="site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="site_libs/bootstrap/bootstrap.min.js"></script>
<link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
<script id="quarto-search-options" type="application/json">{
"location": "sidebar",
"copy-button": false,
"collapse-after": 3,
"panel-placement": "start",
"type": "textbox",
"limit": 20,
"language": {
"search-no-results-text": "No results",
"search-matching-documents-text": "matching documents",
"search-copy-link-title": "Copy link to search",
"search-hide-matches-text": "Hide additional matches",
"search-more-match-text": "more match in this document",
"search-more-matches-text": "more matches in this document",
"search-clear-button-title": "Clear",
"search-detached-cancel-button-title": "Cancel",
"search-submit-button-title": "Submit"
}
}</script>
<link href="site_libs/pagedtable-1.1/css/pagedtable.css" rel="stylesheet">
<script src="site_libs/pagedtable-1.1/js/pagedtable.js"></script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js" type="text/javascript"></script>
<meta name="twitter:title" content="hdPS and its machine learning extensions in residual confounding control - 25 Time-dependent exposure">
<meta name="twitter:description" content="Let us start with an example of exploring the relationship between disease-modifying drugs (DMDs) for multiple sclerosis and long-term mortality.">
<meta name="twitter:card" content="summary">
</head>
<body class="nav-sidebar docked slimcontent">
<div id="quarto-search-results"></div>
<header id="quarto-header" class="headroom fixed-top">
<nav class="quarto-secondary-nav" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
<div class="container-fluid d-flex justify-content-between">
<h1 class="quarto-secondary-nav-title"><span class="chapter-number">25</span> <span class="chapter-title">Time-dependent exposure</span></h1>
<button type="button" class="quarto-btn-toggle btn" aria-label="Show secondary navigation">
<i class="bi bi-chevron-right"></i>
</button>
</div>
</nav>
</header>
<!-- content -->
<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article">
<!-- sidebar -->
<nav id="quarto-sidebar" class="sidebar collapse sidebar-navigation docked overflow-auto">
<div class="pt-lg-2 mt-2 text-left sidebar-header">
<div class="sidebar-title mb-0 py-0">
<a href="./">hdPS and its machine learning extensions in residual confounding control</a>
<div class="sidebar-tools-main">
<a href="https://github.com/ehsanx/" title="Source Code" class="sidebar-tool px-1"><i class="bi bi-github"></i></a>
<a href="" title="Share" id="sidebar-tool-dropdown-0" class="sidebar-tool dropdown-toggle px-1" data-bs-toggle="dropdown" aria-expanded="false"><i class="bi bi-share"></i></a>
<ul class="dropdown-menu" aria-labelledby="sidebar-tool-dropdown-0">
<li>
<a class="dropdown-item sidebar-tools-main-item" href="https://twitter.com/intent/tweet?url=|url|">
<i class="bi bi-bi-twitter pe-1"></i>
Twitter
</a>
</li>
<li>
<a class="dropdown-item sidebar-tools-main-item" href="https://www.facebook.com/sharer/sharer.php?u=|url|">
<i class="bi bi-bi-facebook pe-1"></i>
Facebook
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="mt-2 flex-shrink-0 align-items-center">
<div class="sidebar-search">
<div id="quarto-search" class="" title="Search"></div>
</div>
</div>
<div class="sidebar-menu-container">
<ul class="list-unstyled mt-1">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./index.html" class="sidebar-item-text sidebar-link">Background</a>
</div>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a href="./motivating.html" class="sidebar-item-text sidebar-link">Motivating example</a>
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="true">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 show">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./data.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">1</span> <span class="chapter-title">Data to Analyze</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./psipw.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">2</span> <span class="chapter-title">Propensity score</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./proxy.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">3</span> <span class="chapter-title">Reducing residual confounding</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a href="./hdps.html" class="sidebar-item-text sidebar-link">High-dimensional Propensity score</a>
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" aria-expanded="true">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-2" class="collapse list-unstyled sidebar-section depth1 show">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./step1.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">4</span> <span class="chapter-title">Step 1: Proxy sources</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./step2.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">5</span> <span class="chapter-title">Step 2: Empirical</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./step3.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">6</span> <span class="chapter-title">Step 3: Recurrence</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./step4.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">7</span> <span class="chapter-title">Step 4: Prioritize</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./step5.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">8</span> <span class="chapter-title">Step 5: Covariates</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./step6.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">9</span> <span class="chapter-title">Step 6: Propensity</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./step7.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">10</span> <span class="chapter-title">Step 7: Association</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./sens.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">11</span> <span class="chapter-title">Sensitivity</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a href="./extension.html" class="sidebar-item-text sidebar-link">Challenges</a>
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" aria-expanded="true">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-3" class="collapse list-unstyled sidebar-section depth1 show">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./pubmed.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">12</span> <span class="chapter-title">Literature</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a href="./mllogic.html" class="sidebar-item-text sidebar-link">Machine learning</a>
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-4" aria-expanded="true">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-4" class="collapse list-unstyled sidebar-section depth1 show">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./mllasso.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">13</span> <span class="chapter-title">Pure ML</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./mlhybrid.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">14</span> <span class="chapter-title">Hybrid ML</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./sl.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">15</span> <span class="chapter-title">Ensemble</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./tmle.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">16</span> <span class="chapter-title">TMLE</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./stat.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">17</span> <span class="chapter-title">Statistical Approaches</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./mlcompare.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">18</span> <span class="chapter-title">Compare results</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./dctmle.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">19</span> <span class="chapter-title">DC-TMLE</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./deep.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">20</span> <span class="chapter-title">Deep Learning</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a href="./extension2.html" class="sidebar-item-text sidebar-link">Extensions in Survival and Longitudinal Analyses</a>
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-5" aria-expanded="true">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-5" class="collapse list-unstyled sidebar-section depth1 show">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./hddrs1.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">21</span> <span class="chapter-title">hdDRS with a binary outcome</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./survival.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">22</span> <span class="chapter-title">hdPS with a time-to-event outcome</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./hddrs2.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">23</span> <span class="chapter-title">hdDRS with a survival outcome</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./survival2.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">24</span> <span class="chapter-title">Application in MS</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./ncc.html" class="sidebar-item-text sidebar-link active"><span class="chapter-number">25</span> <span class="chapter-title">Time-dependent exposure</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./prediction.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">26</span> <span class="chapter-title">High-Dimensional Prediction Models</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a href="./guideline.html" class="sidebar-item-text sidebar-link">Guideline</a>
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-6" aria-expanded="true">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-6" class="collapse list-unstyled sidebar-section depth1 show">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./report.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">27</span> <span class="chapter-title">Reporting</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./references.html" class="sidebar-item-text sidebar-link">References</a>
</div>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a href="./NHANES.html" class="sidebar-item-text sidebar-link">Appendix: NHANES</a>
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-7" aria-expanded="true">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-7" class="collapse list-unstyled sidebar-section depth1 show">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./index13.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">28</span> <span class="chapter-title">Download cycle 8</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./index15.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">29</span> <span class="chapter-title">Download cycle 9</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./index17.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">30</span> <span class="chapter-title">Download cycle 10</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./analytic13.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">31</span> <span class="chapter-title">Recoding cycle 8</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./analytic15.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">32</span> <span class="chapter-title">Recoding cycle 9</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./analytic17.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">33</span> <span class="chapter-title">Recoding cycle 10</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./merge13to17.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">34</span> <span class="chapter-title">Merge three cycles</span></a>
</div>
</li>
</ul>
</li>
</ul>
</div>
</nav>
<!-- margin-sidebar -->
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
<nav id="TOC" role="doc-toc" class="toc-active">
<h2 id="toc-title">Table of contents</h2>
<ul>
<li><a href="#time-dependent-cox-regression" id="toc-time-dependent-cox-regression" class="nav-link active" data-scroll-target="#time-dependent-cox-regression"><span class="toc-section-number">25.1</span> Time-dependent Cox regression</a></li>
<li><a href="#nested-case-control-ncc" id="toc-nested-case-control-ncc" class="nav-link" data-scroll-target="#nested-case-control-ncc"><span class="toc-section-number">25.2</span> Nested case-control (NCC)</a></li>
<li><a href="#hdps-in-the-ncc-framework" id="toc-hdps-in-the-ncc-framework" class="nav-link" data-scroll-target="#hdps-in-the-ncc-framework"><span class="toc-section-number">25.3</span> hdPS in the NCC framework</a>
<ul class="collapse">
<li><a href="#step-0-analytic-data" id="toc-step-0-analytic-data" class="nav-link" data-scroll-target="#step-0-analytic-data"><span class="toc-section-number">25.3.1</span> Step 0: Analytic data</a></li>
<li><a href="#step-1-proxy-sources" id="toc-step-1-proxy-sources" class="nav-link" data-scroll-target="#step-1-proxy-sources"><span class="toc-section-number">25.3.2</span> Step 1: Proxy sources</a></li>
<li><a href="#step-2-empirical-covariates" id="toc-step-2-empirical-covariates" class="nav-link" data-scroll-target="#step-2-empirical-covariates"><span class="toc-section-number">25.3.3</span> Step 2: Empirical covariates</a></li>
<li><a href="#step-3-recurrence" id="toc-step-3-recurrence" class="nav-link" data-scroll-target="#step-3-recurrence"><span class="toc-section-number">25.3.4</span> Step 3: Recurrence</a></li>
<li><a href="#step-4-prioritize" id="toc-step-4-prioritize" class="nav-link" data-scroll-target="#step-4-prioritize"><span class="toc-section-number">25.3.5</span> Step 4: Prioritize</a></li>
<li><a href="#step-5-covariates" id="toc-step-5-covariates" class="nav-link" data-scroll-target="#step-5-covariates"><span class="toc-section-number">25.3.6</span> Step 5: Covariates</a></li>
<li><a href="#step-6-propensity-score" id="toc-step-6-propensity-score" class="nav-link" data-scroll-target="#step-6-propensity-score"><span class="toc-section-number">25.3.7</span> Step 6: Propensity score</a></li>
<li><a href="#step-7-association" id="toc-step-7-association" class="nav-link" data-scroll-target="#step-7-association"><span class="toc-section-number">25.3.8</span> Step 7: Association</a></li>
</ul></li>
</ul>
<div class="toc-actions"><div><i class="bi bi-github"></i></div><div class="action-links"><p><a href="https://github.com/ehsanx/edit/main/ncc.qmd" class="toc-action">Edit this page</a></p></div></div></nav>
</div>
<!-- main -->
<main class="content page-columns page-full" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title d-none d-lg-block"><span class="chapter-number">25</span> <span class="chapter-title">Time-dependent exposure</span></h1>
</div>
<div class="quarto-title-meta">
</div>
</header>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-1_0c996cb78d5ea7fbcd8157d3cca25589">
</div>
<section id="time-dependent-cox-regression" class="level2" data-number="25.1">
<h2 data-number="25.1" class="anchored" data-anchor-id="time-dependent-cox-regression"><span class="header-section-number">25.1</span> Time-dependent Cox regression</h2>
<p>Let us start with an example of exploring the relationship between disease-modifying drugs (DMDs) for multiple sclerosis and long-term mortality. The DMD exposure is a time-dependent variable, and the mortality outcome is a time-to-event outcome. Employing Cox proportional hazards models with time-varying exposure to DMDs can address immortal time bias in this example.</p>
<div class="callout-tip callout callout-style-default callout-captioned">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-caption-container flex-fill">
Time-dependent exposure
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li>Time-dependent Cox regression with time-varying exposure can help mitigate immortal time bias.</li>
<li>The hdPS approach is used to deal with residual confounding with a binary ‘time-fixed’ treatment</li>
<li>With a ‘time-dependent’ exposure, implementing the hdPS in conjunction with the time-dependent Cox regression presents a methodological and practical challenge.</li>
</ul>
<p>See the associated article for more details <span class="citation" data-cites="Hossain2025">(<a href="references.html#ref-Hossain2025" role="doc-biblioref">Hossain et al. 2025</a>)</span>.</p>
<div class="cell">
<div class="cell-output-display">
<p><img src="images/pds25ncc.png" class="img-fluid" style="width:80.0%"></p>
</div>
</div>
</div>
</div>
</section>
<section id="nested-case-control-ncc" class="level2 page-columns page-full" data-number="25.2">
<h2 data-number="25.2" class="anchored" data-anchor-id="nested-case-control-ncc"><span class="header-section-number">25.2</span> Nested case-control (NCC)</h2>
<p>The nested case-control (NCC) design is a well-established method for addressing immortal time bias with a time-dependent exposure. The NCC framework provides a robust alternative for addressing immortal time bias, while allowing for the integration of hdPS analysis to minimize the residual confounding bias.</p>
<div class="no-row-height column-margin column-container"><div class="">
<p><span class="citation" data-cites="austin2012comparing ernster1994nested hossain2024benefits">(<a href="references.html#ref-austin2012comparing" role="doc-biblioref">Austin et al. 2012</a>; <a href="references.html#ref-ernster1994nested" role="doc-biblioref">Ernster 1994</a>; <a href="references.html#ref-hossain2024benefits" role="doc-biblioref">Hossain et al. 2024</a>)</span></p>
</div></div><div class="callout-tip callout callout-style-default callout-captioned">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-caption-container flex-fill">
NCC
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li>Match subjects who experienced the event of interest (called cases) to a subset of event-free subjects (called controls) using incidence density sampling</li>
<li>Some controls could later become cases themselves and also serve as controls for other cases</li>
<li>Four controls per case has been shown to provide near-optimal statistical efficiency without the need for the full cohort analysis</li>
</ul>
</div>
</div>
</section>
<section id="hdps-in-the-ncc-framework" class="level2 page-columns page-full" data-number="25.3">
<h2 data-number="25.3" class="anchored" data-anchor-id="hdps-in-the-ncc-framework"><span class="header-section-number">25.3</span> hdPS in the NCC framework</h2>
<p>The time-dependent exposure status becomes a time-independent exposure variable in the NCC analysis. Hence, we could implement the hdPS technique in the NCC framework to deal with residual confounding bias.</p>
<div class="no-row-height column-margin column-container"><div class="">
<p><span class="citation" data-cites="Hossain2025">(<a href="references.html#ref-Hossain2025" role="doc-biblioref">Hossain et al. 2025</a>)</span></p>
</div></div><section id="step-0-analytic-data" class="level3" data-number="25.3.1">
<h3 data-number="25.3.1" class="anchored" data-anchor-id="step-0-analytic-data"><span class="header-section-number">25.3.1</span> Step 0: Analytic data</h3>
<p>To demonstrate the use of hdPS analysis with a time-dependent exposure, we will use a simulated dataset. This example explores the relationship between exposure to disease-modifying drugs (DMDs) for multiple sclerosis and all-cause mortality.</p>
<section id="dataset-with-time-dependent-exposure" class="level4" data-number="25.3.1.1">
<h4 data-number="25.3.1.1" class="anchored" data-anchor-id="dataset-with-time-dependent-exposure"><span class="header-section-number">25.3.1.1</span> Dataset with time-dependent exposure</h4>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-3_921d0bc55d7d8dcb29e97fc0acc64b42">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(simdat)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div data-pagedtable="false">
<script data-pagedtable-source="" type="application/json">
{"columns":[{"label":[""],"name":["_rn_"],"type":[""],"align":["left"]},{"label":["id"],"name":[1],"type":["int"],"align":["right"]},{"label":["follow_up"],"name":[2],"type":["dbl"],"align":["right"]},{"label":["mortality_outcome"],"name":[3],"type":["dbl"],"align":["right"]},{"label":["age"],"name":[4],"type":["dbl"],"align":["right"]},{"label":["sex"],"name":[5],"type":["fct"],"align":["left"]},{"label":["ses"],"name":[6],"type":["fct"],"align":["left"]},{"label":["cci"],"name":[7],"type":["fct"],"align":["left"]},{"label":["year"],"name":[8],"type":["fct"],"align":["left"]},{"label":["anyDMD"],"name":[9],"type":["fct"],"align":["left"]},{"label":["yrs_anyDMD"],"name":[10],"type":["dbl"],"align":["right"]}],"data":[{"1":"1","2":"20.794070","3":"0","4":"42","5":"Male","6":"Low/middle","7":"No","8":"1996-2005","9":"No","10":"NA","_rn_":"1"},{"1":"2","2":"2.704966","3":"0","4":"48","5":"Female","6":"Low/middle","7":"No","8":"1996-2005","9":"No","10":"NA","_rn_":"2"},{"1":"3","2":"9.083251","3":"0","4":"75","5":"Female","6":"Low/middle","7":"No","8":"1996-2005","9":"Yes","10":"4.3966570","_rn_":"3"},{"1":"4","2":"5.150027","3":"1","4":"77","5":"Male","6":"Low/middle","7":"No","8":"2006-2017","9":"Yes","10":"0.3612843","_rn_":"4"},{"1":"5","2":"16.549838","3":"0","4":"35","5":"Female","6":"Low/middle","7":"No","8":"1996-2005","9":"No","10":"NA","_rn_":"5"},{"1":"6","2":"6.344778","3":"0","4":"56","5":"Female","6":"High","7":"Yes","8":"2006-2017","9":"No","10":"NA","_rn_":"6"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
</script>
</div>
</div>
</div>
</section>
<section id="ncc-with-4-control-per-case" class="level4" data-number="25.3.1.2">
<h4 data-number="25.3.1.2" class="anchored" data-anchor-id="ncc-with-4-control-per-case"><span class="header-section-number">25.3.1.2</span> NCC with 4 control per case</h4>
<p>Let us use the nested case-control (NCC) design with 4 controls per case. The <code>ccwc</code> function from the Epi package is used to create the nested case-control dataset. The <code>ccwc</code> function requires the following arguments:</p>
<ul>
<li><code>origin</code>: The time origin for the study</li>
<li><code>entry</code>: The time of entry into the study</li>
<li><code>exit</code>: The follow-up time</li>
<li><code>fail</code>: The event of interest</li>
<li><code>controls</code>: The number of controls per case</li>
<li><code>match</code>: The variables to match on</li>
</ul>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-4_d6b622bcf1dcb6cfebcda599d11d5b7b">
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(Epi)</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="fu">set.seed</span>(<span class="dv">100</span>)</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a>dat.ncc <span class="ot"><-</span> <span class="fu">ccwc</span>(</span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> <span class="at">origin =</span> <span class="dv">0</span>,</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> <span class="at">entry =</span> <span class="dv">0</span>,</span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a> <span class="at">exit =</span> follow_up,</span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a> <span class="at">fail =</span> mortality_outcome,</span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a> <span class="at">controls =</span> <span class="dv">4</span>, </span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a> <span class="at">match =</span> <span class="fu">list</span>(ses, cci, year),</span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a> <span class="at">include =</span> <span class="fu">list</span>(id, follow_up, mortality_outcome, anyDMD, yrs_anyDMD, </span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a> sex, age),</span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a> <span class="at">data =</span> simdat,</span>
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a> <span class="at">silent =</span> T</span>
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb2-16"><a href="#cb2-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-17"><a href="#cb2-17" aria-hidden="true" tabindex="-1"></a><span class="co"># Drop those experienced the event before being exposed</span></span>
<span id="cb2-18"><a href="#cb2-18" aria-hidden="true" tabindex="-1"></a>dat.ncc<span class="sc">$</span>anyDMD[dat.ncc<span class="sc">$</span>yrs_anyDMD <span class="sc">></span> dat.ncc<span class="sc">$</span>Time] <span class="ot"><-</span> <span class="cn">NA</span></span>
<span id="cb2-19"><a href="#cb2-19" aria-hidden="true" tabindex="-1"></a>dat.ncc <span class="ot"><-</span> dat.ncc[<span class="fu">complete.cases</span>(dat.ncc<span class="sc">$</span>anyDMD),]</span>
<span id="cb2-20"><a href="#cb2-20" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-21"><a href="#cb2-21" aria-hidden="true" tabindex="-1"></a>dat.ncc[<span class="dv">1</span><span class="sc">:</span><span class="dv">10</span>,]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div data-pagedtable="false">
<script data-pagedtable-source="" type="application/json">
{"columns":[{"label":[""],"name":["_rn_"],"type":[""],"align":["left"]},{"label":["Set"],"name":[1],"type":["dbl"],"align":["right"]},{"label":["Map"],"name":[2],"type":["dbl"],"align":["right"]},{"label":["Time"],"name":[3],"type":["dbl"],"align":["right"]},{"label":["Fail"],"name":[4],"type":["dbl"],"align":["right"]},{"label":["ses"],"name":[5],"type":["fct"],"align":["left"]},{"label":["cci"],"name":[6],"type":["fct"],"align":["left"]},{"label":["year"],"name":[7],"type":["fct"],"align":["left"]},{"label":["id"],"name":[8],"type":["int"],"align":["right"]},{"label":["follow_up"],"name":[9],"type":["dbl"],"align":["right"]},{"label":["mortality_outcome"],"name":[10],"type":["dbl"],"align":["right"]},{"label":["anyDMD"],"name":[11],"type":["fct"],"align":["left"]},{"label":["yrs_anyDMD"],"name":[12],"type":["dbl"],"align":["right"]},{"label":["sex"],"name":[13],"type":["fct"],"align":["left"]},{"label":["age"],"name":[14],"type":["dbl"],"align":["right"]}],"data":[{"1":"1","2":"4","3":"5.150027","4":"1","5":"Low/middle","6":"No","7":"2006-2017","8":"4","9":"5.150027","10":"1","11":"Yes","12":"0.36128428","13":"Male","14":"77","_rn_":"1"},{"1":"1","2":"3917","3":"5.150027","4":"0","5":"Low/middle","6":"No","7":"2006-2017","8":"3917","9":"20.772854","10":"0","11":"No","12":"NA","13":"Female","14":"24","_rn_":"2"},{"1":"1","2":"15970","3":"5.150027","4":"0","5":"Low/middle","6":"No","7":"2006-2017","8":"15970","9":"17.254431","10":"0","11":"No","12":"NA","13":"Male","14":"32","_rn_":"3"},{"1":"1","2":"3628","3":"5.150027","4":"0","5":"Low/middle","6":"No","7":"2006-2017","8":"3628","9":"12.793185","10":"0","11":"Yes","12":"4.12910096","13":"Female","14":"48","_rn_":"4"},{"1":"1","2":"15657","3":"5.150027","4":"0","5":"Low/middle","6":"No","7":"2006-2017","8":"15657","9":"20.232896","10":"0","11":"No","12":"NA","13":"Male","14":"48","_rn_":"5"},{"1":"2","2":"18","3":"2.956407","4":"1","5":"Low/middle","6":"No","7":"2006-2017","8":"18","9":"2.956407","10":"1","11":"No","12":"NA","13":"Female","14":"73","_rn_":"6"},{"1":"2","2":"10618","3":"2.956407","4":"0","5":"Low/middle","6":"No","7":"2006-2017","8":"10618","9":"11.255467","10":"0","11":"No","12":"NA","13":"Female","14":"31","_rn_":"7"},{"1":"2","2":"5636","3":"2.956407","4":"0","5":"Low/middle","6":"No","7":"2006-2017","8":"5636","9":"11.536196","10":"1","11":"No","12":"NA","13":"Female","14":"62","_rn_":"8"},{"1":"2","2":"7578","3":"2.956407","4":"0","5":"Low/middle","6":"No","7":"2006-2017","8":"7578","9":"15.539760","10":"0","11":"Yes","12":"0.07921368","13":"Female","14":"62","_rn_":"9"},{"1":"2","2":"1218","3":"2.956407","4":"0","5":"Low/middle","6":"No","7":"2006-2017","8":"1218","9":"17.693504","10":"0","11":"No","12":"NA","13":"Female","14":"18","_rn_":"10"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
</script>
</div>
</div>
</div>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-5_921ebe7ec2c2cbe2a7a5b41b4ed0a06a">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Rows</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="fu">dim</span>(simdat)</span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="co">#> [1] 19000 10</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a><span class="fu">dim</span>(dat.ncc)</span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a><span class="co">#> [1] 14370 14</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a><span class="co"># Mortality status</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a><span class="fu">table</span>(simdat<span class="sc">$</span>mortality_outcome)</span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a><span class="co">#> </span></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a><span class="co">#> 0 1 </span></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a><span class="co">#> 15947 3053</span></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a><span class="fu">table</span>(dat.ncc<span class="sc">$</span>Fail)</span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a><span class="co">#> </span></span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a><span class="co">#> 0 1 </span></span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a><span class="co">#> 11317 3053</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
</section>
<section id="step-1-proxy-sources" class="level3" data-number="25.3.2">
<h3 data-number="25.3.2" class="anchored" data-anchor-id="step-1-proxy-sources"><span class="header-section-number">25.3.2</span> Step 1: Proxy sources</h3>
<p>In this example, we will use four data dimensions:</p>
<ul>
<li>3-digit diagnostic codes from hospital database (<em>diag</em>)</li>
<li>3-digit procedure codes from hospital database (<em>proc</em>)</li>
<li>3-digit icd codes from physician claim database (<em>msp</em>)</li>
<li>DINPIN from drug dispensation database (<em>din</em>)</li>
</ul>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-6_8635b5c88f127e38175e003b17818399">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="fu">table</span>(dat.proxy<span class="sc">$</span>dim)</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="co">#> </span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="co">#> diag din msp proc </span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a><span class="co">#> 10000 125 22135 158</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="step-2-empirical-covariates" class="level3" data-number="25.3.3">
<h3 data-number="25.3.3" class="anchored" data-anchor-id="step-2-empirical-covariates"><span class="header-section-number">25.3.3</span> Step 2: Empirical covariates</h3>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-7_06aab537655e1fba7d00d534a5b99d30">
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(autoCovariateSelection)</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>id <span class="ot"><-</span> simdat<span class="sc">$</span>id</span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a>step1 <span class="ot"><-</span> <span class="fu">get_candidate_covariates</span>(<span class="at">df =</span> dat.proxy, <span class="at">domainVarname =</span> <span class="st">"dim"</span>, </span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a> <span class="at">eventCodeVarname =</span> <span class="st">"code"</span>, </span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a> <span class="at">patientIdVarname =</span> <span class="st">"id"</span>, </span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a> <span class="at">patientIdVector =</span> id, </span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a> <span class="at">n =</span> <span class="dv">1000</span>, </span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a> <span class="at">min_num_patients =</span> <span class="dv">20</span>)</span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a>out1 <span class="ot"><-</span> step1<span class="sc">$</span>covars_data</span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(out1)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div data-pagedtable="false">
<script data-pagedtable-source="" type="application/json">
{"columns":[{"label":[""],"name":["_rn_"],"type":[""],"align":["left"]},{"label":["id"],"name":[1],"type":["int"],"align":["right"]},{"label":["code"],"name":[2],"type":["chr"],"align":["left"]}],"data":[{"1":"3430","2":"diag_S82","_rn_":"1"},{"1":"3052","2":"diag_S75","_rn_":"2"},{"1":"11159","2":"diag_S42","_rn_":"3"},{"1":"17207","2":"diag_S62","_rn_":"4"},{"1":"13410","2":"diag_S61","_rn_":"5"},{"1":"12471","2":"diag_I69","_rn_":"6"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
</script>
</div>
</div>
</div>
</section>
<section id="step-3-recurrence" class="level3" data-number="25.3.4">
<h3 data-number="25.3.4" class="anchored" data-anchor-id="step-3-recurrence"><span class="header-section-number">25.3.4</span> Step 3: Recurrence</h3>
<p>Let us generate the binary recurrence covariates.</p>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-8_a95b2604803c19fcc3fb41fabed07f91">
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="fu">all.equal</span>(id, step1<span class="sc">$</span>patientIds)</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a><span class="co">#> [1] TRUE</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Assessing recurrence of codes</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a>step2 <span class="ot"><-</span> <span class="fu">get_recurrence_covariates</span>(<span class="at">df =</span> out1, </span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a> <span class="at">eventCodeVarname =</span> <span class="st">"code"</span>, </span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a> <span class="at">patientIdVarname =</span> <span class="st">"id"</span>,</span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a> <span class="at">patientIdVector =</span> id)</span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a>out2 <span class="ot"><-</span> step2<span class="sc">$</span>recurrence_data</span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a><span class="fu">dim</span>(out2)</span>
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a><span class="co">#> [1] 19000 454</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-9_bbee50922122408c28ec4e6a7b31869e">
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Recurrence covariates</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a>vars.empirical <span class="ot"><-</span> <span class="fu">names</span>(out2)[<span class="sc">-</span><span class="dv">1</span>]</span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(vars.empirical)</span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a><span class="co">#> [1] "rec_diag_H02_once" "rec_diag_H18_once" "rec_diag_H35_once"</span></span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a><span class="co">#> [4] "rec_diag_H40_once" "rec_diag_H44_once" "rec_diag_I69_once"</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<section id="merging-all-recurrence-covariates-with-the-analytic-dataset" class="level4" data-number="25.3.4.1">
<h4 data-number="25.3.4.1" class="anchored" data-anchor-id="merging-all-recurrence-covariates-with-the-analytic-dataset"><span class="header-section-number">25.3.4.1</span> Merging all recurrence covariates with the analytic dataset</h4>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-10_ca3d97dd0b5953e7ba9ad6633c8759eb">
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>hdps.data <span class="ot"><-</span> <span class="fu">merge</span>(dat.ncc, out2, <span class="at">by =</span> <span class="st">"id"</span>, <span class="at">all.x =</span> T)</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a><span class="fu">dim</span>(hdps.data)</span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a><span class="co">#> [1] 14370 467</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
</section>
<section id="step-4-prioritize" class="level3" data-number="25.3.5">
<h3 data-number="25.3.5" class="anchored" data-anchor-id="step-4-prioritize"><span class="header-section-number">25.3.5</span> Step 4: Prioritize</h3>
<p>We will use Cox-PH with LASSO regularization to prioritize the empirical covariates. The hyperparameter (<span class="math inline">\(\lambda\)</span>) will be selected using 5-fold cross-validation.</p>
<section id="hyperparameter-tuning" class="level4" data-number="25.3.5.1">
<h4 data-number="25.3.5.1" class="anchored" data-anchor-id="hyperparameter-tuning"><span class="header-section-number">25.3.5.1</span> Hyperparameter tuning</h4>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-11_9a07bc92dd8e000ff97aadce0f0ec33c">
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Formula with only empirical covariates</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a>formula.out <span class="ot"><-</span> <span class="fu">as.formula</span>(<span class="fu">paste</span>(<span class="st">"Surv(Time, Fail) ~ "</span>, </span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">paste</span>(vars.empirical, <span class="at">collapse =</span> <span class="st">" + "</span>)))</span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true" tabindex="-1"></a><span class="co"># Model matrix for fitting Cox with LASSO regularization</span></span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true" tabindex="-1"></a>X <span class="ot"><-</span> <span class="fu">model.matrix</span>(formula.out, <span class="at">data =</span> hdps.data)[,<span class="sc">-</span><span class="dv">1</span>]</span>
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true" tabindex="-1"></a>Y <span class="ot"><-</span> <span class="fu">as.matrix</span>(<span class="fu">data.frame</span>(<span class="at">time =</span> hdps.data<span class="sc">$</span>Time, <span class="at">status =</span> hdps.data<span class="sc">$</span>Fail))</span>
<span id="cb9-8"><a href="#cb9-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb9-9"><a href="#cb9-9" aria-hidden="true" tabindex="-1"></a><span class="co"># Detect the number of cores</span></span>
<span id="cb9-10"><a href="#cb9-10" aria-hidden="true" tabindex="-1"></a>n_cores <span class="ot"><-</span> parallel<span class="sc">::</span><span class="fu">detectCores</span>()</span>
<span id="cb9-11"><a href="#cb9-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb9-12"><a href="#cb9-12" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a cluster of cores</span></span>
<span id="cb9-13"><a href="#cb9-13" aria-hidden="true" tabindex="-1"></a>cl <span class="ot"><-</span> <span class="fu">makeCluster</span>(n_cores <span class="sc">-</span> <span class="dv">1</span>)</span>
<span id="cb9-14"><a href="#cb9-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb9-15"><a href="#cb9-15" aria-hidden="true" tabindex="-1"></a><span class="co"># Register the cluster for parallel processing</span></span>
<span id="cb9-16"><a href="#cb9-16" aria-hidden="true" tabindex="-1"></a><span class="fu">registerDoParallel</span>(cl)</span>
<span id="cb9-17"><a href="#cb9-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb9-18"><a href="#cb9-18" aria-hidden="true" tabindex="-1"></a><span class="co"># Hyperparameter tuning with 5-fold cross-validation </span></span>
<span id="cb9-19"><a href="#cb9-19" aria-hidden="true" tabindex="-1"></a><span class="fu">set.seed</span>(<span class="dv">123</span>)</span>
<span id="cb9-20"><a href="#cb9-20" aria-hidden="true" tabindex="-1"></a>fit.lasso <span class="ot"><-</span> <span class="fu">cv.glmnet</span>(<span class="at">x =</span> X, <span class="at">y =</span> Y, <span class="at">nfolds =</span> <span class="dv">5</span>, <span class="at">parallel =</span> T, <span class="at">alpha =</span> <span class="dv">1</span>, </span>
<span id="cb9-21"><a href="#cb9-21" aria-hidden="true" tabindex="-1"></a> <span class="at">family =</span> <span class="st">"cox"</span>)</span>
<span id="cb9-22"><a href="#cb9-22" aria-hidden="true" tabindex="-1"></a><span class="fu">stopCluster</span>(cl)</span>
<span id="cb9-23"><a href="#cb9-23" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb9-24"><a href="#cb9-24" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(fit.lasso)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="ncc_files/figure-html/unnamed-chunk-11-1.png" class="img-fluid" width="672"></p>
</div>
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a><span class="do">## Best lambda</span></span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a>fit.lasso<span class="sc">$</span>lambda.min</span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a><span class="co">#> [1] 0.01042345</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="variable-ranking-based-on-cox-lasso" class="level4" data-number="25.3.5.2">
<h4 data-number="25.3.5.2" class="anchored" data-anchor-id="variable-ranking-based-on-cox-lasso"><span class="header-section-number">25.3.5.2</span> Variable ranking based on Cox-LASSO</h4>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-12_87dd134a3d8defd6bc53c9860b233bc0">
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>empvars.lasso <span class="ot"><-</span> <span class="fu">coef</span>(fit.lasso, <span class="at">s =</span> fit.lasso<span class="sc">$</span>lambda.min) </span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a>empvars.lasso <span class="ot"><-</span> <span class="fu">data.frame</span>(<span class="fu">as.matrix</span>(empvars.lasso))</span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a>empvars.lasso <span class="ot"><-</span> <span class="fu">data.frame</span>(<span class="at">vars =</span> <span class="fu">rownames</span>(empvars.lasso), </span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a> <span class="at">coef =</span> empvars.lasso)</span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(empvars.lasso) <span class="ot"><-</span> <span class="fu">c</span>(<span class="st">"vars"</span>, <span class="st">"coef"</span>)</span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a><span class="fu">rownames</span>(empvars.lasso) <span class="ot"><-</span> <span class="cn">NULL</span></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a><span class="co"># Number of non-zero coefficients</span></span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true" tabindex="-1"></a><span class="fu">table</span>(empvars.lasso<span class="sc">$</span>coef <span class="sc">!=</span> <span class="dv">0</span>)</span>
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true" tabindex="-1"></a><span class="co">#> </span></span>
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true" tabindex="-1"></a><span class="co">#> FALSE TRUE </span></span>
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true" tabindex="-1"></a><span class="co">#> 442 11</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Since proxies were random and unrelated to the simulated data, LASSO produced only 11 non-zero coefficients. Let choose an arbitrary value as to demonstrate the process of variable selection.</p>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-13_34b9272f3c56d3eac549653a1bbbcc63">
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a>empvars.lasso <span class="ot"><-</span> <span class="fu">coef</span>(fit.lasso, <span class="at">s =</span> <span class="fu">exp</span>(<span class="sc">-</span><span class="dv">6</span>)) </span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a>empvars.lasso <span class="ot"><-</span> <span class="fu">data.frame</span>(<span class="fu">as.matrix</span>(empvars.lasso))</span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a>empvars.lasso <span class="ot"><-</span> <span class="fu">data.frame</span>(<span class="at">vars =</span> <span class="fu">rownames</span>(empvars.lasso), </span>
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a> <span class="at">coef =</span> empvars.lasso)</span>
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(empvars.lasso) <span class="ot"><-</span> <span class="fu">c</span>(<span class="st">"vars"</span>, <span class="st">"coef"</span>)</span>
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a><span class="fu">rownames</span>(empvars.lasso) <span class="ot"><-</span> <span class="cn">NULL</span></span>
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(empvars.lasso)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div data-pagedtable="false">
<script data-pagedtable-source="" type="application/json">
{"columns":[{"label":[""],"name":["_rn_"],"type":[""],"align":["left"]},{"label":["vars"],"name":[1],"type":["chr"],"align":["left"]},{"label":["coef"],"name":[2],"type":["dbl"],"align":["right"]}],"data":[{"1":"rec_diag_H02_once","2":"0.000000000","_rn_":"1"},{"1":"rec_diag_H18_once","2":"0.006949322","_rn_":"2"},{"1":"rec_diag_H35_once","2":"0.000000000","_rn_":"3"},{"1":"rec_diag_H40_once","2":"0.573851382","_rn_":"4"},{"1":"rec_diag_H44_once","2":"0.000000000","_rn_":"5"},{"1":"rec_diag_I69_once","2":"-0.473305090","_rn_":"6"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
</script>
</div>
</div>
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a><span class="co"># Number of non-zero coefficients</span></span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a><span class="fu">table</span>(empvars.lasso<span class="sc">$</span>coef <span class="sc">!=</span> <span class="dv">0</span>)</span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a><span class="co">#> </span></span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a><span class="co">#> FALSE TRUE </span></span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a><span class="co">#> 196 257</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="rank-empirical-covariates" class="level4" data-number="25.3.5.3">
<h4 data-number="25.3.5.3" class="anchored" data-anchor-id="rank-empirical-covariates"><span class="header-section-number">25.3.5.3</span> Rank empirical covariates</h4>
<p>Now we will rank the empirical covariates based on absolute value of log hazard ratio.</p>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-14_aae49d1a0fa86e24618ae27589326f22">
<div class="sourceCode cell-code" id="cb14"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a>empvars.lasso<span class="sc">$</span>coef.abs <span class="ot"><-</span> <span class="fu">abs</span>(empvars.lasso<span class="sc">$</span>coef)</span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a>empvars.lasso <span class="ot"><-</span> empvars.lasso[<span class="fu">order</span>(empvars.lasso<span class="sc">$</span>coef.abs, <span class="at">decreasing =</span> T),]</span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(empvars.lasso)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div data-pagedtable="false">
<script data-pagedtable-source="" type="application/json">
{"columns":[{"label":[""],"name":["_rn_"],"type":[""],"align":["left"]},{"label":["vars"],"name":[1],"type":["chr"],"align":["left"]},{"label":["coef"],"name":[2],"type":["dbl"],"align":["right"]},{"label":["coef.abs"],"name":[3],"type":["dbl"],"align":["right"]}],"data":[{"1":"rec_diag_T44_once","2":"-1.703227","3":"1.703227","_rn_":"93"},{"1":"rec_diag_O41_once","2":"-1.254879","3":"1.254879","_rn_":"25"},{"1":"rec_msp_793_once","2":"1.225002","3":"1.225002","_rn_":"366"},{"1":"rec_msp_459_once","2":"1.172755","3":"1.172755","_rn_":"240"},{"1":"rec_msp_807_once","2":"1.163068","3":"1.163068","_rn_":"378"},{"1":"rec_msp_117_once","2":"-1.136078","3":"1.136078","_rn_":"141"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
</script>
</div>
</div>
</div>
</section>
</section>
<section id="step-5-covariates" class="level3" data-number="25.3.6">
<h3 data-number="25.3.6" class="anchored" data-anchor-id="step-5-covariates"><span class="header-section-number">25.3.6</span> Step 5: Covariates</h3>
<p>We used all investigator-specified covariates and the top 200 empirical covariates for the PS model. Again, this is a simplistic scenario where we only consider the main effects of the covariates.</p>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-15_c4a41fbf778c998a55246b24a9b3d4cd">
<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Investigator-specified covariates</span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a>investigator.vars <span class="ot"><-</span> <span class="fu">c</span>(<span class="st">"sex"</span>, <span class="st">"age"</span>)</span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Top 200 empirical covariates section based on Cox-LASSO</span></span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true" tabindex="-1"></a>empirical.vars.lasso <span class="ot"><-</span> empvars.lasso<span class="sc">$</span>vars[<span class="dv">1</span><span class="sc">:</span><span class="dv">200</span>]</span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true" tabindex="-1"></a><span class="co"># Investigator-specified and empirical covariates</span></span>
<span id="cb15-8"><a href="#cb15-8" aria-hidden="true" tabindex="-1"></a>vars.hsps <span class="ot"><-</span> <span class="fu">c</span>(investigator.vars, empirical.vars.lasso)</span>
<span id="cb15-9"><a href="#cb15-9" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(vars.hsps)</span>
<span id="cb15-10"><a href="#cb15-10" aria-hidden="true" tabindex="-1"></a><span class="co">#> [1] "sex" "age" "rec_diag_T44_once"</span></span>
<span id="cb15-11"><a href="#cb15-11" aria-hidden="true" tabindex="-1"></a><span class="co">#> [4] "rec_diag_O41_once" "rec_msp_793_once" "rec_msp_459_once"</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="step-6-propensity-score" class="level3" data-number="25.3.7">
<h3 data-number="25.3.7" class="anchored" data-anchor-id="step-6-propensity-score"><span class="header-section-number">25.3.7</span> Step 6: Propensity score</h3>
<section id="create-propensity-score-formula" class="level4" data-number="25.3.7.1">
<h4 data-number="25.3.7.1" class="anchored" data-anchor-id="create-propensity-score-formula"><span class="header-section-number">25.3.7.1</span> Create propensity score formula</h4>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-16_cf9cb7de6f06119cfb101735b6db13bd">
<div class="sourceCode cell-code" id="cb16"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a>ps.formula <span class="ot"><-</span> <span class="fu">as.formula</span>(<span class="fu">paste0</span>(<span class="st">"I(anyDMD == 'Yes') ~ "</span>, </span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">paste</span>(vars.hsps, <span class="at">collapse =</span> <span class="st">"+"</span>)))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="fit-ps-model" class="level4" data-number="25.3.7.2">
<h4 data-number="25.3.7.2" class="anchored" data-anchor-id="fit-ps-model"><span class="header-section-number">25.3.7.2</span> Fit PS model</h4>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-17_be4dfac737858f2bc115e5e18e5a8eb1">
<div class="sourceCode cell-code" id="cb17"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="fu">require</span>(WeightIt)</span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a>W.out <span class="ot"><-</span> <span class="fu">weightit</span>(ps.formula, </span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a> <span class="at">data =</span> hdps.data, </span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true" tabindex="-1"></a> <span class="at">estimand =</span> <span class="st">"ATE"</span>,</span>
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true" tabindex="-1"></a> <span class="at">method =</span> <span class="st">"ps"</span>,</span>
<span id="cb17-6"><a href="#cb17-6" aria-hidden="true" tabindex="-1"></a> <span class="at">stabilize =</span> T)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="obtain-ps" class="level4" data-number="25.3.7.3">
<h4 data-number="25.3.7.3" class="anchored" data-anchor-id="obtain-ps"><span class="header-section-number">25.3.7.3</span> Obtain PS</h4>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-18_066af5b07015d5360aa3a0113fbf5f11">
<div class="sourceCode cell-code" id="cb18"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a>hdps.data<span class="sc">$</span>ps <span class="ot"><-</span> W.out<span class="sc">$</span>ps</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="obtain-weights" class="level4" data-number="25.3.7.4">
<h4 data-number="25.3.7.4" class="anchored" data-anchor-id="obtain-weights"><span class="header-section-number">25.3.7.4</span> Obtain weights</h4>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-19_55412e5921071d1314360cbd05f665c2">
<div class="sourceCode cell-code" id="cb19"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a>hdps.data<span class="sc">$</span>w <span class="ot"><-</span> W.out<span class="sc">$</span>weights</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-20_aeee47da6f9ff2220001fb872d102a07">
<div class="cell-output-display">
<p><img src="ncc_files/figure-html/unnamed-chunk-20-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="assessing-balance" class="level4" data-number="25.3.7.5">
<h4 data-number="25.3.7.5" class="anchored" data-anchor-id="assessing-balance"><span class="header-section-number">25.3.7.5</span> Assessing balance</h4>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-21_ae76de6a032f01fc60fe2366a8190b24">
<div class="cell-output-display">
<p><img src="ncc_files/figure-html/unnamed-chunk-21-1.png" class="img-fluid" width="480"></p>
</div>
</div>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-22_275d82c5efc7ca06e6d06ceae54aa855">
<div class="sourceCode cell-code" id="cb20"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(survey)</span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Balance checking for investigator-specified covariates</span></span>
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a>design.ipw <span class="ot"><-</span> <span class="fu">svydesign</span>(<span class="at">ids =</span> <span class="sc">~</span>id, <span class="at">weights =</span> <span class="sc">~</span>w, <span class="at">data =</span> hdps.data)</span>
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a>tab.ipw <span class="ot"><-</span> <span class="fu">svyCreateTableOne</span>(<span class="at">vars =</span> investigator.vars, </span>
<span id="cb20-6"><a href="#cb20-6" aria-hidden="true" tabindex="-1"></a> <span class="at">strata =</span> <span class="st">"anyDMD"</span>, </span>
<span id="cb20-7"><a href="#cb20-7" aria-hidden="true" tabindex="-1"></a> <span class="at">data =</span> design.ipw, </span>
<span id="cb20-8"><a href="#cb20-8" aria-hidden="true" tabindex="-1"></a> <span class="at">test =</span> F)</span>
<span id="cb20-9"><a href="#cb20-9" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(tab.ipw, <span class="at">smd =</span> T) <span class="co"># Age and sex are balanced</span></span>
<span id="cb20-10"><a href="#cb20-10" aria-hidden="true" tabindex="-1"></a><span class="co">#> Stratified by anyDMD</span></span>
<span id="cb20-11"><a href="#cb20-11" aria-hidden="true" tabindex="-1"></a><span class="co">#> No Yes SMD </span></span>
<span id="cb20-12"><a href="#cb20-12" aria-hidden="true" tabindex="-1"></a><span class="co">#> n 11035.4 3324.4 </span></span>
<span id="cb20-13"><a href="#cb20-13" aria-hidden="true" tabindex="-1"></a><span class="co">#> sex = Male (%) 3199.3 (29.0) 1007.3 (30.3) 0.029</span></span>
<span id="cb20-14"><a href="#cb20-14" aria-hidden="true" tabindex="-1"></a><span class="co">#> age (mean (SD)) 45.58 (13.75) 45.67 (13.48) 0.007</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
</section>
<section id="step-7-association" class="level3 page-columns page-full" data-number="25.3.8">
<h3 data-number="25.3.8" class="anchored" data-anchor-id="step-7-association"><span class="header-section-number">25.3.8</span> Step 7: Association</h3>
<section id="obtain-hr" class="level4" data-number="25.3.8.1">
<h4 data-number="25.3.8.1" class="anchored" data-anchor-id="obtain-hr"><span class="header-section-number">25.3.8.1</span> Obtain HR</h4>
<p>We can fit the Cox-PH model, adjusting for the matched strata.</p>
<div class="cell" data-hash="ncc_cache/html/unnamed-chunk-23_67931037f8748f4afddde6130cf2040d">
<div class="sourceCode cell-code" id="cb21"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(survival)</span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(Publish)</span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a>fit.hdps <span class="ot"><-</span> <span class="fu">coxph</span>(<span class="fu">Surv</span>(Time, Fail) <span class="sc">~</span> anyDMD <span class="sc">+</span> <span class="fu">strata</span>(Set), </span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a> <span class="at">weights =</span> w,</span>
<span id="cb21-5"><a href="#cb21-5" aria-hidden="true" tabindex="-1"></a> <span class="at">data =</span> hdps.data)</span>
<span id="cb21-6"><a href="#cb21-6" aria-hidden="true" tabindex="-1"></a><span class="fu">publish</span>(fit.hdps, <span class="at">pvalue.method =</span> <span class="st">"robust"</span>, <span class="at">confint.method =</span> <span class="st">"robust"</span>, </span>
<span id="cb21-7"><a href="#cb21-7" aria-hidden="true" tabindex="-1"></a> <span class="at">print =</span> F)<span class="sc">$</span>regressionTable[<span class="dv">1</span><span class="sc">:</span><span class="dv">2</span>,]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div data-pagedtable="false">
<script data-pagedtable-source="" type="application/json">
{"columns":[{"label":[""],"name":["_rn_"],"type":[""],"align":["left"]},{"label":["Variable"],"name":[1],"type":["chr"],"align":["left"]},{"label":["Units"],"name":[2],"type":["chr"],"align":["left"]},{"label":["HazardRatio"],"name":[3],"type":["chr"],"align":["left"]},{"label":["CI.95"],"name":[4],"type":["chr"],"align":["left"]},{"label":["p-value"],"name":[5],"type":["chr"],"align":["left"]}],"data":[{"1":"anyDMD","2":"No","3":"Ref","4":"","5":"","_rn_":"1"},{"1":"","2":"Yes","3":"0.63","4":"[0.56;0.69]","5":"<0.001","_rn_":"2"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
</script>
</div>
</div>
</div>
</section>
<section id="obtain-hr-with-conditional-logistic" class="level4 page-columns page-full" data-number="25.3.8.2">
<h4 data-number="25.3.8.2" class="anchored" data-anchor-id="obtain-hr-with-conditional-logistic"><span class="header-section-number">25.3.8.2</span> Obtain HR with conditional logistic</h4>
<p>For the NCC analysis, an alternative to the stratified Cox-PH model is to use the conditional logistic regression. The HR and SE from both models should be similar under the proportional hazards assumption.</p>
<div class="no-row-height column-margin column-container"><div class="">
<p><span class="citation" data-cites="liu2010cox">(<a href="references.html#ref-liu2010cox" role="doc-biblioref">Liu et al. 2010</a>)</span></p>
</div></div><div class="cell" data-hash="ncc_cache/html/unnamed-chunk-24_213fd889a105f016140e6943448799e8">
<div class="sourceCode cell-code" id="cb22"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a>fit.hdps1 <span class="ot"><-</span> <span class="fu">clogit</span>(Fail <span class="sc">~</span> anyDMD <span class="sc">+</span> <span class="fu">strata</span>(Set), </span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a> <span class="at">weights =</span> w, </span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a> <span class="at">data =</span> hdps.data, </span>
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true" tabindex="-1"></a> <span class="at">method =</span> <span class="st">"efron"</span>)</span>
<span id="cb22-5"><a href="#cb22-5" aria-hidden="true" tabindex="-1"></a><span class="fu">publish</span>(fit.hdps1, <span class="at">pvalue.method =</span> <span class="st">"robust"</span>, <span class="at">confint.method =</span> <span class="st">"robust"</span>, </span>
<span id="cb22-6"><a href="#cb22-6" aria-hidden="true" tabindex="-1"></a> <span class="at">print =</span> F)<span class="sc">$</span>regressionTable[<span class="dv">1</span><span class="sc">:</span><span class="dv">2</span>,]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div data-pagedtable="false">
<script data-pagedtable-source="" type="application/json">
{"columns":[{"label":[""],"name":["_rn_"],"type":[""],"align":["left"]},{"label":["Variable"],"name":[1],"type":["chr"],"align":["left"]},{"label":["Units"],"name":[2],"type":["chr"],"align":["left"]},{"label":["HazardRatio"],"name":[3],"type":["chr"],"align":["left"]},{"label":["CI.95"],"name":[4],"type":["chr"],"align":["left"]},{"label":["p-value"],"name":[5],"type":["chr"],"align":["left"]}],"data":[{"1":"anyDMD","2":"No","3":"Ref","4":"","5":"","_rn_":"1"},{"1":"","2":"Yes","3":"0.63","4":"[0.56;0.69]","5":"<0.001","_rn_":"2"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
</script>
</div>
</div>
</div>
<div id="refs" class="references csl-bib-body hanging-indent" role="doc-bibliography" style="display: none">
<div id="ref-austin2012comparing" class="csl-entry" role="doc-biblioentry">
Austin, Peter C, Geoffrey M Anderson, Candemir Cigsar, and Andrea Gruneir. 2012. <span>“Comparing the Cohort Design and the Nested Case–Control Design in the Presence of Both Time-Invariant and Time-Dependent Treatment and Competing Risks: Bias and Precision.”</span> <em>Pharmacoepidemiology and Drug Safety</em> 21 (7): 714–24.
</div>
<div id="ref-ernster1994nested" class="csl-entry" role="doc-biblioentry">
Ernster, Virginia L. 1994. <span>“Nested Case-Control Studies.”</span> <em>Preventive Medicine</em> 23 (5): 587–90.
</div>
<div id="ref-Hossain2025" class="csl-entry" role="doc-biblioentry">
Hossain, Md Belal, Huah Shin Ng, Feng Zhu, Helen Tremlett, and Mohammad Ehsanul Karim. 2025. <span>“Simultaneously Dealing with Immortal Time Bias and Residual Confounding: A Case Study of a High-Dimensional Propensity Score Approach with a Nested Case–Control Framework in Multiple Sclerosis Research.”</span> <em>Pharmacoepidemiology and Drug Safety</em> 34 (7): e70174.
</div>
<div id="ref-hossain2024benefits" class="csl-entry" role="doc-biblioentry">
Hossain, Md Belal, Hubert Wong, Mohsen Sadatsafavi, James C Johnston, Victoria J Cook, and Mohammad Ehsanul Karim. 2024. <span>“Benefits of Repeated Matched-Cohort and Nested Case–Control Analyses with Time-Dependent Exposure in Observational Studies.”</span> <em>Statistics in Biosciences</em>, 1–29.
</div>
<div id="ref-liu2010cox" class="csl-entry" role="doc-biblioentry">
Liu, Mengling, Wenbin Lu, Roy E Shore, and Anne Zeleniuch-Jacquotte. 2010. <span>“Cox Regression Model with Time-Varying Coefficients in Nested Case–Control Studies.”</span> <em>Biostatistics</em> 11 (4): 693–706.
</div>
</div>
</section>
</section>
</section>
</main> <!-- /main -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const clipboard = new window.ClipboardJS('.code-copy-button', {
target: function(trigger) {
return trigger.previousElementSibling;
}
});
clipboard.on('success', function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
let tooltip;
if (window.bootstrap) {
button.setAttribute("data-bs-toggle", "tooltip");
button.setAttribute("data-bs-placement", "left");
button.setAttribute("data-bs-title", "Copied!");