-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3_Inference.R
101 lines (68 loc) · 2.45 KB
/
3_Inference.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
library(tidyverse)
library(rstan)
source("R/inference.R")
### Country list -----
source("data/country_list.R")
### Collect duration ----
Durations_list <- lapply(names(countries), function(iso) {
iso <- glue::as_glue(iso)
country <- countries[names(countries) == iso]
infer_duration(iso, country)
})
names(Durations_list) <- names(countries)
for (iso in names(countries)) {
iso <- glue::as_glue(iso)
Durations <- Durations_list[[iso]]
save(Durations, file = "out/Durations_" + iso + ".rdata")
}
Durations <- list(
Durations_Sex = bind_rows(lapply(Durations_list, function(x) x$Durations_Sex)),
Durations_All = bind_rows(lapply(Durations_list, function(x) x$Durations_All))
)
save(Durations, file = "out/Durations_All.rdata")
### Collect conversion rate ----
Conversion_list <- lapply(names(countries), function(iso) {
iso <- glue::as_glue(iso)
country <- countries[names(countries) == iso]
infer_conversion(iso, country)
})
names(Conversion_list) <- names(countries)
for (iso in names(countries)) {
iso <- glue::as_glue(iso)
Conversion <- Conversion_list[[iso]]
save(Conversion, file = "out/Conversion_" + iso + ".rdata")
}
Conversion <- list(
Reg = lapply(Conversion_list, function(x) x$Reg),
Pars = bind_rows(lapply(Conversion_list, function(x) x$Pars)),
Dens = bind_rows(lapply(Conversion_list, function(x) x$Dens)),
Wts = bind_rows(lapply(Conversion_list, function(x) x$Wts)) %>% mutate(ISO = names(countries))
)
save(Conversion, file = "out/Conversion_All.rdata")
### Collect cascade ----
Cascade_list <- lapply(names(countries), function(iso) {
iso <- glue::as_glue(iso)
country <- countries[names(countries) == iso]
infer_cascade(iso, country)
})
names(Cascade_list) <- names(countries)
Cohort_list <- lapply(names(countries), function(iso) {
country <- countries[names(countries) == iso]
infer_cohort(iso, country, 200)
})
names(Cohort_list) <- names(countries)
for (iso in names(countries)) {
iso <- glue::as_glue(iso)
Cascade <- Cascade_list[[iso]]
Cohort <- Cohort_list[[iso]]
save(Cascade, Cohort, file = "out/Cascade_" + iso + ".rdata")
}
Cascade <- list(
Cascade_Sex = bind_rows(lapply(Cascade_list, function(x) x$Cascade_Sex)),
Cascade_All = bind_rows(lapply(Cascade_list, function(x) x$Cascade_All))
)
Cohort <- list(
Cohort = bind_rows(lapply(Cohort_list, function(x) x$Cohort)),
End = bind_rows(lapply(Cohort_list, function(x) x$End))
)
save(Cascade, Cohort, file = "out/Cascade_All.rdata")