-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsurvival_bookdown.tex
653 lines (544 loc) · 27.2 KB
/
survival_bookdown.tex
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
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{book}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
pdftitle={dsSurvival: Privacy preserving survival models in DataSHIELD},
pdfauthor={Soumya Banerjee and Tom R P Bishop},
hidelinks,
pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\usepackage{longtable,booktabs}
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{5}
\usepackage{booktabs}
\usepackage[]{natbib}
\bibliographystyle{apalike}
\title{dsSurvival: Privacy preserving survival models in DataSHIELD}
\author{Soumya Banerjee and Tom R P Bishop}
\date{2022-06-16}
\begin{document}
\maketitle
{
\setcounter{tocdepth}{1}
\tableofcontents
}
This is a bookdown with executable code demonstrating how to use the dsSurvival package to create privacy preserving survival models in DataSHIELD. dsSurvival builds privacy preserving survival models.
\hypertarget{prerequisites}{%
\chapter{Prerequisites}\label{prerequisites}}
This is a bookdown with executable code demonstrating how to use the dsSurvival package to create privacy preserving survival models in DataSHIELD. dsSurvival builds privacy preserving survival models.
DataSHIELD is a platform for federated analysis of private data. DataSHIELD has a client-server architecture and this package has a client side and server side component.
The client side package is called dsSurvivalClient:
\url{https://github.com/neelsoumya/dsSurvivalClient}
The server side package is called dsSurvival:
\url{https://github.com/neelsoumya/dsSurvival}
Please install R. Then install R Studio
\url{https://www.rstudio.com/products/rstudio/download/preview/}
We assume that the reader is familiar with R and DataSHIELD.
We outline some of the other prerequisites that need to be installed below:
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{install.packages}\NormalTok{(}\StringTok{'devtools'}\NormalTok{)}
\KeywordTok{library}\NormalTok{(devtools)}
\NormalTok{devtools}\OperatorTok{::}\KeywordTok{install_github}\NormalTok{(}\StringTok{'neelsoumya/dsSurvivalClient'}\NormalTok{)}
\NormalTok{devtools}\OperatorTok{::}\KeywordTok{install_github}\NormalTok{(}\StringTok{'datashield/dsBaseClient@6.1.1'}\NormalTok{)}
\KeywordTok{install.packages}\NormalTok{(}\StringTok{'rmarkdown'}\NormalTok{)}
\KeywordTok{install.packages}\NormalTok{(}\StringTok{'knitr'}\NormalTok{)}
\KeywordTok{install.packages}\NormalTok{(}\StringTok{'tinytex'}\NormalTok{)}
\KeywordTok{install.packages}\NormalTok{(}\StringTok{'metafor'}\NormalTok{)}
\KeywordTok{install.packages}\NormalTok{(}\StringTok{'DSOpal'}\NormalTok{)}
\KeywordTok{install.packages}\NormalTok{(}\StringTok{'DSI'}\NormalTok{)}
\KeywordTok{install.packages}\NormalTok{(}\StringTok{'opalr'}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\hypertarget{intro}{%
\chapter{Introduction}\label{intro}}
This is a document that outlines a vignette for implementing privacy preserving survival models
and meta-analyzing hazard ratios in the DataSHIELD platform.
We used the \textbf{bookdown} package \citep{R-bookdown}, R Markdown and \textbf{knitr} \citep{xie2015} for this document. Our package \textbf{dsSurvival} \citep{Banerjeef}\citep{soumya_banerjee_2021_4917552}\citep{Banerjee2022} uses the \textbf{metafor} package for meta-analysis \citep{Viechtbauer2010}.
\hypertarget{survival-models}{%
\section{Survival models}\label{survival-models}}
Survival models are used extensively in healthcare. Previously building survival models in DataSHIELD involved building piecewise exponential regression models. This is an approximation and involves having to define appropriate time buckets. A lack of familiarity with this approach also makes people suspicious.
The scope of our package implementation is restricted to being study-level meta-analysis (SLMA) rather than full likelihood.
\hypertarget{computational-workflow}{%
\chapter{Computational workflow}\label{computational-workflow}}
The computational steps are outlined below.
The first step is connecting to the server and loading the survival data.
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{library}\NormalTok{(knitr)}
\KeywordTok{library}\NormalTok{(rmarkdown)}
\KeywordTok{library}\NormalTok{(tinytex)}
\KeywordTok{library}\NormalTok{(survival)}
\KeywordTok{library}\NormalTok{(metafor)}
\KeywordTok{library}\NormalTok{(ggplot2)}
\KeywordTok{library}\NormalTok{(dsSurvivalClient)}
\KeywordTok{require}\NormalTok{(}\StringTok{'DSI'}\NormalTok{)}
\KeywordTok{require}\NormalTok{(}\StringTok{'DSOpal'}\NormalTok{)}
\KeywordTok{require}\NormalTok{(}\StringTok{'dsBaseClient'}\NormalTok{)}
\NormalTok{builder <-}\StringTok{ }\NormalTok{DSI}\OperatorTok{::}\KeywordTok{newDSLoginBuilder}\NormalTok{()}
\NormalTok{builder}\OperatorTok{$}\KeywordTok{append}\NormalTok{(}\DataTypeTok{server=}\StringTok{"server1"}\NormalTok{, }\DataTypeTok{url=}\StringTok{"https://opal-sandbox.mrc-epid.cam.ac.uk"}\NormalTok{,}
\DataTypeTok{user=}\StringTok{"dsuser"}\NormalTok{, }\DataTypeTok{password=}\StringTok{"P@ssw0rd"}\NormalTok{, }
\DataTypeTok{table =} \StringTok{"SURVIVAL.EXPAND_NO_MISSING1"}\NormalTok{)}
\NormalTok{builder}\OperatorTok{$}\KeywordTok{append}\NormalTok{(}\DataTypeTok{server=}\StringTok{"server2"}\NormalTok{, }\DataTypeTok{url=}\StringTok{"https://opal-sandbox.mrc-epid.cam.ac.uk"}\NormalTok{,}
\DataTypeTok{user=}\StringTok{"dsuser"}\NormalTok{, }\DataTypeTok{password=}\StringTok{"P@ssw0rd"}\NormalTok{, }
\DataTypeTok{table =} \StringTok{"SURVIVAL.EXPAND_NO_MISSING2"}\NormalTok{)}
\NormalTok{builder}\OperatorTok{$}\KeywordTok{append}\NormalTok{(}\DataTypeTok{server=}\StringTok{"server3"}\NormalTok{, }\DataTypeTok{url=}\StringTok{"https://opal-sandbox.mrc-epid.cam.ac.uk"}\NormalTok{,}
\DataTypeTok{user=}\StringTok{"dsuser"}\NormalTok{, }\DataTypeTok{password=}\StringTok{"P@ssw0rd"}\NormalTok{, }
\DataTypeTok{table =} \StringTok{"SURVIVAL.EXPAND_NO_MISSING3"}\NormalTok{) }
\NormalTok{logindata <-}\StringTok{ }\NormalTok{builder}\OperatorTok{$}\KeywordTok{build}\NormalTok{()}
\NormalTok{connections <-}\StringTok{ }\NormalTok{DSI}\OperatorTok{::}\KeywordTok{datashield.login}\NormalTok{(}\DataTypeTok{logins =}\NormalTok{ logindata, }\DataTypeTok{assign =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{symbol =} \StringTok{"D"}\NormalTok{) }
\end{Highlighting}
\end{Shaded}
\hypertarget{creating-server-side-variables-for-survival-analysis}{%
\section{Creating server-side variables for survival analysis}\label{creating-server-side-variables-for-survival-analysis}}
We now outline the steps for analysing survival data.
We show this using synthetic data. There are 3 data sets that are held on the same server but can be considered to be on separate servers/sites.
The \textbf{cens} variable has the event information and the \textbf{survtime} variable has the time information. There is also age and gender information in the variables named \textbf{age} and \textbf{female}, respectively.
We will look at how age and gender affect survival time and then meta-analyze the hazard ratios from the survival model.
\begin{itemize}
\tightlist
\item
make sure that the outcome variable is numeric
\end{itemize}
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{ds.asNumeric}\NormalTok{(}\DataTypeTok{x.name =} \StringTok{"D$cens"}\NormalTok{,}
\DataTypeTok{newobj =} \StringTok{"EVENT"}\NormalTok{,}
\DataTypeTok{datasources =}\NormalTok{ connections)}
\KeywordTok{ds.asNumeric}\NormalTok{(}\DataTypeTok{x.name =} \StringTok{"D$survtime"}\NormalTok{,}
\DataTypeTok{newobj =} \StringTok{"SURVTIME"}\NormalTok{,}
\DataTypeTok{datasources =}\NormalTok{ connections)}
\end{Highlighting}
\end{Shaded}
\begin{itemize}
\tightlist
\item
convert time id variable to a factor
\end{itemize}
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{ds.asFactor}\NormalTok{(}\DataTypeTok{input.var.name =} \StringTok{"D$time.id"}\NormalTok{,}
\DataTypeTok{newobj =} \StringTok{"TID"}\NormalTok{,}
\DataTypeTok{datasources =}\NormalTok{ connections)}
\end{Highlighting}
\end{Shaded}
\begin{itemize}
\tightlist
\item
create in the server-side the log(survtime) variable
\end{itemize}
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{ds.log}\NormalTok{(}\DataTypeTok{x =} \StringTok{"D$survtime"}\NormalTok{,}
\DataTypeTok{newobj =} \StringTok{"log.surv"}\NormalTok{,}
\DataTypeTok{datasources =}\NormalTok{ connections)}
\end{Highlighting}
\end{Shaded}
\begin{itemize}
\tightlist
\item
create start time variable
\end{itemize}
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{ds.asNumeric}\NormalTok{(}\DataTypeTok{x.name =} \StringTok{"D$starttime"}\NormalTok{,}
\DataTypeTok{newobj =} \StringTok{"STARTTIME"}\NormalTok{,}
\DataTypeTok{datasources =}\NormalTok{ connections)}
\KeywordTok{ds.asNumeric}\NormalTok{(}\DataTypeTok{x.name =} \StringTok{"D$endtime"}\NormalTok{,}
\DataTypeTok{newobj =} \StringTok{"ENDTIME"}\NormalTok{,}
\DataTypeTok{datasources =}\NormalTok{ connections)}
\end{Highlighting}
\end{Shaded}
\hypertarget{create-survival-object-and-call-ds.coxph.slma}{%
\section{Create survival object and call ds.coxph.SLMA()}\label{create-survival-object-and-call-ds.coxph.slma}}
There are two options to generate the survival object. You can generate it separately or in line.
If a survival object is generated separately, it is stored on the server and can be used later in an assign function ( ds.coxphSLMAassign() ). The motivation for creating the model on the server side is inspired from the ds.glmassign functions. This allows the survival model to be stored on the server and can be used later for diagnostics.
\begin{itemize}
\tightlist
\item
use constructed Surv object in \emph{ds.coxph.SLMA()}
\end{itemize}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{dsSurvivalClient}\OperatorTok{::}\KeywordTok{ds.Surv}\NormalTok{(}\DataTypeTok{time=}\StringTok{'STARTTIME'}\NormalTok{, }\DataTypeTok{time2=}\StringTok{'ENDTIME'}\NormalTok{, }
\DataTypeTok{event =} \StringTok{'EVENT'}\NormalTok{, }\DataTypeTok{objectname=}\StringTok{'surv_object'}\NormalTok{,}
\DataTypeTok{type=}\StringTok{'counting'}\NormalTok{)}
\NormalTok{coxph_model_full <-}\StringTok{ }\NormalTok{dsSurvivalClient}\OperatorTok{::}\KeywordTok{ds.coxph.SLMA}\NormalTok{(}\DataTypeTok{formula =} \StringTok{'surv_object~D$age+D$female'}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{itemize}
\tightlist
\item
use direct inline call to \emph{survival::Surv()}
\end{itemize}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{dsSurvivalClient}\OperatorTok{::}\KeywordTok{ds.coxph.SLMA}\NormalTok{(}\DataTypeTok{formula =} \StringTok{'survival::Surv(time=SURVTIME,event=EVENT)~D$age+D$female'}\NormalTok{, }
\DataTypeTok{dataName =} \StringTok{'D'}\NormalTok{, }
\DataTypeTok{datasources =}\NormalTok{ connections)}
\end{Highlighting}
\end{Shaded}
\begin{itemize}
\tightlist
\item
call with \emph{survival::strata()}
\end{itemize}
The strata() option allows us to relax some of the proportional hazards assumptions. It allows fitting of a separate baseline hazard function within each strata.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{coxph_model_strata <-}\StringTok{ }\NormalTok{dsSurvivalClient}\OperatorTok{::}\KeywordTok{ds.coxph.SLMA}\NormalTok{(}\DataTypeTok{formula =} \StringTok{'surv_object~D$age + }
\StringTok{ survival::strata(D$female)'}\NormalTok{)}
\KeywordTok{summary}\NormalTok{(coxph_model_strata)}
\end{Highlighting}
\end{Shaded}
\hypertarget{diagnostics-for-cox-proportional-hazards-models}{%
\section{Diagnostics for Cox proportional hazards models}\label{diagnostics-for-cox-proportional-hazards-models}}
We have also created functions to test for the assumptions of
Cox proportional hazards models. This requires a call to the function ds.cox.zphSLMA. Before the call, a server-side object has to be created using the assign function ds.coxphSLMAassign().
All the function calls are shown below:
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{dsSurvivalClient}\OperatorTok{::}\KeywordTok{ds.coxphSLMAassign}\NormalTok{(}\DataTypeTok{formula =} \StringTok{'surv_object~D$age+D$female'}\NormalTok{,}
\DataTypeTok{objectname =} \StringTok{'coxph_serverside'}\NormalTok{)}
\NormalTok{dsSurvivalClient}\OperatorTok{::}\KeywordTok{ds.cox.zphSLMA}\NormalTok{(}\DataTypeTok{fit =} \StringTok{'coxph_serverside'}\NormalTok{)}
\NormalTok{dsSurvivalClient}\OperatorTok{::}\KeywordTok{ds.coxphSummary}\NormalTok{(}\DataTypeTok{x =} \StringTok{'coxph_serverside'}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
These diagnostics can allow an analyst to determine if the proportional hazards assumption in Cox proportional hazards models is satisfied. If the p-values shown below are greater than 0.05 for any co-variate, then the proportional hazards assumption is correct for that co-variate.
If the proportional hazards assumptions are violated (p-values less than 0.05), then the analyst will have to modify the model. Modifications may include introducing strata or using time-dependent covariates. Please see the links below for more information on this:
\begin{itemize}
\item
\url{https://stats.stackexchange.com/questions/317336/interpreting-r-coxph-cox-zph}
\item
\url{https://stats.stackexchange.com/questions/144923/extended-cox-model-and-cox-zph/238964\#238964}
\end{itemize}
A diagnostic summary is shown below.
\begin{verbatim}
## surv_object~D$age+D$female
\end{verbatim}
\begin{verbatim}
## NULL
\end{verbatim}
\begin{verbatim}
## $server1
## chisq df p
## D$age 1.022 1 0.31
## D$female 0.364 1 0.55
## GLOBAL 1.239 2 0.54
##
## $server2
## chisq df p
## D$age 2.26 1 0.13
## D$female 1.96 1 0.16
## GLOBAL 3.68 2 0.16
##
## $server3
## chisq df p
## D$age 15.27 1 9.3e-05
## D$female 8.04 1 0.0046
## GLOBAL 23.31 2 8.7e-06
\end{verbatim}
\begin{verbatim}
## $server1
## Call:
## survival::coxph(formula = formula, data = dataTable, weights = weights,
## ties = ties, singular.ok = singular.ok, model = model, x = x,
## y = y)
##
## n= 2060, number of events= 426
##
## coef exp(coef) se(coef) z Pr(>|z|)
## D$age 0.041609 1.042487 0.003498 11.894 < 2e-16 ***
## D$female1 -0.660002 0.516850 0.099481 -6.634 3.26e-11 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## exp(coef) exp(-coef) lower .95 upper .95
## D$age 1.0425 0.9592 1.0354 1.0497
## D$female1 0.5169 1.9348 0.4253 0.6281
##
## Concordance= 0.676 (se = 0.014 )
## Likelihood ratio test= 170.7 on 2 df, p=<2e-16
## Wald test = 168.2 on 2 df, p=<2e-16
## Score (logrank) test = 166.3 on 2 df, p=<2e-16
##
##
## $server2
## Call:
## survival::coxph(formula = formula, data = dataTable, weights = weights,
## ties = ties, singular.ok = singular.ok, model = model, x = x,
## y = y)
##
## n= 1640, number of events= 300
##
## coef exp(coef) se(coef) z Pr(>|z|)
## D$age 0.04067 1.04151 0.00416 9.776 < 2e-16 ***
## D$female1 -0.62756 0.53389 0.11767 -5.333 9.66e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## exp(coef) exp(-coef) lower .95 upper .95
## D$age 1.0415 0.9601 1.0331 1.0500
## D$female1 0.5339 1.8730 0.4239 0.6724
##
## Concordance= 0.674 (se = 0.017 )
## Likelihood ratio test= 117.8 on 2 df, p=<2e-16
## Wald test = 115.2 on 2 df, p=<2e-16
## Score (logrank) test = 116.4 on 2 df, p=<2e-16
##
##
## $server3
## Call:
## survival::coxph(formula = formula, data = dataTable, weights = weights,
## ties = ties, singular.ok = singular.ok, model = model, x = x,
## y = y)
##
## n= 2688, number of events= 578
##
## coef exp(coef) se(coef) z Pr(>|z|)
## D$age 0.042145 1.043045 0.003086 13.655 < 2e-16 ***
## D$female1 -0.599238 0.549230 0.084305 -7.108 1.18e-12 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## exp(coef) exp(-coef) lower .95 upper .95
## D$age 1.0430 0.9587 1.0368 1.0494
## D$female1 0.5492 1.8207 0.4656 0.6479
##
## Concordance= 0.699 (se = 0.011 )
## Likelihood ratio test= 227.9 on 2 df, p=<2e-16
## Wald test = 228.4 on 2 df, p=<2e-16
## Score (logrank) test = 229.4 on 2 df, p=<2e-16
\end{verbatim}
\hypertarget{summary-of-survival-objects}{%
\section{Summary of survival objects}\label{summary-of-survival-objects}}
We can also summarize a server-side object of type \emph{survival::Surv()}
using a call to \emph{ds.coxphSummary()}. This will provide a non-disclosive
summary of the server-side object. The server-side survival object can be created using ds.coxphSLMAassign().
An example call is shown below:
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{dsSurvivalClient}\OperatorTok{::}\KeywordTok{ds.coxphSummary}\NormalTok{(}\DataTypeTok{x =} \StringTok{'coxph_serverside'}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\hypertarget{meta-analyze-hazard-ratios}{%
\section{Meta-analyze hazard ratios}\label{meta-analyze-hazard-ratios}}
We now outline how the hazard ratios from the survival models are meta-analyzed.
We use the \emph{metafor} package for meta-analysis. We show the summary of an
example meta-analysis and a forest plot below. The forest plot shows a basic
example of meta-analyzed hazard ratios from a survival model (analyzed in dsSurvivalClient).
The log-hazard ratios and their standard errors from each study can be
found after running \emph{ds.coxphSLMA()}
The hazard ratios can then be meta-analyzed by running the commands shown below.
These commands get the hazard ratios correspondng to age in the survival model.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{input_logHR =}\StringTok{ }\KeywordTok{c}\NormalTok{(coxph_model_full}\OperatorTok{$}\NormalTok{server1}\OperatorTok{$}\NormalTok{coefficients[}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{], }
\NormalTok{ coxph_model_full}\OperatorTok{$}\NormalTok{server2}\OperatorTok{$}\NormalTok{coefficients[}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{], }
\NormalTok{ coxph_model_full}\OperatorTok{$}\NormalTok{server3}\OperatorTok{$}\NormalTok{coefficients[}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{])}
\NormalTok{input_se =}\StringTok{ }\KeywordTok{c}\NormalTok{(coxph_model_full}\OperatorTok{$}\NormalTok{server1}\OperatorTok{$}\NormalTok{coefficients[}\DecValTok{1}\NormalTok{,}\DecValTok{3}\NormalTok{], }
\NormalTok{ coxph_model_full}\OperatorTok{$}\NormalTok{server2}\OperatorTok{$}\NormalTok{coefficients[}\DecValTok{1}\NormalTok{,}\DecValTok{3}\NormalTok{], }
\NormalTok{ coxph_model_full}\OperatorTok{$}\NormalTok{server3}\OperatorTok{$}\NormalTok{coefficients[}\DecValTok{1}\NormalTok{,}\DecValTok{3}\NormalTok{])}
\NormalTok{meta_model <-}\StringTok{ }\NormalTok{metafor}\OperatorTok{::}\KeywordTok{rma}\NormalTok{(input_logHR, }\DataTypeTok{sei =}\NormalTok{ input_se, }\DataTypeTok{method =} \StringTok{'REML'}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
A summary of this meta-analyzed model is shown below.
\begin{verbatim}
##
## Random-Effects Model (k = 3; tau^2 estimator: REML)
##
## logLik deviance AIC BIC AICc
## 9.3824 -18.7648 -14.7648 -17.3785 -2.7648
##
## tau^2 (estimated amount of total heterogeneity): 0 (SE = 0.0000)
## tau (square root of estimated tau^2 value): 0
## I^2 (total heterogeneity / total variability): 0.00%
## H^2 (total variability / sampling variability): 1.00
##
## Test for Heterogeneity:
## Q(df = 2) = 0.0880, p-val = 0.9569
##
## Model Results:
##
## estimate se zval pval ci.lb ci.ub
## 1.0425 0.0020 515.4456 <.0001 1.0385 1.0465 ***
##
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
\end{verbatim}
We now show a forest plot with the meta-analyzed hazard ratios. The hazard ratios come
from the dsSurvivalClient function \emph{ds.coxphSLMA()}. The plot shows the coefficients for age in the survival model.
The command is shown below.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{metafor}\OperatorTok{::}\KeywordTok{forest.rma}\NormalTok{(}\DataTypeTok{x =}\NormalTok{ meta_model, }\DataTypeTok{digits =} \DecValTok{4}\NormalTok{) }
\end{Highlighting}
\end{Shaded}
\begin{figure}
\centering
\includegraphics{survival_bookdown_files/figure-latex/unnamed-chunk-21-1.pdf}
\caption{\label{fig:unnamed-chunk-21}Example forest plot of meta-analyzed hazard ratios.}
\end{figure}
\hypertarget{plotting-of-privacy-preserving-survival-curves}{%
\section{Plotting of privacy-preserving survival curves}\label{plotting-of-privacy-preserving-survival-curves}}
We also plot privacy preserving survival curves.
\begin{verbatim}
dsSurvivalClient::ds.survfit(formula='surv_object~1', objectname='survfit_object')
dsSurvivalClient::ds.plotsurvfit(formula = 'survfit_object')
\end{verbatim}
\begin{verbatim}
## NULL
\end{verbatim}
\begin{figure}
\centering
\includegraphics{survival_bookdown_files/figure-latex/unnamed-chunk-23-1.pdf}
\caption{\label{fig:unnamed-chunk-23}Privacy preserving survival curves.}
\end{figure}
\begin{verbatim}
## $server1
## Call: survfit(formula = formula)
##
## records n events median 0.95LCL 0.95UCL
## 2060.00 886.00 426.00 5.24 3.13 6.84
##
## $server2
## Call: survfit(formula = formula)
##
## records n events median 0.95LCL 0.95UCL
## 1640.00 659.00 300.00 6.56 4.57 8.45
##
## $server3
## Call: survfit(formula = formula)
##
## records n events median 0.95LCL 0.95UCL
## 2688.00 1167.00 578.00 3.86 2.59 6.15
\end{verbatim}
Finally, once you have finished your analysis, you can disconnect from the server(s) using the following command:
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{DSI}\OperatorTok{::}\KeywordTok{datashield.logout}\NormalTok{(}\DataTypeTok{conns =}\NormalTok{ connections)}
\end{Highlighting}
\end{Shaded}
\newpage
\begin{itemize}
\item
\url{https://github.com/datashield}
\item
\url{http://www.metafor-project.org}
\item
\url{https://github.com/neelsoumya/dsSurvival}
\item
\url{https://github.com/neelsoumya/dsSurvivalClient}
\end{itemize}
\hypertarget{summary}{%
\chapter{Summary}\label{summary}}
This bookdown shows how to build privacy preserving survival models using dsSurvival in DataSHIELD. You can read more at:
\begin{itemize}
\item
\url{https://github.com/neelsoumya/dsSurvivalClient}
\item
\url{https://github.com/neelsoumya/dsSurvival}
\item
\url{https://neelsoumya.github.io/dsSurvival_bookdown/}
\item
\url{https://github.com/datashield}
\end{itemize}
\bibliography{book.bib,packages.bib}
\end{document}