forked from reconhub/outbreaker2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAnalyse_results_cchain.Rmd
184 lines (158 loc) · 6.72 KB
/
Analyse_results_cchain.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
---
title: "Analysis of Bayesian results - Genouest"
author: "Jonathan Roux"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
word_document: default
pdf_document: default
html_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r message=TRUE, warning=FALSE, include=FALSE}
##############################
#### Loading of libraries ####
##############################
library(data.table)
library(knitr)
library(ggplot2)
library(ggrepel)
source("./Functions_Rmd.R")
##########################################
#### Loading of chains_detect100_bind ####
##########################################
load("../StageCRENet/hackathon/outbreaker/data/data1.Rdata")
load("../StageCRENet/hackathon/outbreaker/chains/chains1.Rdata")
## Preparation of data ##
detect100 <- data$detect100
chains_detect100 <- chains$detect100
chains_detect100_bind <- rbindlist(chains_detect100)
setnames(chains_detect100_bind,
c("hospID","origin"),
c("to","from"))
# Keeping in mind the chains #
counter <- 0
for(i in 1:chains_detect100_bind[,.N]){
if(chains_detect100_bind[i, is.na(from)])
counter <- counter + 1
chains_detect100_bind[i, chain := counter]
}
# Length of chains #
lengths_chains <- chains_detect100_bind[, .N, by = "chain"]
chains_detect100_bind <- merge(chains_detect100_bind,
lengths_chains[, .(chain,
length_chain = N-1)],
by = "chain")
## Preparation of chains_detect100_bind to facilitate the computation of parameters ##
detect100[,num := seq_len(.N)]
chains_detect100_bind.2 <- merge(chains_detect100_bind,
detect100[,.(hospID, t_descendant = t,
t_detect_descendant = t_detect,
num)],
by.x = c("to", "t_detect"),
by.y = c("hospID","t_detect_descendant"))
chains_detect100_bind.2 <- merge(chains_detect100_bind.2,
detect100[,.(hospID,
t_ancestor = t,
num)],
by.x = c("from"),
by.y = c("hospID"),
all.x=TRUE)
chains_detect100_bind.2 <- chains_detect100_bind.2[t_ancestor<t | is.na(from)]
chains_detect100_bind.2 <- chains_detect100_bind.2[order(to, t, t_ancestor)]
chains_detect100_bind.2 <- chains_detect100_bind.2[,.SD[.N],
by = c("from", "to", "t")]
# chains_detect100_bind.2[, t.y := NULL]
setnames(chains_detect100_bind.2, c("num.x","num.y"), c("ids_to","ids_from"))
detect100[, num := NULL]
chains_detect100_bind <- chains_detect100_bind.2
###################################################
#### Loading of data of chains' reconstruction ####
###################################################
# Number of scenarii #
no_scenarii <- 3
# Location of rds files #
# Genouest or Ordi #
location <- "Genouest"
# Type: complete or incomplete #
type <- "complete"
# Loading of data #
# results_1 <- readRDS("./tmp_results/Ordi/1-results_50000_5_parLapply_scenario1.rds")
# results_2 <- readRDS("./tmp_results/Genouest/1-results_50000_5_parLapply_scenario2.rds")
# results_3 <- readRDS("./tmp_results/Ordi/1-results_50000_5_parLapply_scenario3.rds")
##########################
#### Global variables ####
##########################
# Burning period #
vec_burning <- rep(5000, no_scenarii)
# Thinning #
thinning <- rep(5, no_scenarii)
# No iterations #
no_iter <- rep(50000, no_scenarii)
# Adding noise on dates of infection #
adding_noise <- c("-", "P(3.5)", "P(7)")
# Minimal support #
min.support <- 10^(-seq(0, 4, by = 0.05))
###################################
#### Computation of parameters ####
###################################
result_function <- lapply(1:no_scenarii,
ParametersSynthesis,
vec_burning = vec_burning,
location = location,
type = type,
NotRetrieved = FALSE,
StudyKappa = FALSE,
chains_detect100_bind = chains_detect100_bind,
NewBurning = TRUE,
min.support = min.support)
output <- t(cbind(no_iter = no_iter,
thinning = thinning,
burning = vec_burning,
adding_noise = adding_noise,
rbindlist(lapply(result_function,
function(r) {
r$parameters
}
)
)
)
)
output.dt <- as.data.table(output)
names(output.dt) <- as.character(paste0("Scenario ",1:no_scenarii))
output.dt[, parameter := c("No. of iterations", "Thinning", "Burning period",
"Noise added",
"Value of pi", "Value of sigma",
"Value of poisson_scale", "Shannon entropy",
"Consensus-No links retrieved",
"Consensus-Sensitivity", "Consensus-% chains reconstructed",
"All ancestors-Sensitivity", "All ancestors-Specificity",
"All ancestors-No links retrieved", "All ancestors-PPV",
"All ancestors-NPV", "All ancestors-% chains reconstructed",
"All ancestors-Maximum sensitivity",
"All ancestors-Related minimal support",
"All ancestors-Related no links retrieved",
"All ancestors-Related specificity",
"All ancestors-Related PPV",
"All ancestors-Related NPV",
"All ancestors-Related % chains reconstructed",
"Youden max",
"Youden max-Related minimal support",
"Youden max-Related sensitivity",
"Youden max-Related specificity",
"Youden max-Related no links retrieved",
"Youden max-Related PPV",
"Youden max-Related NPV",
"Youden max-Related % chains reconstructed"
)]
setcolorder(output.dt, "parameter")
```
```{r echo=FALSE,warning=FALSE,results="asis", message=FALSE}
kable(output.dt)
lapply(result_function,
function(r) {
r$ROC
}
)
```