-
Notifications
You must be signed in to change notification settings - Fork 1
/
global.R
64 lines (53 loc) · 1.78 KB
/
global.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
####################################
# Dependencies
###################################
require(tidyverse)
require(igraph)
require(visNetwork)
require(ggbeeswarm)
require(ggvis)
require(RColorBrewer)
# Shiny dependencies
require(shiny)
require(shinydashboard)
require(dashboardthemes)
require(shinydashboardPlus)
require(shinyWidgets)
require(shinyjs)
####################################
# Read individual files
###################################
# Folder to loead: Distance matrix, Edges list, Nodes list, STAD object
files <- dir("data/icd_list")
r_files <- which(!is.na(files %>% str_extract("a_")))
# Graph layoutL ForceAtlas2
files_layout <- dir("data/layout")
# Combine both files
files_all <- c(files[r_files], files_layout)
# Define status of all files:
# n: First column is a prefix to detect the interesting files
# icd: ICD9 code
# file: file type: distances, edges, mds, etc.
status <- as.data.frame(matrix( unlist(strsplit(files_all, "_")), byrow = TRUE, ncol = 3))
colnames(status) <- c("n", "icd", "file")
# Filter all ICD codes with seven files
status_s <- status %>%
select(-n) %>%
group_by(icd) %>%
summarise(num = n()) %>%
ungroup() %>%
filter(num == 7)
####################################
# Diagnosis
###################################
# Diagnosis table for all patients with all descriptions and importance order (634709 rows)
diagnosis <- readRDS("data/diagnosis.RDS")
# Diagnosis table for all ICD codes (354 rows)
diagnosis_title <- readRDS("data/diagnosis_title.RDS") %>%
rename(icd = ICD9_CODE) %>%
arrange(desc(Freq)) %>%
inner_join(status_s %>% mutate(icd = as.character(icd)), by = "icd") %>%
mutate(label = paste0(icd, ": ", LONG_TITLE, " (", Freq ,")") )
# Define icd_choices
icd_choices <- diagnosis_title$icd
names(icd_choices) <- diagnosis_title$label