-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06_model_run_prev_usage_fit_eir.R
53 lines (41 loc) · 1.68 KB
/
06_model_run_prev_usage_fit_eir.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
library(zoo)
library(dplyr)
source("R/run_model.R")
##################################################################################################
# Run function
run <- function(init_EIR, usage, model_parameters){
# Time of reading data
time <- 6*365
model <- run_model(model_parameters = model_parameters,
resistance = 0, init_EIR = init_EIR, usage = usage,
t_max=10*365)
# Prevs in kids
prev <- rollmean(model$prev, k=3*365, fill = NA, align='left')[time]
non_user_prev <- rollmean(model$prev1, k=3*365, fill = NA, align='left')[time]
user_prev <- rollmean(model$prev2, k=3*365, fill = NA, align='left')[time]
prev_data <- data.frame("overall" = prev,
"user" = user_prev,
"non_user" = non_user_prev)
return (prev_data$non_user - prev_data$user)
}
##################################################################################################
fitted_data <- readRDS("outputs/fitted_EIRs_prev_usage_new.RDS")
model_parameters <- read_excel(path="data/parameter_sweep_res.xlsx")
prevs <- as.numeric(rownames(fitted_data))
usages <- as.numeric(colnames(fitted_data))
model_data <- matrix(ncol = length(usages), nrow = length(prevs))
for (i in 1:length(prevs)){
for(j in 1:length(usages)){
if (i == 8 & j > 8){
print("None")
} else {
model_data[i,j] <- run(init_EIR = fitted_data[i,j],
usage = usages[j],
model_parameters = model_parameters[1,])
}
}
}
data <- as.data.frame(model_data)
colnames(data) <- usages
rownames(data) <- prevs
saveRDS(data, "outputs/modelled_data_prev_usage_new.RDS")