-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnnIntMed_Supplement.Rmd
206 lines (179 loc) · 7.88 KB
/
AnnIntMed_Supplement.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
---
title: "Development and validation of an EHR-based frailty index, Supplementary Materials"
author: 'Alex Bokov ^1,✉^, Sara Espinoza ^1^, Chandana Tripathy ^1^, and Kathleen R. Stevens ^1^'
css: "production.css"
documentclass: article
description: 'Manuscript'
clean: false
bibliography: efi_paper.bib
csl: harvard-cite-them-right.csl
always_allow_html: true
output:
bookdown::html_document2:
fig_caption: true
self_contained: true
number_sections: false
keep_md: true
clean: false
bookdown::word_document2:
reference_docx: efi_template.docx
fig_caption: true
self_contained: true
keep_md: true
number_sections: false
---
```{r load_deps, echo=FALSE, message=FALSE, warning=FALSE, results='hide'}
.projpackages <- c('GGally','pander','dplyr','ggplot2','data.table'
,'grid','gridExtra','gtable'
,'survival','broom','forcats'
#,'table1','english'
,'bookdown'
#,'DiagrammeR','DiagrammeRsvg','rsvg'
,'survminer');
.deps <- c( 'analysis.R' );
.debug <- 0;
message(paste0('\n\n working dir: ',getwd(),'\n\n'));
cat('\n\nAvailable Files:',list.files(),sep='\n','\n');
.junk<-capture.output(source(file.path('./scripts/global.R'),chdir=TRUE,echo=!1
,local=TRUE));
# Set some formatting options for this document
panderOptions('table.alignment.default','right');
panderOptions('table.alignment.rownames','right');
panderOptions('table.split.table',Inf);
panderOptions('p.wrap','');
panderOptions('p.copula',', and ');
panderOptions('graph.fontfamily','serif');
# theme_get() gives default theme
theme_set(theme_bw(base_family = 'serif',base_size=14) +
theme(strip.background = element_rect(fill=NA,color=NA)
,strip.text = element_text(size=15)));
knitr::opts_chunk$set(echo=.debug>0, warning=.debug>0, message=.debug>0);
options(digits=5); # default is 7
knitr::knit_hooks$set(inline = nb);
# knitr::knit_hooks$set(inline = function(x) {
# knitr:::format_sci(x, 'md')
# })
# detect current output format
.outfmt <- knitr::opts_knit$get('rmarkdown.pandoc.to');
if(is.null(.outfmt)){
.outfmt <- if(knitr::is_html_output()) 'html' else {
if(knitr::is_latex_output()) 'latex' else {
if(interactive()) 'html' else {
'unknown';
}}}};
message('.outfmt = ',.outfmt);
.currentscript <- current_scriptname('AnnIntMed_Supplement.Rmd');
.outcomenames <- c('vi_c_falls','vi_c_drugadverse','v157_unspcfd__ptnts_tf')
snip_outcomes <- rname(.outcomenames);
snip_todates <- dat03[,.(xx=max(start_date)),by=patient_num] %>%
with(range(xx)) %>% paste0(collapse=' and ');
snip_fromdates <- dat03[,.(xx=min(start_date)),by=patient_num] %>%
with(range(xx)) %>% paste0(collapse=' and ');
```
## Proportionality of adverse drug events.
```{r drugcloglog, fig.cap='Log-log Kaplan-Meier estimates versus time for adverse drug events'}
ggsurvplot(survfit(Surv(a_t0,a_t1,xx)~Frail,data=fitsval$vi_c_drugadverse$data)
,fun='cloglog',palette=c('#00BFC4','#F8766D'),xscale='d_m',xlab='log(Months)',font.family=theme_get()$text$family);
```
## Distribution of Predictors.
```{r lpcdf, fig.cap='Comparison of linear predictor distributions for the development and validation models. The development distributions are plotted as dashed lines and the validation, as solid lines. These are not Kaplan-Meier plots despite a visual similarity. These plots show the shape of the cumulative distribution of the linear predictors, to visualize the extent to which they diverge between the validation and the developmental models',fig.width=11,fig.asp=0.3 }
.lpcdf <- sapply(.outcomenames,function(ii) valresults[[ii]]$Frailty$ggcdf +
ggtitle(rnameshort(ii)) + theme(legend.position='none') + xlab('') +
ylab(''),simplify=F);
.lpcdfl <- gtable::gtable_filter(ggplotGrob(valresults[[1]]$Frailty$ggcdf)
,'guide-box');
arrangeGrob(grobs=.lpcdf,nrow=1
,left=text_grob('Cumulative Density',rot=90,vjust=1,family='serif')
,bottom=text_grob('Linear Predictor',just='bottom',family='serif')
) %>%
grid.arrange(.lpcdfl,widths=grid::unit.c(unit(1,'npc') - .lpcdfl$width
,.lpcdfl$width))
```
## Kaplan-Meier plots and Cox model results for development data
```{r kmpsi, fig.cap=NULL, message=FALSE,collapse='true',results='asis'}
panderOptions('knitr.auto.asis', FALSE);
with(fits$vi_c_falls,{
message(dispname);
.srv1 <- survfit(Surv(a_t0,a_t1,xx)~Frail,id=patient_num,data=data);
plotsurv01(.srv1,labs=c('Non-Frail','Frail'),title=dispname
,dat1=data) %>% print;
pander(cphunivar(models$Frailty,3,3),row.names=F);
risktable00(survfit(Surv(a_t0, a_t1, xx) ~ Frail,data,id = patient_num)) %>%
pander(row.names=F);
});
```
```{r kmpsicap, fig.cap='Falls',fig.height=0.1}
.oldmar <- par('mar'); par(mar=c(0,0,0,0));
plot(0,type='n',axes=F,xlab=NA,ylab=NA,cex=0.01);
par(mar=.oldmar);
```
```{r kminf, fig.cap=NULL, message=FALSE,collapse='true',results='asis'}
panderOptions('knitr.auto.asis', FALSE);
with(fits$vi_c_drugadverse,{
message(dispname);
.srv1 <- survfit(Surv(a_t0,a_t1,xx)~Frail,id=patient_num,data=data);
plotsurv01(.srv1,labs=c('Non-Frail','Frail'),title=dispname
,dat1=data) %>% print;
pander(cphunivar(models$Frailty,3,3),row.names=F);
risktable00(survfit(Surv(a_t0, a_t1, xx) ~ Frail,data,id = patient_num)) %>%
pander(row.names=F);
});
```
```{r kminfcap, fig.cap='Adverse drug reactions.',fig.height=0.1}
.oldmar <- par('mar'); par(mar=c(0,0,0,0));
plot(0,type='n',axes=F,xlab=NA,ylab=NA,cex=0.01);
par(mar=.oldmar);
```
```{r kmtra, fig.cap=NULL, message=FALSE,collapse='true',results='asis'}
panderOptions('knitr.auto.asis', FALSE);
with(fits$v157_unspcfd__ptnts_tf,{
message(dispname);
.srv1 <- survfit(Surv(a_t0,a_t1,xx)~Frail,id=patient_num,data=data);
plotsurv01(.srv1,labs=c('Non-Frail','Frail'),title=dispname
,dat1=data) %>% print;
pander(cphunivar(models$Frailty,3,3),row.names=F);
risktable00(survfit(Surv(a_t0, a_t1, xx) ~ Frail,data,id = patient_num)) %>%
pander(row.names=F);
});
```
```{r kmtracap, fig.cap='Heart failure.',fig.height=0.1}
.oldmar <- par('mar'); par(mar=c(0,0,0,0));
plot(0,type='n',axes=F,xlab=NA,ylab=NA,cex=0.01);
par(mar=.oldmar);
```
## Harrell's C and proportional hazard test for development data
```{r tb3}
panderOptions('knitr.auto.asis', TRUE);
subset(tb3,Outcome %in% .outcomenames & Predictor == 'Frailty') %>%
mutate(Outcome = rnameshort(Outcome)
,`Concordance (95% CI)`=paste0(nb(Concordance,2)
,' ('
,nb(Concordance-1.96*`SE Concordance`,2)
,', '
,nb(Concordance+1.96*`SE Concordance`,2)
,')')
,`PH: χ^2^~df=1~`=nb(`χ² (ZPH)`,2),`PH: P`=nb(`P (ZPH)`,3)
) %>%
select('Outcome','Concordance (95% CI)','PH: χ^2^~df=1~','PH: P') %>%
pander(caption="(\\#tab:tb3) Performance of EFI models.
Concordance shows Harrell's c-statistic for each model. The remaining two
columns are the χ^2^ statistic and p-value the proportional hazard test. A
low p-value indicates a violation of the proportionality assumption.",row.names=F);
```
## Crosswalk Tables for eFI
### ICD9 and ICD10
```{r icdefimap}
import('https://raw.githubusercontent.com/bokov/FreeFI/master/CUSTOM_EFI_CODES_I2B2.tsv') %>%
select(c('GROUP','DIAG','DEFICIT','NOTES')) %>%
pander(missing='',table.caption.prefix='S'
,caption='Crosswalk of ICD9 and ICD10 codes to functional deficits');
```
### Blood Pressure, BMI, and Labs
```{r labefimap}
import('https://raw.githubusercontent.com/bokov/FreeFI/master/CUSTOM_EFI_LABS_I2B2.tsv') %>%
pander(missing='',table.caption.prefix='S'
,caption='Crosswalk of labs and vitals to functional deficits');
```
---
date: '2021-08-08'
---