This repository was archived by the owner on Apr 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoint_model.Rmd
executable file
·1769 lines (1549 loc) · 55.3 KB
/
joint_model.Rmd
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
---
title: 'Jointly Modelling SNPs<br>with<br>Survival & Longitudinal Trait'
author: 'Mickaël CANOUIL, *Ph.D.*'
date: 'Monday, 21<sup>st</sup> of January (2019)'
monofont: 'Source Code Pro'
monofontoptions: 'Scale=0.7'
bibliography: [bib/Canouil_etal_2018.bib]
biblio-style: apalike
nocite: |
@rizopoulos_joint_2012, @elashoff_joint_2016
csl: template/csl/apa.csl
params:
eval: TRUE
output:
ioslides_presentation:
css: 'template/dark.css'
logo: 'template/logo_UMR.png'
smaller: false
self_contained: true
incremental: false
---
```{r setup, include = FALSE}
options(stringsAsFactors = FALSE)
# Sys.setlocale("LC_TIME", "english_united kingdom.1252")
output_directory <- ""
### Load packages and functions
require(JM)
require(survival)
require(survminer)
library(tidyverse)
library(broom)
library(scales)
library(parallel)
library(grid)
library(knitr)
library(rmarkdown)
library(kableExtra)
library(gganimate)
options(gganimate.dev_args = list(width = 800, height = 450))
library(ggrepel)
library(ggraph)
source('https://github.com/mcanouil/DEV/raw/master/R/theme_black.R')
source('https://github.com/mcanouil/DEV/raw/master/R/ggmanhattan.R')
source('https://github.com/mcanouil/DEV/raw/master/joint_model/jointModelSimulation.R')
pretty_kable <- function (
data,
font_size = 12,
format_args = list(scientific = -1, digits = 3, big.mark = ","),
col.names = NA,
full_width = FALSE,
format = "html",
...
) {
output <- knitr::kable(
x = data,
format.args = format_args,
col.names = col.names,
...
)
kableExtra::kable_styling(
kable_input = output,
bootstrap_options = c("striped", "hover", "condensed", "responsive"),
full_width = full_width,
position = "center",
font_size = font_size
)
}
options("width" = 80)
### Set knitr rmarkdown chunk options
opts_chunk$set(
include = TRUE,
echo = FALSE,
warning = FALSE,
message = FALSE,
eval = params$eval,
tidy = FALSE,
crop = TRUE,
autodep = TRUE,
dpi = 120,
fig.path = "./images/",
cache = TRUE,
# cache.path = NULL,
width = 80,
comment = "#>",
results = "asis",
fig.height = 3.375, # floor(10/3 * 10)/10* 0.9,
fig.width = 6 # floor(16/9 * 10/3 *10)/10 * 0.9
)
### Define theme
theme_set(theme_black(base_size = 14))
# options(tibble.print_max = 3, tibble.print_min = 3)
### Get data
# file.copy(
# from = "/disks/DATATMP/DESIR_longitudinal/ArticleR/MetaboChip_T2D.annot.Rdata",
# to = "data/MetaboChip_T2D.annot.Rdata"
# )
load(file = "data/MetaboChip_T2D.annot.Rdata")
# jm_data <- new.env()
# load(file = "/disks/DATATMP/DESIR_longitudinal/ArticleR/DataArticle_20180417.Rdata", envir = jm_data)
# rm(
# list = setdiff(ls(jm_data), c("rawsettings", "bestEffect", "simuDtaRMSE", "sprof", "p.estimateJM.sign")),
# envir = jm_data
# )
# save(jm_data, file = "data/DataArticle_20180417.Rdata")
load(file = "data/DataArticle_20180417.Rdata")
### Some functions
format_scientific <- function(x, digits = 3) {
y <- format(x, scientific = -1, digits = digits)
if (length(grep("e", y)) != 0) {
return(
paste0(
gsub("e.*", "", format(x, scientific = -1, digits = digits)),
"\\times 10^{",
gsub(".*e", "", format(x, scientific = -1, digits = digits)), "}"
)
)
} else {
return(y)
}
}
my_trans <- function () {
trans_new(
name = "my",
transform = function(x){sqrt(abs(x))*sign(x)},
inverse = function(x) {(x^2)*sign(x)},
domain = c(-Inf, Inf)
)
}
sqrt_zero_trans <- function() {
trans_new(
name = "sqrt_zero",
transform = base::sqrt,
inverse = function(x) ifelse(x==0, 0, x^2),
domain = c(0, Inf)
)
}
```
# Around the Genetic<br>of<br>Type 2 Diabetes | A bit of history ... {.flexbox .vcenter}
## A lot of SNPs discovered ... {.flexbox .vcenter}
```{r t2dhistory, out.height = "432px", out.width = "768px"}
include_graphics(path = "images/T2Dhistory.jpg")
```
<p>@flannick_type_2016</p>
## Associated with T2D and traits ... {.flexbox .vcenter}
```{r prokopenko, out.height = "432px", out.width = "768px"}
include_graphics(path = "images/ProkopenkoMetaboDiagram.png")
```
<p>@marullo_insights_2014</p>
## But, weak correlation of the effects {.flexbox .vcenter}
```{r scott1, out.height = "432px", out.width = "432px"}
include_graphics(path = "images/ng2385-F2.png")
```
<p>@scott_large-scale_2012</p>
## But, weak correlation of the effects {.flexbox .vcenter}
```{r yaghootkar1, out.height = "432px", out.width = "768px"}
include_graphics(path = "images/Yaghootkar.png")
```
<p>@yaghootkar_recent_2013</p>
# Is There<br>a<br>Genetic Joint Effect? {.flexbox .vcenter}
<p class="auto-fadein" align="center" style="line-height: 175%;">
_"In all cases, the glucose-raising allele was associated with increased risk of T2D, yet fasting glucose effect sizes and T2D ORs were weakly correlated"_
</p>
<p class="auto-fadein">
@scott_large-scale_2012
</p>
## Why use a Joint Model? {.flexbox .vleft}
* To identify biomarker relevant to a disease
* To identify the effect of a treatment on a disease
(independently of the association between the disease and the biomarker)
<i>For example:</i>
* __Biomarker__: CD4 counts
* __Event__: death
## We can start with a Cox Model ... {.flexbox .vleft}
(Extended) Cox model:
$$\begin{align}
\lambda_i(t)=\lambda_0(t) \exp(\beta Y_i(t) + \alpha Z_i + \eta W_i)
\end{align}$$
Where:
* $\lambda_i(t)$ is the hazard function at time $t$ for individual $i$;
* $\lambda_0(t)$ is the unspecified baseline hazard function;
* $\alpha$ measures the effect of $Z_i$ on the hazard function;
* $\beta$ measures the association between the trajectory function $Y_i(t)$ and the hazard function.
## We can start with a Cox Model ... {.flexbox .vleft}
```{r, echo = TRUE, results = "hide", eval = FALSE}
coxph(Surv(Time, death) ~ drug, data = aids.id)
```
```{r}
fitCOX <- coxph(Surv(Time, death) ~ drug, data = aids.id, x = TRUE)
pCOX <- ggsurvplot(
fit = survfit(Surv(Time, death) ~ drug, data = aids.id),
conf.int = TRUE
)$plot +
theme_black(base_size = 14) +
scale_colour_viridis_d(name = NULL) +
scale_fill_viridis_d(name = NULL) +
theme(legend.position = c(1, 1), legend.justification = c(1.05, 1.05))
print(pCOX)
```
## We can start with a Cox Model ... {.flexbox .vleft}
```{r, echo = TRUE, results = "hide", eval = FALSE}
coxph(Surv(Time, death) ~ drug, data = aids.id)
```
```{r, results = 'markup'}
summary(coxph(Surv(Time, death) ~ drug, data = aids.id, x = TRUE))
```
## It works, but biomarkers ... {.flexbox .vleft}
1. are measured at determined time points ($t_{ij}$)
2. can have missing values over time
* => Imputation?
* $\Rightarrow$ Bias introduction
3. are measured with some degree of error
* $\Rightarrow$ Noise in the biomarker trajectory ($Y_i(t_{ij}) \neq X_i(t_{ij})$)
4. can be endogenous
* $\Rightarrow$ Trajectory can change when the event occurs
* $\Rightarrow$ Bias introduction
## Hopefully, the Mixed Model is there! {.flexbox .vleft}
(Generalised) linear mixed effect model:
$$Y_{i}(t_{ij})=X_{i}(t_{ij})+\epsilon_{i}(t_{ij})$$
where:
* $Y_{i}(t_{ij})$ is the observed value
* $X_{i}(t_{ij})$ is the true (unobserved) value of the longitudinal measurement at time $t_{ij}$ for individual $i$.
* $\epsilon_{i}(t_{ij})$ is a random error term, usually:
$$\epsilon_{i}(t_{ij})\sim \mathcal{N}(0,\sigma^2)$$
## Hopefully, the Mixed Model is there! {.flexbox .vleft}
```{r, echo = TRUE, results = "hide", eval = FALSE}
lme(sqrt(CD4) ~ obstime*drug - drug, random = ~ 1|patient, data = aids)
```
```{r}
fitLME <- lme(fixed = sqrt(CD4) ~ obstime*drug - drug, random = ~ 1 | patient, data = aids)
pLME <- ggplot() +
geom_line(
data = aids,
mapping = aes(x = obstime, y = sqrt(CD4), colour = drug, group = patient),
show.legend = FALSE
) +
geom_point(
data = aids %>%
filter(death==1) %>%
group_by(patient) %>%
filter(obstime==max(obstime)) %>%
ungroup(),
mapping = aes(x = Time, y = sqrt(CD4), fill = drug, group = patient),
shape = 23,
colour = "white",
size = 3,
show.legend = FALSE
) +
facet_grid(cols = vars(drug)) +
scale_colour_viridis_d() +
scale_fill_viridis_d()
print(pLME)
```
## Hopefully, the Mixed Model is there! {.flexbox .vleft}
```{r, echo = TRUE, results = "hide", eval = FALSE}
lme(sqrt(CD4) ~ obstime*drug - drug, random = ~ 1|patient, data = aids)
```
```{r, results = "markup"}
summary(lme(sqrt(CD4) ~ obstime*drug - drug, random = ~ 1 | patient, data = aids))
```
## Let's use a Joint Model {.flexbox .vleft}
```{r, echo = TRUE, results = "hide"}
fitCOX <- coxph(Surv(Time, death) ~ drug, data = aids.id, x = TRUE)
fitLME <- lme(sqrt(CD4) ~ obstime*drug - drug, random = ~ 1 | patient, data = aids)
### <b>
fitJOINT <- jointModel(fitLME, fitCOX, timeVar = "obstime", method = "piecewise-PH-aGH")
### </b>
```
```{r, results = "markup", include = FALSE, eval = FALSE}
out <- capture.output(summary(fitJOINT))[20:44]
cat(out, sep = "\n")
```
```{r, eval = FALSE, echo = TRUE}
#> Variance Components:
#> StdDev
#> (Intercept) 0.8793445
#> Residual 0.4093577
#>
#> Coefficients:
#> Longitudinal Process
#> Value Std.Err z-value p-value
#> (Intercept) 2.5100 0.0434 57.8778 <0.0001
### <b>
#> obstime -0.0362 0.0035 -10.3474 <0.0001
#> obstime:drugddI 0.0045 0.0049 0.9173 0.3590
### </b>
#>
#> Event Process
#> Value Std.Err z-value p-value
### <b>
#> drugddI 0.3458 0.1523 2.2715 0.0231
#> Assoct -1.0866 0.1184 -9.1786 <0.0001
### </b>
#> log(xi.1) -1.6560 0.2529 -6.5475
#> log(xi.*) ...... ..... ......
```
## What is a Joint Model? With a picture! {.flexbox .vleft}
```{r diagram_data, out.height = "432px", out.width = "768px"}
data_arrows <- tribble(
~x, ~y, ~xend, ~yend, ~step,
0.15, 1, 0.85, 1, 2,
0.20, 1, 0.80, 1, 3,
0.20, 1, 0.80, 1, 4,
0.20, 1, 0.80, 1, 5,
0.20, 1, 0.80, 1, 6,
0.20, 1, 0.80, 1, 7,
0.20, 1, 0.80, 1, 8,
1.20, 1, 1.85, 0.55, 4,
1.20, 1, 1.85, 0.55, 8,
1.15, 0, 1.85, 0.45, 5,
1.15, 0, 1.85, 0.45, 7,
1.15, 0, 1.85, 0.45, 8,
1, 0.1, 1, 0.9, 6,
1, 0.1, 1, 0.9, 7,
1, 0.1, 1, 0.9, 8
)
data_labels <- tribble(
~x, ~y, ~label, ~colour, ~step,
1, 1, "Y(t)", 1, 1,
2, 0.5, "S", 1, 1,
1, 0, "Z", 1, 1,
0, 1, "Y(t)", 1, 2,
1, 1, "X(t)", 1, 2,
2, 0.5, "T2D", 1, 2,
1, 0, "SNP", 1, 2,
0.5, 1.1, "epsilon", 2, 2,
0, 1, "FG[obs]", 1, 3,
1, 1, "FG[true]", 1, 3,
2, 0.5, "T2D", 1, 3,
1, 0, "SNP", 1, 3,
0.5, 1.1, "epsilon", 2, 3,
0, 1, "FG[obs]", 1, 4,
1, 1, "FG[true]", 1, 4,
2, 0.5, "T2D", 1, 4,
1, 0, "SNP", 1, 4,
0.5, 1.1, "epsilon", 2, 4,
1.5, 0.9, "beta", 2, 4,
0, 1, "FG[obs]", 1, 5,
1, 1, "FG[true]", 1, 5,
2, 0.5, "T2D", 1, 5,
1, 0, "SNP", 1, 5,
0.5, 1.1, "epsilon", 2, 5,
1.5, 0.10, "alpha", 2, 5,
0, 1, "FG[obs]", 1, 6,
1, 1, "FG[true]", 1, 6,
2, 0.5, "T2D", 1, 6,
1, 0, "SNP", 1, 6,
0.5, 1.1, "epsilon", 2, 6,
0.9, 0.5, "gamma", 2, 6,
0, 1, "FG[obs]", 1, 7,
1, 1, "FG[true]", 1, 7,
2, 0.5, "T2D", 1, 7,
1, 0, "SNP", 1, 7,
0.5, 1.1, "epsilon", 2, 7,
0.9, 0.5, "gamma", 2, 7,
1.5, 0.10, "alpha", 2, 7,
0, 1, "FG[obs]", 1, 8,
1, 1, "FG[true]", 1, 8,
2, 0.5, "T2D", 1, 8,
1, 0, "SNP", 1, 8,
0.5, 1.1, "epsilon", 2, 8,
1.5, 0.10, "alpha", 2, 8,
0.9, 0.5, "gamma", 2, 8,
1.5, 0.9, "beta", 2, 8
)
p_init <- ggplot() +
theme(
panel.grid = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
panel.border = element_blank(),
legend.position = "none"
)
p <- p_init +
geom_segment(
data = data_arrows %>% filter(step==1),
mapping = aes(x = x, xend = xend, y = y, yend = yend),
colour = "white",
arrow = arrow(length = unit(8, "point"), type = "closed"),
lineend = "round",
linejoin = "round"
) +
geom_text(
data = data_labels %>% filter(step==1),
mapping = aes(x = x, y = y, label = label, colour = factor(colour)),
size = 6,
parse = TRUE
) +
scale_x_continuous(expand = expand_scale(mult = 0.2)) +
scale_y_continuous(expand = expand_scale(mult = 0.2)) +
scale_colour_viridis_d() +
coord_cartesian(xlim = c(0, 2), ylim = c(0, 1))
print(p)
cat("\n")
```
```{r diagram_figs, out.height = "432px", out.width = "768px"}
for (istep in 2:8) {
cat("\n## What is a Joint Model? With a picture! {.flexbox .vcenter}\n")
cat("\n")
p <- p_init +
geom_segment(
data = data_arrows %>% filter(step==istep),
mapping = aes(x = x, xend = xend, y = y, yend = yend),
colour = "white",
arrow = arrow(length = unit(8, "point"), type = "closed"),
lineend = "round",
linejoin = "round"
) +
geom_text(
data = data_labels %>% filter(step==istep),
mapping = aes(x = x, y = y, label = label, colour = factor(colour)),
size = 6,
parse = TRUE
) +
scale_x_continuous(expand = expand_scale(mult = 0.2)) +
scale_y_continuous(expand = expand_scale(mult = 0.2)) +
scale_colour_viridis_d() +
coord_cartesian(xlim = c(0, 2), ylim = c(0, 1))
print(p)
cat("\n")
}
# p <- p +
# transition_states(
# states = step,
# transition_length = 0,
# state_length = 2,
# wrap = FALSE
# )
# animate(
# plot = p,
# nframes = 400,
# width = 800,
# height = 450,
# res = 120,
# bg = ggplot2::theme_get()$plot.background$colour,
# renderer = ffmpeg_renderer(options = list(pix_fmt = "yuv420p", "r" = 0.9))
# )
```
## What can we do with a Joint Model? {.flexbox .vleft}
Test simultaneously an effect on:
* a biomarker ($\gamma$);
* an event ($\alpha$);
* a biomarker and an event ($\beta\gamma+\alpha$).
## The best part? {.flexbox .vleft}
A gain in statistical power to detect those effects
* if $\beta\neq0$, to detect a joint effect of $Z$: $\beta\gamma+\alpha\neq0$
(from @chen_sample_2011);
* compared to the extended Cox model.
## What is a Joint Model? With equations! {.flexbox .vleft}
The standard (joint likelihood) formulation involves two components:
* a longitudinal component
* a time-to-event (survival) component.
With:
* $n$, the sample size;
* $i$, an individual ($i=1,\cdots,n$);
* $m_i$, the number of measurements on individual $i$;
* $t_{ij}$, a time points ($j=1,\cdots,m_i$).
## The longitudinal component {.flexbox .vleft}
(Generalised) linear mixed effect model:
$$Y_{i}(t_{ij})=X_{i}(t_{ij})+\epsilon_{i}(t_{ij})$$
$X_{ij}$ is the trajectory function, and could be defined:
$$\begin{gather}X_{i}(t_{ij})=\theta_{0i} + \theta_{1i}t_{ij} + \cdots + \theta_{pi}t_{ij}^p &, & \boldsymbol\theta_p \sim \mathcal{N}(\boldsymbol\mu_, \boldsymbol\Sigma)\end{gather}$$
For simplicity here, we assume linearity over time ($\theta_{0i}+\theta_{1i}t_{ij}$):
$$\begin{gather}Y_{i}(t_{ij})=\theta_{0i}+\theta_{1i}t_{ij}+\gamma Z_i+\delta W_i+\epsilon_{ij} &, & \boldsymbol{\theta} \sim \mathcal{N}_2 (\boldsymbol{\mu},\boldsymbol{\Sigma})\end{gather}$$
## The longitudinal component {.flexbox .vleft}
(Generalised) linear mixed effect model:
$$Y_{i}(t_{ij})=\theta_{0i}+\theta_{1i}t_{ij}+\gamma Z_i+\delta W_i+\epsilon_{ij}$$
With:
* $Y_{i}(t_{ij})$, the observed value;
* $X_{i}(t_{ij})$, the true (unobserved) value of the longitudinal measurement at time $t_{ij}$ for individual $i$;
* $\epsilon_{ij}$,a random error term, usually: $\epsilon_{ij}\sim \mathcal{N}(0,\sigma^2)$;
* $Z_i$, a vector denoting the genotype of individual $i$;
* $W_i$, a set of adjusting covariates.
## The time-to-event component {.flexbox .vleft}
(Extended) Cox model (proportional hazards):
$$\begin{align}
\lambda_i(t)&=\lim_{dt \to 0} \frac{P\{t\leq T_i<t+dt|T_i\geq t, \bar{Y_i}(t), Z_i, W_i\}}{dt}\\
&=\lambda_0(t) \exp\{\beta X_{i}(t) + \alpha Z_i + \eta W_i\}
\end{align}$$
With:
* $\bar{Y_i}(t)=\{Y_i(u),0 \leq u \leq t\}$, the history of the trajectory;
* $T_i$, the event time for individual $i$;
* $C_i$, the right censoring time (end of the follow-up);
* $\Delta_i$, an event indicator: $\begin{cases}
\Delta_i=0, & \text{if }\ T_i>C_i. \\
\Delta_i=1, & \text{if }\ T_i <= C_i.
\end{cases}$
## Hypothesis testing {}
<div class="centered">Null hypothesis: $\begin{cases}H_0&:& \theta=\theta_0\\H_1&:& \theta\neq\theta_0\end{cases}$</div>
* __Likelihood Ratio Test__
$$LRT=-2\{\ell(\hat{\theta}_0)-\ell(\hat{\theta})\}$$
* __Wald Test__
$$\begin{gather}
W=(\hat{\theta}-\theta_0)^\top \mathcal{I}(\hat{\theta})(\hat{\theta}-\theta_0)\\
\left(\text{Univariate: }(\hat{\theta}_j-\theta_{0j})/\widehat{\text{s.e.}}(\hat{\theta}_j)\right)
\end{gather}$$
* __Score Test__
$$U=S^\top(\hat{\theta}_0)\{\mathcal{I}(\hat{\theta}_0)\}^{-1}S(\hat{\theta}_0)$$
# Is the<br>Joint Model Approach<br>Worth It? | Let's find out with simulations! {.flexbox .vcenter}
## Estimators (& Computation time) {.flexbox .vleft}
* Are Joint Model estimators good?
* Bias, variance and RMSE (Root-Mean Square Error)
$$\begin{align}
\operatorname{MSE}(\hat\phi)&= \operatorname{Bias}(\hat\phi)^2 + \operatorname{Var}(\hat\phi)\\
\operatorname{RMSE}(\hat{\phi})&=\sqrt{\operatorname{MSE}(\hat\phi)}\\
&=\sqrt{E\{(\hat{\phi}-\phi)^2\}}
\end{align}$$
$$\phi=(\beta, \gamma, \alpha)$$
* Can we do a whole genome analysis...
... in a reasonable time frame?
## A more "naive" approach! {.flexbox .vleft}
What if, we split the job in two?
$\Rightarrow$ "Two-Step"? [@tsiatis_modeling_1995]
1. (Generalised) linear mixed effect model
$$\begin{align}
Y_{i}(t)&=X_i(t)+ \epsilon_{i}(t)\\
X^*_{i}(t)&=E\{X_{i}(t)|\bar{Y_i}(t), T_i\geq t\}
\end{align}$$
2. (Extended) Cox model (proportional hazards)
$$h_i(t)=h_0(t) \exp\{\beta X^*_{i}(t)\}$$
## Time to generate fake data! {.flexbox .vleft}
Let's keep it simple, i.e., without covariates:
* the trajectory: $Y_{i}(t)=\theta_{0i} + \theta_{1i}t + \gamma Z_i + \epsilon_{i}(t)$
* the event: $\lambda_i(t)=\lambda_0(t) \exp\{\beta X_{i}(t) + \alpha Z_i\}$
* the time of event, e.g., the exponential distribution [@austin_generating_2012]:
$$\begin{gather}
H_i(T_i)=\int_0^{T_i}\lambda_0(t) \exp(\beta X_i(t)+\alpha Z_i)dt , & \lambda_0(t)=\lambda\\
F_i(T_i)=1-exp(-H_i(T_i))=u , & u\sim\mathcal{U}(0, 1)
\end{gather}$$
$$T_i=\frac{1}{\beta\theta_{1i}}\log\left(1-\frac{\beta\theta_{1i}\times \log(1-u)}{\lambda \exp(\beta\theta_{0i}+(\beta\gamma+\alpha)Z_i)}\right)$$
## Set the parameters! {.flexbox .vcenter}
<div class="columns-2">
<div class="centered">
```{r scott2, out.height = "360px", out.width = "360px"}
include_graphics(path = "images/ng2385-F2.png")
```
<p>@scott_large-scale_2012</p>
</div>
<div class="centered">
```{r yaghootkar2, out.height = "360px", out.width = "360px"}
include_graphics(path = "images/Yaghootkar.png")
```
<p>@yaghootkar_recent_2013</p>
</div>
</div>
## Set the parameters! {.flexbox .vcenter}
```{r parameters_table}
settings.table <- data.frame(
matrix(NA, nrow = 9, ncol = 2, dimnames = list(NULL, c("Parameters", "Values")))
)
settings.table[, "Parameters"] <- c(
"Number of participants ($n$)",
"Number of measures ($m$)",
"Diabetes incidence rate ($d$)",
"Minor allele frequency ($f$)",
"Random effects ($\\theta$)",
"SNP effect on $Y_{ij}$ ($\\gamma$)",
"SNP effect on $T_i$ ($\\alpha$)",
"Association between $Y_{ij}$ and $T_i$ ($\\beta$)",
"Error term ($\\epsilon$)"
)
settings.table[, "Values"] <- c(
format(jm_data$rawsettings$n+1, big.mark = ","),
4,
signif(jm_data$rawsettings$d, digits = 3),
signif(jm_data$rawsettings$maf, digits = 3),
paste0(
"$\\sim\\mathcal{N}_2\\left (\\begin{bmatrix}",
format_scientific(jm_data$rawsettings$thetas[1]), "\\\\",
format_scientific(jm_data$rawsettings$thetas[2]),
"\\end{bmatrix} , \\begin{bmatrix} ",
format_scientific(jm_data$rawsettings$Epsilon_thetas[1, 1]), " & ",
format_scientific(jm_data$rawsettings$Epsilon_thetas[1, 2]), " \\\\ ",
format_scientific(jm_data$rawsettings$Epsilon_thetas[2, 1]), " & ",
format_scientific(jm_data$rawsettings$Epsilon_thetas[2, 2]), " \\end{bmatrix} \\right )$"
),
signif(jm_data$rawsettings$gamma, digits = 3),
paste0(
signif(jm_data$rawsettings$alpha[2], digits = 3),
" (OR=", signif(exp(jm_data$rawsettings$alpha[2]), digits = 3), ")"
),
signif(jm_data$rawsettings$beta, digits = 3),
paste0("$\\sim\\mathcal{N}(0,", signif(jm_data$rawsettings$sigma, digits = 3), "^2)$")
)
kable(
x = settings.table,
format.args = list(scientific = -1, digits = 3, big.mark = ","),
align = c("l", "c"),
escape = FALSE,
caption = paste0(
'Parameters and numerical values used for sensitivity analysis and simulations, based on results from ',
jm_data$bestEffect[, "snp"],
' within gene _',
jm_data$bestEffect[, "closestgene"],
'_ in the French cohort D.E.S.I.R.'
),
table.attr = 'style="font-size:75%; line-height:2; width:768px;" class="table-striped"'
)
```
## How does our fake data looks like? {.flexbox .vcenter}
```{r simulations_data, out.height = "432px", out.width = "768px"}
oneSimulation <- function(sampleSize, settings, seed) {
set.seed(seed)
settings$alpha["(Intercept)"] <- uniroot(
f = findAlphai,
interval = settings$alpha["(Intercept)"] * c(0.99, 1.01),
tol = 1e-3,
settings = settings,
extendInt = "yes"
)$root
smldta <- simulateJM(
n = sampleSize,
times = settings$times,
thetas = settings$thetas,
gamma = settings$gamma,
maf = settings$maf,
Epsilon_thetas = settings$Epsilon_thetas,
sigma = settings$sigma,
beta = settings$beta,
Epsilon_beta = settings$Epsilon_beta,
alpha = settings$alpha,
nu = settings$nu,
lambda = settings$lambda,
cens = settings$cens,
seed = seed
)
smldta[, "ID"] <- rep(seq(1, nrow(smldta) / length(settings$times)), each = length(settings$times))
smldta[["Ytrue"]] <- as.vector(smldta[["Ytrue"]])
smldta[["Ysurv"]] <- as.vector(smldta[["Ysurv"]])
smldta <- smldta %>%
group_by(ID) %>%
mutate(
group = any(Event==1),
event_time = ifelse(group&DiscreteEventTime==Time, DiscreteEventTime, NA),
Ytrue_event = ifelse(group&DiscreteEventTime==Time, rnorm(n = 1, mean = 8.5, sd = jm_data$rawsettings$sigma*2), Ytrue),
Yobs_event = rnorm(n = length(Ytrue_event), mean = Ytrue_event, sd = jm_data$rawsettings$sigma),
Ytrue_event = ifelse(DiscreteEventTime<=Time, NA, Ytrue_event),
Yobs_event = ifelse(DiscreteEventTime<Time, NA, Yobs_event)
) %>%
ungroup() %>%
mutate(
seed_id = paste(seed, ID, sep = "_"),
event_labels = ifelse(group, "Incident cases", "Controls") %>%
factor(levels = c("Controls", "Incident cases")),
sim_id = seed
)
return(smldta)
}
default_settings <- jm_data$rawsettings
default_settings$d <- 0.1
simulated_data <- mclapply(X = 1:50, mc.cores = 50, FUN = function(iseed) {
oneSimulation(sampleSize = 100, settings = default_settings, seed = 20181018+iseed)
}) %>%
bind_rows()
p <- simulated_data %>%
mutate(sim_id = as.character(sim_id)) %>%
ggplot() +
geom_line(
mapping = aes(x = Time, y = Yobs_event, colour = event_labels, group = factor(seed_id)),
show.legend = FALSE
) +
geom_point(
mapping = aes(x = event_time, y = Yobs_event, fill = event_labels, group = factor(seed_id)),
shape = 23,
colour = "white",
size = 3,
show.legend = FALSE
) +
facet_grid(cols = vars(event_labels)) +
scale_x_continuous(breaks = c(0, 3, 6, 9)) +
scale_colour_viridis_d() +
scale_fill_viridis_d() +
labs(y = "Yobs", title = "N=100; d=10%; Seed: {closest_state}") +
transition_states(states = sim_id, transition_length = 1, state_length = 1)
animate(
plot = p,
fps = 10,
width = 800*1.5,
height = 450*1.5,
res = 120,
bg = ggplot2::theme_get()$plot.background$colour,
renderer = gifski_renderer(
# file = "./images/simulations_data.gif"
)
)
```
## What could we expect? {.flexbox .vleft}
Let's do some power calculation (chen_sample_2011):
$$\begin{gather}
H_0:\ \beta\gamma+\alpha=0 \\
d=\frac{(z_{\tilde{\beta}}+z_{1-\tilde{\alpha}})^2}{f(1-f)(\beta\gamma+\alpha)^2} \\
z_{\tilde{\beta}}=\pm\sqrt{df(1-f)(\beta\gamma+\alpha)^2}+z_{1-\tilde{\alpha}}
\end{gather}$$
<div>With:</div>
<div class="columns-2">
* $d$, the incidence rate;
* $f$, the allele frequency;
* $\tilde{\alpha}$, the significance level;
* $\tilde{\beta}_{\tilde{\alpha}}$, statistical power at $\tilde{\alpha}$.
</div>
<div class="centered">
$\Rightarrow\tilde{\beta}_{\tilde{\alpha}}=46.56\%$ for _TCF7L2_ (rs17747324).
</div>
# Back to the Simulations! | Let's see some (animated) pictures! {.flexbox .vcenter}
```{r simulations_results, out.height = "432px", out.width = "768px"}
all_gif <- jm_data$simuDtaRMSE %>%
mutate(
group = map_chr(.x = p, .f = function(.p) {
switch(
EXPR = .p,
"L.SNP" = {"## $\\gamma$: Association between $Z_{i}$ and $X_{i}(t)$"},
"S.Assoct" = {"## $\\beta$: Association between $X_{i}(t)$ and $S_{i}$"},
"S.SNP" = {"## $\\alpha$: Association beteen the $Z_{i}$ and $S_{i}$"}
)
}) %>%
factor(
levels = c(
"## $\\beta$: Association between $X_{i}(t)$ and $S_{i}$",
"## $\\gamma$: Association between $Z_{i}$ and $X_{i}(t)$",
"## $\\alpha$: Association beteen the $Z_{i}$ and $S_{i}$"
)
)
) %>%
arrange(group) %>%
mutate(
model = map_chr(.x = model, .f = function(.model) {
c("Joint Model", "Two Step", "Linear Mixed Model", "Cox Model with\ntime varying covariate")[c("JointModel", "TwoStep", "MixedModel", "SurvivalModelTime")%in%.model]
}),
model = factor(
x = model,
levels = c("Joint Model", "Two Step", "Linear Mixed Model", "Cox Model with\ntime varying covariate")
)
) %>%
group_by(group) %>%
nest() %>%
mutate(
RMSE = map(.x = data, .f = function(.data) {
p <- ggplot(data = .data, aes(x = maf, y = RMSE, fill = model)) +
geom_bar(stat = "identity", position = "dodge") +
theme(
axis.text.x = element_text(angle = 60, hjust = 1, vjust = 1),
panel.spacing.x = unit(0, "in"),
panel.grid.minor = element_blank()
) +
labs(
title = "{closest_state}",
x = "Allele Frequency (f)",
y = switch(unique(.data[["p"]]),
"L.SNP" = {expression("RMSE" == sqrt(symbol(E)((hat(gamma) - gamma) ^ 2)))},
"S.Assoct" = {expression("RMSE" == sqrt(symbol(E)((hat(beta) - beta) ^ 2)))},
"S.SNP" = {expression("RMSE" == sqrt(symbol(E)((hat(alpha) - alpha) ^ 2)))}
),
caption = "Adapted from Canouil et al., 2018."
) +
theme(plot.caption = element_text(size = rel(0.5), hjust = 1)) +
scale_fill_viridis_d(name = NULL, drop = FALSE) +
facet_grid(rows = vars(d), cols = vars(measures))
if (unique(.data[["p"]])=="S.SNP") {
p <- p + scale_y_continuous(
expand = expand_scale(mult = c(0, 0.05)),
trans = "sqrt_zero",
breaks = c(0, 1, 2.5, 5, 10)
)
} else {
p <- p + scale_y_continuous(expand = expand_scale(mult = c(0, 0.05)))
}
p +
transition_states(
states = n,
transition_length = 4,
state_length = 10
)
})
) %>%
mutate(
bias = map(.x = data, .f = function(.data) {
p <- ggplot(data = .data, aes(x = maf, y = Bias, fill = model)) +
geom_bar(stat = "identity", position = "dodge") +
theme(
axis.text.x = element_text(angle = 60, hjust = 1, vjust = 1),
panel.spacing.x = unit(0, "in"),
panel.grid.minor = element_blank()
) +
labs(
title = "{closest_state}",
x = "Allele Frequency (f)",
y = switch(unique(.data[["p"]]),
"L.SNP" = {expression(Bias(hat(gamma)))},
"S.Assoct" = {expression(Bias(hat(beta)))},
"S.SNP" = {expression(Bias(hat(alpha)))}
),
caption = "Adapted from Canouil et al., 2018."
) +
theme(plot.caption = element_text(size = rel(0.5), hjust = 1)) +
scale_fill_viridis_d(name = NULL, drop = FALSE) +
facet_grid(rows = vars(d), cols = vars(measures))
if (unique(.data[["p"]])=="S.SNP") {
p <- p + scale_y_continuous(expand = expand_scale(mult = c(0.05, 0.05)), trans = "my", breaks = c(-1, 0, 1, 2.5, 5, 7.5))
} else {
p <- p + scale_y_continuous(expand = expand_scale(mult = c(0.05, 0.05)))
}
p +
transition_states(
states = n,
transition_length = 4,
state_length = 10
)
})
) %>%
mutate(
var = map(.x = data, .f = function(.data) {
p <- ggplot(data = .data, aes(x = maf, y = Var, fill = model)) +
geom_bar(stat = "identity", position = "dodge") +
theme(
axis.text.x = element_text(angle = 60, hjust = 1, vjust = 1),
panel.spacing.x = unit(0, "in"),
panel.grid.minor = element_blank()
) +
labs(
title = "{closest_state}",
x = "Allele Frequency (f)",
y = switch(unique(.data[["p"]]),
"L.SNP" = {expression(Var(hat(gamma)))},
"S.Assoct" = {expression(Var(hat(beta)))},
"S.SNP" = {expression(Var(hat(alpha)))}
),
caption = "Adapted from Canouil et al., 2018."
) +
theme(plot.caption = element_text(size = rel(0.5), hjust = 1)) +
scale_fill_viridis_d(name = NULL, drop = FALSE) +
facet_grid(rows = vars(d), cols = vars(measures))
if (unique(.data[["p"]])=="S.SNP") {
p <- p + scale_y_continuous(
expand = expand_scale(mult = c(0, 0.05)),
trans = "sqrt_zero",
breaks = c(0, 1, 10, 25, 50, 75)
)
} else {
p <- p + scale_y_continuous(expand = expand_scale(mult = c(0, 0.05)))
}