class: center, middle, inverse, title-slide #
pammtools
Survival Analysis with Generalized Additive Mixed Models ## R Medicine 2020
###
Andreas Bender (
@adibender
)
,
Fabian Scheipl, Philipp Kopper ###
Department of Statistics, LMU Munich --- layout: true <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/styles/github.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <div class="my-footer"><span><i class="fa fa-twitter">@adibender</i>                            </span></div> ??? `$$\usepackage{amsmath,amssymb,bm} \newcommand{\ra}{\rightarrow} \newcommand{\bs}[1]{\boldsymbol{#1}} \newcommand{\tn}[1]{\textnormal{#1}} \newcommand{\mbf}[1]{\mathbf{#1}} \newcommand{\E}{\mathbb{E}} \newcommand{\bfx}{\mathbf{x}} \newcommand{\bfX}{\mathbf{X}} \newcommand{\bfB}{\mathbf{B}} \newcommand{\bff}{\mathbf{f}} \newcommand{\bsbeta}{\boldsymbol{\beta}}$$` --- .font150[ **Time-to-event Analysis** (Survival Analysis) requires special methods because - outcome can not always be fully observed (**censoring**, **truncation**) - covariate values can change over time (**time-varying covariates**) - covariate effects can change over time (**time-varying effects**) - competing events prevent observation of the event of interest (**competing risks**) - observation units transition between different states (**recurrent events**, **multi-state models**) ] --- .font150[ Hitorically Survival Analysis dominated by Cox type models Many **Survival Models** can be represented **as Poisson Regression** (on transformed data) - Piece-wise Exponential Model (PEM; estimation based on GLM) <br> e.g., <a name=cite-laird_covariance_1981></a><a name=cite-friedman_piecewise_1982></a>[Laird and Olivier (1981)](http://www.jstor.org/stable/2287816); [Friedman (1982)](http://www.jstor.org/stable/2240502) - Piece-wise exponential Additive Mixed Model (PAMM; estimation based on GAMM) <br> e.g., <a name=cite-cai_mixed_2002></a><a name=cite-bender_generalized_2018></a>[Cai, Hyndman, and Wand (2002)](http://dx.doi.org/10.1198/106186002862); [Bender, Groll, and Scheipl (2018)](https://doi.org/10.1177/1471082X17748083) ] -- .font150[ `\(\ra\)` Use any method/R package for Survival Analysis that supports optimization of Poisson Likelihood (e.g., GAMMs via **`mgcv`**; <a name=cite-wood_generalized_2017></a>[Wood (2017)](#bib-wood_generalized_2017)) ] --- .center[ <img src="img/pem-framework.svg", width = "900px"> ] --- layout:false class: inverse, middle, center .font200[Survival Analysis as Poisson Regression] <html> <div style='float:left'></div><hr color='#005500' size=1px width=1000px> </html> --- layout: true <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/styles/github.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <div class="my-footer"><span><i class="fa fa-twitter">@adibender</i>                            </span></div> --- <div class="row"> <div class = "column", align = "center"> .font150[Data in "standard" time-to-event format] <br> </div> <div class = "column", align = "center"> .font150[Data in PED format] <br> </div> </div> <div class = "row" align = "middle"> <div class = "column", align = "middle"> .middle[ <img src="img/tab-standard.svg", width = "400px" align="middle"><br> .font150[ `\(\ra\)` transform to PED using intervals cut points `\(0, 1, 1.5\)` and `\(3\)` ] ] </div> <div class = "column" align ="middle"> <img src="img/tab-ped.svg", width = "500px" align="middle" > </div> </div> --- count: false <div class="row"> <div class = "column", align = "center"> .font150[Data in "standard" time-to-event format] <br> </div> <div class = "column", align = "center"> .font150[Data in PED format] <br> </div> </div> <div class = "row" align = "middle"> <div class = "column", align = "middle"> .middle[ <img src="img/tab-standard.svg", width = "400px" align="middle"><br> .font150[ `\(\ra\)` transform to PED using intervals cut points `\(0, 1, 1.5\)` and `\(3\)` ] ] </div> <div class = "column" align ="middle"> <img src="img/tab-ped1.svg", width = "500px" align="middle" > </div> </div> --- count: false <div class="row"> <div class = "column", align = "center"> .font150[Data in "standard" time-to-event format] <br> </div> <div class = "column", align = "center"> .font150[Data in PED format] <br> </div> </div> <div class = "row" align = "middle"> <div class = "column", align = "middle"> .middle[ <img src="img/tab-standard.svg", width = "400px" align="middle"><br> .font150[ `\(\ra\)` transform to PED using intervals cut points `\(0, 1, 1.5\)` and `\(3\)` ] ] </div> <div class = "column" align ="middle"> <img src="img/tab-ped2.svg", width = "500px" align="middle" > </div> </div> --- count: false <div class="row"> <div class = "column", align = "center"> .font150[Data in "standard" time-to-event format] <br> </div> <div class = "column", align = "center"> .font150[Data in PED format] <br> </div> </div> <div class = "row" align = "middle"> <div class = "column", align = "middle"> .middle[ <img src="img/tab-standard.svg", width = "400px" align="middle"><br> .font150[ `\(\ra\)` transform to PED using intervals cut points `\(0, 1, 1.5\)` and `\(3\)` ] ] </div> <div class = "column" align ="middle"> <img src="img/tab-ped3.svg", width = "500px" align="middle" > </div> </div> --- count: false <div class="row"> <div class = "column", align = "center"> .font150[Data in "standard" time-to-event format] <br> </div> <div class = "column", align = "center"> .font150[Data in PED format] <br> </div> </div> <div class = "row" align = "middle"> <div class = "column", align = "middle"> .middle[ <img src="img/tab-standard.svg", width = "400px" align="middle"><br> .font150[ `\(\ra\)` transform to PED using intervals cut points `\(0, 1, 1.5\)` and `\(3\)` ] ] </div> <div class = "column" align ="middle"> <img src="img/tab-ped4.svg", width = "500px" align="middle" > </div> </div> --- layout:false class: inverse, middle, center .font200[The **`pammtools`** package] <html> <div style='float:left'></div> <hr color='#005500' size=1px width=1000px> </html> --- layout: true <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/styles/github.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <div class="my-footer"><span><i class="fa fa-twitter">@adibender</i>                            </span></div> --- .font150[ **`pammtools`** facilitates - data transformation (`as_ped`): + right-censoring + competing risks - post-processing: + prediction (`add_hazard`, `add_surv_prob`, `add_cif`), + model evaluation (integrated brier score via **`pec`**) - convenience functions ] --- ```r library(pammtools) data("tumor") ``` | days| status| age|sex |complications | |----:|------:|---:|:------|:-------------| | 311| 1| 65|male |no | | 469| 0| 82|female |no | | 1257| 1| 66|female |no | | 1| 1| 96|female |yes | | 13| 1| 72|male |yes | | 1542| 0| 29|male |yes | --- ### Data Transformation ```r ped <- tumor %>% as_ped(Surv(days, status) ~ .) ``` | id| tstart| tend|interval | offset| ped_status| age|sex |complications | |---:|------:|----:|:--------|---------:|----------:|---:|:------|:-------------| | 167| 0| 1|(0,1] | 0.0000000| 0| 64|male |yes | | 167| 1| 2|(1,2] | 0.0000000| 0| 64|male |yes | | 167| 2| 3|(2,3] | 0.0000000| 0| 64|male |yes | | 167| 3| 5|(3,5] | 0.6931472| 0| 64|male |yes | | 167| 5| 6|(5,6] | 0.0000000| 0| 64|male |yes | | 167| 6| 7|(6,7] | 0.0000000| 0| 64|male |yes | | 167| 7| 8|(7,8] | 0.0000000| 1| 64|male |yes | | 397| 0| 1|(0,1] | 0.0000000| 0| 68|female |yes | | 397| 1| 2|(1,2] | 0.0000000| 0| 68|female |yes | | 397| 2| 3|(2,3] | 0.0000000| 1| 68|female |yes | --- ### Propportional Hazards Model ```r pam1 <- mgcv::gam( formula = ped_status ~ s(tend) + sex + complications + s(age), data = ped, family = poisson(), offset = offset) summary(pam1) ## Parametric coefficients: ## Estimate Std. Error z value Pr(>|z|) ## (Intercept) -7.86165 0.08396 -93.632 < 2e-16 *** ## sexfemale 0.12095 0.10604 1.141 0.254 ## complicationsyes 0.68619 0.10695 6.416 1.4e-10 *** ## Approximate significance of smooth terms: ## edf Ref.df Chi.sq p-value ## s(tend) 3.794 4.717 19.83 0.00116 ** ## s(age) 4.903 5.920 28.56 8.04e-05 *** ... ``` --- ### Hazard ```r hazard_df <- ped %>% make_newdata(tend = unique(tend), complications = unique(complications)) %>% add_hazard(pam1) # age fixed at mean, sex at modus value ``` |interval | tend|complications | hazard| ci_lower| ci_upper| |:--------|----:|:-------------|---------:|---------:|---------:| |(0,1] | 1|no | 0.0005227| 0.0003787| 0.0007215| |(1,2] | 2|no | 0.0005219| 0.0003783| 0.0007198| |(2,3] | 3|no | 0.0005210| 0.0003780| 0.0007181| |(0,1] | 1|yes | 0.0010381| 0.0007420| 0.0014524| |(1,2] | 2|yes | 0.0010365| 0.0007414| 0.0014491| |(2,3] | 3|yes | 0.0010348| 0.0007407| 0.0014458| --- ### Survival Porbability ```r surv_prob <- ped %>% make_newdata(tend = unique(tend), complications = unique(complications)) %>% group_by(complications) %>% # important !! add_surv_prob(pam1) ``` <img src="rmed2020-pammtools_files/figure-html/unnamed-chunk-10-1.png" width="500px" height="350px" style="display: block; margin: auto;" /> --- ### Stratified Model ```r pam2 <- pamm( formula = ped_status ~ s(tend, by = complications) + sex + s(age), data = ped) summary(pam2) ## Parametric coefficients: ## Estimate Std. Error z value Pr(>|z|) ## (Intercept) -7.78558 0.07921 -98.288 <2e-16 *** ## sexfemale 0.15409 0.10584 1.456 0.145 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## ## Approximate significance of smooth terms: ## edf Ref.df Chi.sq p-value ## s(tend):complicationsno 6.102 7.279 8.717 0.293 ## s(tend):complicationsyes 6.096 7.224 126.152 < 2e-16 *** ## s(age) 1.051 1.101 23.819 1.6e-06 *** ... ``` --- ### Stratified Model (Hazard) ```r gg_slice(ped, pam2, term = "tend", tend = seq(0,1000, by = 10), complications = unique(complications)) ``` <img src="rmed2020-pammtools_files/figure-html/unnamed-chunk-13-1.png" width="400px" style="display: block; margin: auto;" /> --- background-image: url(img/screenshot-hp.png) background-size: contain https://adibender.github.io/pammtools/index.html --- layout: false ## References <a name=bib-bender_generalized_2018></a>[Bender, A. et al.](#cite-bender_generalized_2018) (2018). "A generalized additive model approach to time-to-event analysis". En. In: _Statistical Modelling_ 18.3-4, pp. 299-321. ISSN: 1471-082X. DOI: [10.1177/1471082X17748083](https://doi.org/10.1177%2F1471082X17748083). <a name=bib-bender_general_2020></a>[Bender, A. et al.](#cite-bender_general_2020) (2020). "A General Machine Learning Framework for Survival Analysis". In: _arXiv:2006.15442 [cs, stat]_. arXiv: [2006.15442](https://arxiv.org/abs/2006.15442). <a name=bib-cai_mixed_2002></a>[Cai, T. et al.](#cite-cai_mixed_2002) (2002). "Mixed Model-Based Hazard Estimation". In: _Journal of Computational and Graphical Statistics_ 11.4, pp. 784-798. ISSN: 1061-8600. DOI: [10.1198/106186002862](https://doi.org/10.1198%2F106186002862). URL: [http://dx.doi.org/10.1198/106186002862](http://dx.doi.org/10.1198/106186002862) (visited on Jan. 07, 2015). <a name=bib-friedman_piecewise_1982></a>[Friedman, M.](#cite-friedman_piecewise_1982) (1982). "Piecewise Exponential Models for Survival Data with Covariates". In: _The Annals of Statistics_ 10.1, pp. 101-113. ISSN: 00905364. URL: [http://www.jstor.org/stable/2240502](http://www.jstor.org/stable/2240502). <a name=bib-laird_covariance_1981></a>[Laird, N. et al.](#cite-laird_covariance_1981) (1981). "Covariance Analysis of Censored Survival Data Using Log-Linear Analysis Techniques". In: _Journal of the American Statistical Association_ 76.374, pp. 231-240. DOI: [10.2307/2287816](https://doi.org/10.2307%2F2287816). URL: [http://www.jstor.org/stable/2287816](http://www.jstor.org/stable/2287816). <a name=bib-wood_generalized_2017></a>[Wood, S. N.](#cite-wood_generalized_2017) (2017). _Generalized Additive Models: An Introduction with R_. Englisch. 2 Rev ed.. Boca Raton: Chapman & Hall/Crc Texts in Statistical Science. ISBN: 978-1-4987-2833-1.