-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunited_old_models.R
194 lines (168 loc) · 10.7 KB
/
united_old_models.R
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
## UNITED_OLD_MODELS -------------------------------------------------------------------
# load libraries ---------------------------------------------------------------------------------
library(tidyverse)
library(writexl)
## load functions needed for generating data ------------------------------------
source("data/create_data.R")
#load UNITED data ---------------------------------------------------------------------------------
## 3 genes ----------------------------------------------------------------------------------------------------
## Load model predictions
predictions_dataset.UNITED_type1_old <- readRDS("model_predictions/predictions_dataset.UNITED_type1_old.rds")
predictions_dataset.UNITED_type2_old <- readRDS("model_predictions/predictions_dataset.UNITED_type2_old.rds")
##load cohort data
dataset.UNITED_type1_old <- create_data(dataset = "united t1d") %>%
## if MODY testing missing, change to 0
mutate(M = ifelse(is.na(M), 0, M))
dataset.UNITED_type2_old <- create_data(dataset = "united t2d")
##merge cohort and predictions data
UNITED_type1_old <- cbind(dataset.UNITED_type1_old,predictions_dataset.UNITED_type1_old)
UNITED_type2_old <- cbind(dataset.UNITED_type2_old,predictions_dataset.UNITED_type2_old)
## all genes -----------------------------------------------------------------------------------------------
## Load model predictions
predictions_dataset.UNITED_type1_all_genes_old <- readRDS("model_predictions/predictions_dataset.UNITED_type1_all_genes_old.rds")
predictions_dataset.UNITED_type2_all_genes_old <- readRDS("model_predictions/predictions_dataset.UNITED_type2_all_genes_old.rds")
## load cohort data
dataset.UNITED_type1_all_genes <- create_data(dataset = "united t1d", commonmody = FALSE) %>%
## if MODY testing missing, change to 0
mutate(M = ifelse(is.na(M), 0, M))
dataset.UNITED_type2_all_genes <- create_data(dataset = "united t2d", commonmody = FALSE)
##merge cohort and predictions data
UNITED_type1_all_genes_old <- cbind(dataset.UNITED_type1_all_genes,predictions_dataset.UNITED_type1_all_genes_old)
UNITED_type2_all_genes_old <- cbind(dataset.UNITED_type2_all_genes,predictions_dataset.UNITED_type2_all_genes_old)
##Thresholds -----------------------------------------------------------------------------
### 3 genes --------------------------------------------------------------------------------------
#### T1D ------------------------------------------------------------------------------------
##### 5%
UNITED_type1_old_5PERC <- UNITED_type1_old %>%
summarise(totalover = sum(prob >= 0.05),
ncasespickedup = sum(prob >= 0.05 & M ==1),
PPV = (sum(prob >= 0.05 & M ==1)/sum(prob >= 0.05))*100,
nmissedcases = sum(M==1) - sum(prob >= 0.05 & M ==1),
Missedcases = ((sum(M==1) - sum(prob >= 0.05 & M ==1))/sum(M==1))*100,
NPV = (sum(prob < 0.05 & M == 0)/sum(prob < 0.05))*100,
Sensitivity = (sum(prob >= 0.05 & M ==1)/sum(M==1))*100,
Specificity = (sum(prob < 0.05 & M == 0)/sum(M==0))*100)
##### 10%
UNITED_type1_old_10PERC <- UNITED_type1_old %>%
summarise(totalover = sum(prob >= 0.1),
ncasespickedup = sum(prob >= 0.1 & M ==1),
PPV = (sum(prob >= 0.1 & M ==1)/sum(prob >= 0.1))*100,
nmissedcases = sum(M==1) - sum(prob >= 0.1 & M ==1),
Missedcases = ((sum(M==1) - sum(prob >= 0.1 & M ==1))/sum(M==1))*100,
NPV = (sum(prob < 0.1 & M == 0)/sum(prob < 0.1))*100,
Sensitivity = (sum(prob >= 0.1 & M ==1)/sum(M==1))*100,
Specificity = (sum(prob < 0.1 & M == 0)/sum(M==0))*100)
### 20%
UNITED_type1_old_20PERC <- UNITED_type1_old %>%
summarise(totalover = sum(prob >= 0.2),
ncasespickedup = sum(prob >= 0.2 & M ==1),
PPV = (sum(prob >= 0.2 & M ==1)/sum(prob >= 0.2))*100,
nmissedcases = sum(M==1) - sum(prob >= 0.2 & M ==1),
Missedcases = ((sum(M==1) - sum(prob >= 0.2 & M ==1))/sum(M==1))*100,
NPV = (sum(prob < 0.2 & M == 0)/sum(prob < 0.2))*100,
Sensitivity = (sum(prob >= 0.2 & M ==1)/sum(M==1))*100,
Specificity = (sum(prob < 0.2 & M == 0)/sum(M==0))*100)
UNITED_type1_old_THRESHOLDS <- rbind(UNITED_type1_old_5PERC, UNITED_type1_old_10PERC, UNITED_type1_old_20PERC)
write_xlsx(UNITED_type1_old_THRESHOLDS,"UNITED_type1_old_THRESHOLDS_table.xlsx")
##Thresholds -----------------------------------------------------------------------------
##T2D ----------------------------------------------------------------------------------------
### 5%
UNITED_type2_old_5PERC <- UNITED_type2_old %>%
summarise(totalover = sum(prob >= 0.05),
ncasespickedup = sum(prob >= 0.05 & M ==1),
PPV = (sum(prob >= 0.05 & M ==1)/sum(prob >= 0.05))*100,
nmissedcases = sum(M==1) - sum(prob >= 0.05 & M ==1),
Missedcases = ((sum(M==1) - sum(prob >= 0.05 & M ==1))/sum(M==1))*100,
NPV = (sum(prob < 0.05 & M == 0)/sum(prob < 0.05))*100,
Sensitivity = (sum(prob >= 0.05 & M ==1)/sum(M==1))*100,
Specificity = (sum(prob < 0.05 & M == 0)/sum(M==0))*100)
### 10%
UNITED_type2_old_10PERC <- UNITED_type2_old %>%
summarise(totalover = sum(prob >= 0.1),
ncasespickedup = sum(prob >= 0.1 & M ==1),
PPV = (sum(prob >= 0.1 & M ==1)/sum(prob >= 0.1))*100,
nmissedcases = sum(M==1) - sum(prob >= 0.1 & M ==1),
Missedcases = ((sum(M==1) - sum(prob >= 0.1 & M ==1))/sum(M==1))*100,
NPV = (sum(prob < 0.1 & M == 0)/sum(prob < 0.1))*100,
Sensitivity = (sum(prob >= 0.1 & M ==1)/sum(M==1))*100,
Specificity = (sum(prob < 0.1 & M == 0)/sum(M==0))*100)
### 20%
UNITED_type2_old_20PERC <- UNITED_type2_old %>%
summarise(totalover = sum(prob >= 0.2),
ncasespickedup = sum(prob >= 0.2 & M ==1),
PPV = (sum(prob >= 0.2 & M ==1)/sum(prob >= 0.2))*100,
nmissedcases = sum(M==1) - sum(prob >= 0.2 & M ==1),
Missedcases = ((sum(M==1) - sum(prob >= 0.2 & M ==1))/sum(M==1))*100,
NPV = (sum(prob < 0.2 & M == 0)/sum(prob < 0.2))*100,
Sensitivity = (sum(prob >= 0.2 & M ==1)/sum(M==1))*100,
Specificity = (sum(prob < 0.2 & M == 0)/sum(M==0))*100)
UNITED_type2_old_THRESHOLDS <- rbind(UNITED_type2_old_5PERC, UNITED_type2_old_10PERC, UNITED_type2_old_20PERC)
write_xlsx(UNITED_type2_old_THRESHOLDS,"UNITED_type2_old_THRESHOLDS_table.xlsx")
### all genes ----------------------------------------------------------------------------------------
#### T1D ------------------------------------------------------------------------------------
### 5%
UNITED_type1_all_genes_old_5PERC <- UNITED_type1_all_genes_old %>%
summarise(totalover = sum(prob >= 0.05),
ncasespickedup = sum(prob >= 0.05 & M ==1),
PPV = (sum(prob >= 0.05 & M ==1)/sum(prob >= 0.05))*100,
nmissedcases = sum(M==1) - sum(prob >= 0.05 & M ==1),
Missedcases = ((sum(M==1) - sum(prob >= 0.05 & M ==1))/sum(M==1))*100,
NPV = (sum(prob < 0.05 & M == 0)/sum(prob < 0.05))*100,
Sensitivity = (sum(prob >= 0.05 & M ==1)/sum(M==1))*100,
Specificity = (sum(prob < 0.05 & M == 0)/sum(M==0))*100)
### 10%
UNITED_type1_all_genes_old_10PERC <- UNITED_type1_all_genes_old %>%
summarise(totalover = sum(prob >= 0.1),
ncasespickedup = sum(prob >= 0.1 & M ==1),
PPV = (sum(prob >= 0.1 & M ==1)/sum(prob >= 0.1))*100,
nmissedcases = sum(M==1) - sum(prob >= 0.1 & M ==1),
Missedcases = ((sum(M==1) - sum(prob >= 0.1 & M ==1))/sum(M==1))*100,
NPV = (sum(prob < 0.1 & M == 0)/sum(prob < 0.1))*100,
Sensitivity = (sum(prob >= 0.1 & M ==1)/sum(M==1))*100,
Specificity = (sum(prob < 0.1 & M == 0)/sum(M==0))*100)
### 20%
UNITED_type1_all_genes_old_20PERC <- UNITED_type1_all_genes_old %>%
summarise(totalover = sum(prob >= 0.2),
ncasespickedup = sum(prob >= 0.2 & M ==1),
PPV = (sum(prob >= 0.2 & M ==1)/sum(prob >= 0.2))*100,
nmissedcases = sum(M==1) - sum(prob >= 0.2 & M ==1),
Missedcases = ((sum(M==1) - sum(prob >= 0.2 & M ==1))/sum(M==1))*100,
NPV = (sum(prob < 0.2 & M == 0)/sum(prob < 0.2))*100,
Sensitivity = (sum(prob >= 0.2 & M ==1)/sum(M==1))*100,
Specificity = (sum(prob < 0.2 & M == 0)/sum(M==0))*100)
UNITED_type1_all_genes_old_THRESHOLDS <- rbind(UNITED_type1_all_genes_old_5PERC, UNITED_type1_all_genes_old_10PERC, UNITED_type1_all_genes_old_20PERC)
write_xlsx(UNITED_type1_all_genes_old_THRESHOLDS,"UNITED_type1_all_genes_old_THRESHOLDS_table.xlsx")
##Thresholds -----------------------------------------------------------------------------
##T2D ----------------------------------------------------------------------------------------
### 5%
UNITED_type2_all_genes_old_5PERC <- UNITED_type2_all_genes_old %>%
summarise(totalover = sum(prob >= 0.05),
ncasespickedup = sum(prob >= 0.05 & M ==1),
PPV = (sum(prob >= 0.05 & M ==1)/sum(prob >= 0.05))*100,
nmissedcases = sum(M==1) - sum(prob >= 0.05 & M ==1),
Missedcases = ((sum(M==1) - sum(prob >= 0.05 & M ==1))/sum(M==1))*100,
NPV = (sum(prob < 0.05 & M == 0)/sum(prob < 0.05))*100,
Sensitivity = (sum(prob >= 0.05 & M ==1)/sum(M==1))*100,
Specificity = (sum(prob < 0.05 & M == 0)/sum(M==0))*100)
### 10%
UNITED_type2_all_genes_old_10PERC <- UNITED_type2_all_genes_old %>%
summarise(totalover = sum(prob >= 0.1),
ncasespickedup = sum(prob >= 0.1 & M ==1),
PPV = (sum(prob >= 0.1 & M ==1)/sum(prob >= 0.1))*100,
nmissedcases = sum(M==1) - sum(prob >= 0.1 & M ==1),
Missedcases = ((sum(M==1) - sum(prob >= 0.1 & M ==1))/sum(M==1))*100,
NPV = (sum(prob < 0.1 & M == 0)/sum(prob < 0.1))*100,
Sensitivity = (sum(prob >= 0.1 & M ==1)/sum(M==1))*100,
Specificity = (sum(prob < 0.1 & M == 0)/sum(M==0))*100)
### 20%
UNITED_type2_all_genes_old_20PERC <- UNITED_type2_all_genes_old %>%
summarise(totalover = sum(prob >= 0.2),
ncasespickedup = sum(prob >= 0.2 & M ==1),
PPV = (sum(prob >= 0.2 & M ==1)/sum(prob >= 0.2))*100,
nmissedcases = sum(M==1) - sum(prob >= 0.2 & M ==1),
Missedcases = ((sum(M==1) - sum(prob >= 0.2 & M ==1))/sum(M==1))*100,
NPV = (sum(prob < 0.2 & M == 0)/sum(prob < 0.2))*100,
Sensitivity = (sum(prob >= 0.2 & M ==1)/sum(M==1))*100,
Specificity = (sum(prob < 0.2 & M == 0)/sum(M==0))*100)
UNITED_type2_all_genes_old_THRESHOLDS <- rbind(UNITED_type2_all_genes_old_5PERC, UNITED_type2_all_genes_old_10PERC, UNITED_type2_all_genes_old_20PERC)
write_xlsx(UNITED_type2_all_genes_old_THRESHOLDS,"UNITED_type2_all_genes_old_THRESHOLDS_table.xlsx")