-
Notifications
You must be signed in to change notification settings - Fork 1
/
access_metrics.R
139 lines (124 loc) · 4.78 KB
/
access_metrics.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
library(tidyverse)
library(RPostgres)
library(odbc)
library(DBI)
library(skimr)
# https://data-viz.it.wisc.edu/cornell-parameter-sweep/
con <- dbConnect(RPostgres::Postgres(),
dbname = "test",
host = "database-2.clbsgd2qdkby.us-east-1.rds.amazonaws.com",
port = 5432,
user = "postgres",
password = "YxDi7HnjfpBxHKQ")
## Metrics with sim_id and group_number
metrics <- dbGetQuery(con, 'Select * from metrics') %>%
as_tibble() %>%
pivot_longer(cols = -c(sim_id, group_number),
names_to = "metric_name",
values_to = "metric_value")
## Parameters for each simulation
all_params <-
tbl(con, "group_params") %>%
distinct() %>%
collect() %>%
mutate(across(where(bit64::is.integer64), as.numeric))
all_params_wide <-
all_params %>%
select(-`_scenario_name`) %>%
pivot_wider(id_cols = sim_id,
names_from = group_number,
values_from = c(everything(), -sim_id, -group_number)) %>%
mutate(across(everything(), ~ as.factor(.x)))
skim_df <-
all_params_wide %>%
skimr::skim() %>%
filter(factor.n_unique > 1)
## A basic combination of the two with only the parameters that are varied
metrics %>%
pivot_wider(names_from = "metric_name", values_from = "metric_value") %>%
left_join(all_params_wide %>%
select(sim_id, skim_df$skim_variable),
by = "sim_id")
tmpfn <- function(x, y = "") {
paste0(y, " ", 100 * signif(as.numeric(as.character(x)), 2), "%")
}
dat <- metrics %>%
mutate(metric_name = make.names(metric_name)) %>%
pivot_wider(names_from = "metric_name", values_from = "metric_value") %>%
left_join(all_params_wide %>%
select(sim_id, skim_df$skim_variable),
by = "sim_id") %>%
rename(contact_UG_on = "contact_rate_multiplier_0",
contact_UG_off = "contact_rate_multiplier_1",
contact_Grad_res = "contact_rate_multiplier_2",
contact_Grad_tea = "contact_rate_multiplier_3",
contact_Staff = "contact_rate_multiplier_4",
prev_UG_on = "initial_ID_prevalence_0",
prev_UG_off = "initial_ID_prevalence_1",
test_UG_on = "test_population_fraction_0",
test_UG_off = "test_population_fraction_1") %>%
mutate(test_UG_on = tmpfn(test_UG_on, "test_UG_on"),
test_UG_off = tmpfn(test_UG_off, "test_UG_off"),
prev_UG_off = tmpfn(prev_UG_off, "prev_UG_off"),
prev_UG_on = tmpfn(prev_UG_on, "prev_UG_on"))
ggplot(dat %>%
filter(contact_UG_on == 1.25,
contact_UG_off == 1,
contact_Grad_res == 1,
contact_Grad_tea == 1,
contact_Staff == 1)) +
aes(Time.of.peak.COVID.19.cases, Peak.active.cases,
col = test_UG_off) +
geom_point() +
geom_smooth(se = FALSE) +
scale_y_log10() +
facet_grid(test_UG_on ~ prev_UG_on)
fit <- lm(log10(Peak.active.cases) ~
contact_UG_on + contact_UG_off +
contact_Grad_res + contact_Grad_tea +
contact_Staff +
test_UG_on + test_UG_off +
prev_UG_on + prev_UG_off, dat)
fits <- lm(log10(Peak.active.cases) ~
(contact_UG_on + contact_UG_off +
contact_Grad_res + contact_Grad_tea +
contact_Staff +
test_UG_on + test_UG_off +
prev_UG_on + prev_UG_off)^2, dat)
fitss <- step(fits)
anova(fitss)
ggplot(dat %>%
mutate(contact_UG_on = as.numeric(as.character(contact_UG_on))) %>%
filter(contact_UG_off == 1,
contact_Grad_res == 1,
contact_Grad_tea == 1,
contact_Staff == 1,
test_UG_off == "test_UG_off 7.1%")) +
aes(contact_UG_on, Peak.active.cases,
col = prev_UG_off) +
geom_jitter(height = 0, width = 0.05) +
geom_smooth(method = "lm", se = FALSE) +
scale_y_log10() +
facet_grid(test_UG_on ~ prev_UG_on)
ggplot(dat %>%
# mutate(contact_UG_on = as.numeric(as.character(contact_UG_on))) %>%
filter(contact_UG_on == 1,
contact_UG_off == 1,
contact_Grad_res == 1,
contact_Grad_tea == 1,
contact_Staff == 1,
test_UG_off == "test_UG_off 7.1%")) +
aes(Time.of.peak.COVID.19.cases, Peak.active.cases,
col = prev_UG_off) +
geom_jitter(height = 0, width = 0.05) +
geom_smooth(method = "lm", se = FALSE) +
scale_y_log10() +
facet_grid(test_UG_on ~ prev_UG_on)
dat %>%
mutate(contact_UG_on = as.numeric(as.character(contact_UG_on))) %>%
filter(contact_UG_off == 1,
contact_Grad_res == 1,
contact_Grad_tea == 1,
contact_Staff == 1,
test_UG_off == "test_UG_off 7.1%") %>%
select(Peak.active.cases, contact_UG_on, test_UG_on, prev_UG_on, prev_UG_off)