-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparamSweep_nbm_Tsp.R
82 lines (64 loc) · 2.42 KB
/
paramSweep_nbm_Tsp.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
# This script sweeps across combinations of numbers of blood meals nbm and the development length of the parasite Tsp
# Created by Paola Carrillo-Bustamante
# 2020-07-10
rm(list=ls()) #remove old values to avoid troubles
setwd("C:\\Users\\isabe\\OneDrive\\Documentos\\GitHub\\resourceallocation\\code")
library(deSolve)
library(dplyr)
source('functions.R') # contains BM periodic waves
source('models.R') # contains the ODE models we are testing
###sweep functions ----
computeSimulations<-function(s.vec, p.vec, O_init, T.sigma, name)
{
#create the parameter vectors for Tsigma and Tsp
n_bm<-c(1,2,3,4,5)
T.sp<-c(8,9,10,11,12,13,14)
#generate data frames with the results
all_runs<-c()
#set the indection status
my_s<-my_replace(s, c(O = O_init))
#go through each for loop
for(i in n_bm)
{
for (j in T.sp)
{
print(paste0("simulating ODE system with n.bm=", i, " and T.sp = ", j))
my_p<-my_replace(p,c(T_sigma = T.sigma*24, sporogonyTime= j*24, number_BM = i))
tmp<-run(condition = i, params = my_p, state = my_s,tend = 25)
names(tmp)[5]<-"NB"
tmp<-add.type(tmp, j)
names(tmp)[6]<-"T.sp"
tmp<-add.type(tmp,name)
names(tmp)[7]<-"Infection"
all_runs<-bind_rows(all_runs,tmp)
}
}
T_sigma<-rep(T.sigma, nrow(all_runs))
all_runs<-cbind(all_runs,T_sigma)
print(paste0("saving simulations to: ../results/",Sys.Date(),"_paramSweep_nbm_t.sp_",name,".csv"))
#save the generated data
write.csv2(all_runs, file = paste0("../results/",Sys.Date(),"_paramSweep_nbm_t.sp_",name,".csv"), row.names = FALSE)
}
runSweep<-function(infected, T_sigma = 5, s.vec, p.vec)
{
if(infected)
{
O_init<-0.1
name<-"infected"
}else{
O_init<-0
name<-"uninfected"
}
print(name)
computeSimulations(s.vec, p.vec, O_init, T_sigma, name)
}
### set initial states and parameters ---
s<-c(B = 0, R = 0.5, E = 0.1, O = 0.0, S = 0, beta_E = 0)
p<-c(K = 1, alpha = 1, delta_B = 0.001, beta_P = 0.08, delta_R = 0.005, delta_E = 0.5, gamma=0.1,
T_sigma = 24*5, delta_sigma = 6, shift_sigma = 12, number_BM = 1,bm.qual=1, number_BM_quality = 1,
delta_sigma_e20 = 24,a = 0.5, b = 0.5,c=0.3,
traversalTime = 3*24, sporogonyTime = 11*24)
#Run simulations with:
runSweep(infected=TRUE, T_sigma = 5) # actual sweep
runSweep(infected=FALSE, T_sigma = 5) #control for eggs
#runSweep(infected=TRUE, T_sigma = 5) #control for parasite