-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlambda_progression.Rmd
163 lines (138 loc) · 4.04 KB
/
lambda_progression.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
---
title: "Lambda progression"
author: "Johann Hawe"
date: "3 12 2021"
output: html_document
---
```{r setup, include=FALSE}
library(tidyverse)
library(cowplot)
library(reshape2)
library(ggpubr)
theme_set(theme_cowplot())
knitr::opts_chunk$set(echo = TRUE)
```
```{r load_data}
fparsed_results <- "results/current/prior_noise_rho_summary.tsv"
if (!file.exists(fparsed_results)) {
# load simulation results
fprior_noise_results <-
list.files(
"results/current/biogrid_stringent/simulation/fits/",
".*subsetall.RData",
full.names = T
)
prior_noise_results <- lapply(fprior_noise_results, function(f) {
load(f)
iter <- gsub(".*(iter[0-9]+).*", "\\1", f)
lapply(result, function(res) {
rdegree <- as.character(res$rdegree)
rho_best_priors <- res$fits$glasso_fit$rho_best
rho_best <- res$fits$glasso_no_priors_fit$rho_best
tibble(rdegree, rho_best, rho_best_priors)
}) %>% bind_rows()
}) %>% bind_rows()
write_tsv(path = fparsed_results, prior_noise_results)
} else {
prior_noise_results <- read_tsv(fparsed_results)
}
fparsed_results <-
"results/current/subset_progression_rho_summary.tsv"
if (!file.exists(fparsed_results)) {
fsubset_results <-
list.files(
"results/current/biogrid_stringent/simulation/fits/",
".*subset[0-9]+.RData",
full.names = T
)
i <- 0
subset_progression_results <-
mclapply(fsubset_results, function(f) {
i <<- i + 1
if (i %% 1000 == 0) {
print(i)
gc(full = T)
}
load(f)
if (length(result) > 0) {
res <- result[[1]]
rho_best_priors <- res$fits$glasso_fit$rho_best
rho_best <- res$fits$glasso_no_priors_fit$rho_best
tibble(subset, rho_best, rho_best_priors)
} else {
NULL
}
}, mc.cores = 4) %>% bind_rows()
write_tsv(path = fparsed_results,
subset_progression_results)
} else {
subset_progression_results <- read_tsv(fparsed_results)
}
```
```{r define_plot_function}
plot_progression <- function(data,
id_name = "rdegree",
x_label = "prior error") {
toplot <- melt(data, id.vars = id_name) %>%
mutate(variable = gsub("rho_best_priors", "prior based", variable)) %>%
mutate(variable = gsub("rho_best", "without priors", variable))
ggplot(toplot, aes(
x = factor(as.character(get(id_name)),
levels = unique(pull(toplot, !!id_name)),
ordered = T),
y = value,
col = variable
)) +
stat_boxplot(geom = "errorbar", width = .75) +
geom_boxplot(
outlier.size = 0,
alpha = 0.5,
coef = 0,
outlier.shape = NA,
) +
stat_summary(
fun.y = median,
geom = "smooth",
position = position_dodge(0.75),
aes(group = variable),
lwd = 0.8
) +
scale_color_brewer(type = "qual") +
background_grid(major = "x") +
#geom_vline(
# xintercept = 11.5,
# size = 1.5,
# color = "black",
# linetype = "dashed"
#) +
labs(x = x_label,
y = "Rho",
fill = "",
color = "type") +
theme(
legend.position = "right",
legend.text = element_text(size = 12),
legend.title = element_text(size = 14),
axis.text.x = element_text(
hjust = 0,
vjust = 0.5,
angle = -45,
size = 12
),
axis.title.x = element_text(size = 14),
plot.margin = margin(0.2, 1, 0.2, 0.2, "cm")
)
}
```
```{r plot_results}
gp1 <- plot_progression(prior_noise_results, x_label = "prior error")
gp2 <- plot_progression(mutate(subset_progression_results,
subset = as.numeric(subset)) %>%
arrange(subset),
id_name = "subset", x_label = "subset size")
ga <- ggarrange(gp1, gp2, nrow = 1, ncol = 2, common.legend = T,
legend = "bottom", labels = "AUTO")
save_plot("results/current/revisions/figures/simulation_rho_progression.pdf",
ga, ncol = 2, nrow = 1)
ga
```