/
wrapper-v1.1.3.R
221 lines (182 loc) · 8.32 KB
/
wrapper-v1.1.3.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# main-produce-farm-v1.1.3.R is part of Food INdustry CoViD Control Tool
# (FInd CoV Control), version 1.1.3.
# Copyright (C) 2020-2021 Cornell University.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#revising the use of double_wrap_* variables to make solo use of wrapper.R less
#confusing
# behavior of wrapper.R is controlled by other files using several tests for
# all-caps variables. Production code has not run wrapper.R directly for some,
# time now; if it is still possible to run it directly without further
# modification, then the following should evaluate to FALSE:
# exists('ANALYZE') && ANALYZE == TRUE
# exists('DOUBLE_WRAPPED') && DOUBLE_WRAPPED == TRUE
# If using double-wrapped.R to run a batch of scenarios, a number of
# parameters may be overwritten by the "double_wrapped" variables; as a reminder
# of this, they are marked with comments of the form:
# batch mode: [double_wrapped variable name]
# These comments can be ignored entirely if not intending to ever use batch mode
# (assuming that not using batch mode still works).
# Number of individuals initially in various states other than completely
# susceptible
wrapper_fn = function() { #will it work? the goal is to get more meaningful debug data
initial_recovered = 0 # batch mode: double_wrap_initial_recovered
initial_V1 = 0 # batch mode: double_wrap_initial_V1
initial_V2 = 0 # batch mode: double_wrap_initial_V2
###########################################
# Flags controlling various interventions #
###########################################
# Social distancing interventions
theoretical_social_distancing_R0_reduction = 0
#surveillance -- currently, these cannot both be true, but that limitation may at some point be lifted
temperature_screening = FALSE
temperature_threshold = 37.1 # batch mode: double_wrap_temp_test
# values currently recognized: 37.1, 37.5, 38,
# 38.5 (degress celsius)
# combining other values with
# temperature_testing = TRUE will cause an error
viral_testing_rate = 0.3 # batch mode: double_wrap_viral_test_rate
rational_testing = TRUE
isolation_duration = 14 # batch mode: double_wrap_isolation_duration
#vaccination
vaccination_rate = 0 # batch mode: double_wrap_vax_rate
rational_vaccination = FALSE #TRUE is not currently implemented, but may be at some point in the future
##############################
# Program control parameters #
##############################
num_sims = 100 # number of simulations; 100 takes 1-2 minutes (less on a faster machine); for production use, most likely want 1000+
# batch mode: double_wrap_num_sims
################################################################
# Code to allow batch running, by overriding parameters #
# set in this file with those set in the invoking file. #
# If not using batch mode, this section may safely be ignored. #
################################################################
if(exists('DOUBLE_WRAPPED') && DOUBLE_WRAPPED == TRUE) {
initial_recovered = double_wrap_initial_recovered
theoretical_social_distancing_R0_reduction = double_wrap_reduction
temperature_screening = (double_wrap_temp_test != FALSE)
temperature_threshold = double_wrap_temp_test
viral_testing_rate = double_wrap_viral_test_rate
vaccination_rate = double_wrap_vax_rate
community_foi = double_wrap_community_foi
num_sims = double_wrap_num_sims
isolation_duration = double_wrap_isolation_duration
baseline_work_R0 = double_wrap_baseline_work_R0
initial_V1 = double_wrap_initial_V1
initial_V2 = double_wrap_initial_V2
rational_testing = double_wrap_rational_testing
}
#############################################################################
# Derived values; simple use will not require modification below this point #
#############################################################################
social_distancing_R0_factor = (
(1 - theoretical_social_distancing_R0_reduction)
)
total_R0_factor = social_distancing_R0_factor
net_work_R0 = total_R0_factor * baseline_work_R0
#for now, assuming that R0 reductions only apply at work
if(temperature_screening) {
if(viral_testing_rate != 0) {
stop() #both at once is not yet implemented
}
if(temperature_threshold == 37.1) {
sensitivity = .63
specificity = .95
} else if (temperature_threshold == 37.5) {
sensitivity = .32
specificity = .99
} else if (temperature_threshold == 38) {
sensitivity = .18
specificity = 1.00
} else if (temperature_threshold == 38.5) {
sensitivity = .08
specificity = 1.00
} else {
stop('Invalid screening temperature')
}
testing_parameters = list(
#following several parameters taken from Cashore et al. 2020,
#citing Kojima et al. 2020 and To et al. 2020. assuming them equal
#for now, will run just fine with alternate assumptions
### the following are parameters for virus testing
asymptomatic_FNR = specificity, #presumably, we'll catch a few by chance
presymptomatic_FNR = specificity,
mild_FNR = 1 - sensitivity,
FPR = 1 - specificity,
rational_testing = rational_testing
)
work_testing_rate = 1
} else {
testing_parameters = list(
#following several parameters taken from Cashore et al. 2020,
#citing Kojima et al. 2020 and To et al. 2020. assuming them equal
#for now, will run just fine with alternate assumptions
### the following are parameters for virus testing
asymptomatic_FNR = 1 - 0.9,
presymptomatic_FNR = 1 - 0.9,
mild_FNR = 1 - 0.9,
FPR = 1 - 0.9995,
rational_testing = rational_testing
)
work_testing_rate = viral_testing_rate
}
#########################
# filename construction #
#########################
filename_core = paste(subdirectory, unique_id, '_community-', community_foi, ',work_R0-', baseline_work_R0, sep = '')
R0_factor_string = paste()
if(total_R0_factor != 1) {
filename_core = paste(filename_core , 'x(1-', 1 - total_R0_factor, ')', sep = '')
}
if(dormitory_R0 > 0) {
filename_core = paste(filename_core, ',dormitory_R0-', dormitory_R0, sep = '')
}
filename_core = paste(filename_core, ',E0-', n_exposed, sep = '')
if(n_mild > 0) {
filename_core = paste(filename_core, ',IM0-', n_mild, sep = '')
}
if(temperature_screening) {
filename_core = paste(filename_core, ',T.test-', temperature_threshold, sep = '')
}
if(viral_testing_rate != 0) {
filename_core = paste(filename_core, ',v.test-', viral_testing_rate, sep = '')
if(rational_testing) {
filename_core = paste(filename_core, '-rational', sep = '')
}
}
if(vaccination_rate != 0) {
filename_core = paste(filename_core, ',vax-rate', vaccination_rate, sep = '')
}
if(isolation_duration != 14) {
filename_core = paste(filename_core, ',isol-dur-', isolation_duration, sep = '')
}
if(initial_recovered > 0) {
filename_core = paste(filename_core, ',initial_recovered-', initial_recovered, sep = '')
}
if(initial_V2 > 0) {
filename_core = paste(filename_core, ',initial_V2-', initial_V2, sep = '')
}
if(initial_V1 > 0) {
filename_core = paste(filename_core, ',initial_V1-', initial_V1, sep = '')
}
filename_core = paste(filename_core, ',n_sims-', num_sims, sep = '')
full_output_save_name = paste(filename_core, '_full-output.rds', sep = '')
#and now let's run the model
if(!(exists('ANALYZE') && ANALYZE == TRUE)) {
source('main-produce-farm-v1.1.3.R', local = TRUE)
main_produce_farm_fn()
}
full_output_save_name
} #wrapper_fn