-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_parameter.R
257 lines (195 loc) · 6.15 KB
/
get_parameter.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
## function name get_parameter
#' retrieve all parameters of specified type or class
#' @param data parameter dataframe output from \code{\link{load_epidata}}
#' @param parameter_name name of the parameter type or parameter class to
#' retrieve, ensuring the name matches that in data
#' @return dataframe with all parameter estimates and columns
#' @importFrom cli cli_abort
#' @export
#' @examples
#' df <- load_epidata(pathogen = "ebola")
#' get_parameter(data = df$params, parameter_name = "Human delay - serial interval")
#' @examples
#' df <- load_epidata(pathogen = "marburg")
#' get_parameter(data = df$params, parameter_name = "Attack rate")
get_parameter <- function(data, parameter_name) {
# Validate input: check if 'data' is a dataframe
if (!is.data.frame(data)) {
cli_abort("Error: 'data' should be a dataframe.")
}
# Validate input: check if 'parameter_name' is a non-empty string
if (!is.character(parameter_name) || parameter_name == "") {
cli_abort("Error: 'parameter_name' must be a non-empty string.")
}
# Validate that 'parameter_type' column exists in 'data'
if (!"parameter_type" %in% names(data)) {
cli_abort("Error: 'data' does not contain the required 'parameter_type' column.")
}
# Validate that 'parameter_class' column exists in 'data'
if (!"parameter_class" %in% names(data)) {
cli_abort("Error: 'data' does not contain the required 'parameter_class' column.")
}
# Check if there are any entries that match 'parameter_name' or 'parameter_class'
if (sum(data$parameter_type == parameter_name) == 0 &
sum(data$parameter_class == parameter_name) == 0) {
cli_abort("Error: No entries found matching the specified 'parameter_name'.
Check spelling and case of 'parameter name'.")
}
# if
if(parameter_name %in% data$parameter_type){
# Extract and return the matching rows
get_param <- data[data$parameter_type == parameter_name, , drop = FALSE]
} else if(parameter_name %in% data$parameter_class){
# Extract and return the matching rows
get_param <- data[data$parameter_class == parameter_name, , drop = FALSE]
}
get_param
}
#' Retrieve all incubation period parameters for a given pathogen
#'
#' @param data parameter dataframe output from \code{\link{load_epidata}}
#' @inheritParams get_key_columns
#' @return dataframe with all parameter estimates of this type and key columns
#' (see \code{\link{get_key_columns}})
#' @export
#' @name get_specific
#'
#' @examples
#' df <- load_epidata(pathogen = "lassa")
#' get_incubation_period(data = df$params, all_columns = FALSE)
get_incubation_period <- function(data, all_columns){
get_key_columns(
get_parameter(data,"Human delay - incubation period"),
"delays",
all_columns
)
}
#' Retrieve all serial interval estimates for a given pathogen
#' @name get_specific
#' @inheritParams get_key_columns
get_serial_interval <- function(data, all_columns){
get_key_columns(
get_parameter(data,"Human delay - serial interval"),
"delays",
all_columns
)
}
#' Retrieve all generation time estimates for a given pathogen
#' @inheritParams get_key_columns
#' @name get_specific
get_generation_time <- function(data, all_columns){
get_key_columns(
get_parameter(data,"Human delay - generation time"),
"delays",
all_columns
)
}
#' Retrieve all delay parameters for a given pathogen
#'@name get_specific
#'@inheritParams get_key_columns
get_delays <- function(data, all_columns){
get_key_columns(
get_parameter(data,"Human delay"),
"delays",
all_columns
)
}
#' Retrieve all CFR parameters for a given pathogen
#'@name get_specific
get_cfr <- function(data, all_columns){
get_key_columns(
get_parameter(data,"Severity - case fatality rate (CFR)"),
"cfr",
all_columns
)
}
#' Retrieve all risk factor parameters for a given pathogen
#'@inheritParams get_key_columns
#'@name get_specific
get_risk_factors <- function(data, all_columns){
get_key_columns(
get_parameter(data,"Risk factors"),
"risk_factors",
all_columns
)
}
#' Retrieve all genomic parameters for a given pathogen
#'@inheritParams get_key_columns
#'@name get_specific
get_genomic <- function(data, all_columns){
get_key_columns(
get_parameter(data,"Mutations"),
"genoomic",
all_columns
)
}
#' Retrieve all reproduction number parameters for a given pathogen
#'@inheritParams get_key_columns
#'@name get_specific
get_reproduction_number <- function(data, all_columns){
get_key_columns(
get_parameter(data,"Reproduction number"),
"reproduction_number",
all_columns
)
}
#' Retrieve all seroprevalence parameters for a given pathogen
#' @inheritParams get_key_columns
#' @name get_specific
get_seroprevalence <- function(data, all_columns){
get_key_columns(
get_parameter(data,"Seroprevalence"),
"sero",
all_columns
)
}
#' Retrieve all doubling time parameters for a given pathogen
#' @inheritParams get_key_columns
#' @name get_specific
get_doubling_time <- function(data, all_columns){
get_key_columns(
get_parameter(data,"Doubling time"),
"doubling_time",
all_columns
)
}
#' Retrieve all attack rate parameters for a given pathogen
#' @inheritParams get_key_columns
#' @name get_specific
get_attack_rate <- function(data, all_columns){
get_key_columns(
get_parameter(data,"Attack rate"),
"attack_rate",
all_columns
)
}
#' Retrieve all growth rate parameters for a given pathogen
#' @inheritParams get_key_columns
#' @name get_specific
get_growth_rate <- function(data, all_columns){
get_key_columns(
get_parameter(data,"Growth rate (r)"),
"growth_rate",
all_columns
)
}
#' Retrieve all overdispersion parameters for a given pathogen
#' @inheritParams get_key_columns
#' @name get_specific
get_overdispersion <- function(data, all_columns){
get_key_columns(
get_parameter(data,"Overdispersion"),
"overdispersion",
all_columns
)
}
#' Retrieve all overdispersion parameters for a given pathogen
#' @inheritParams get_key_columns
#' @name get_specific
get_relative_contribution <- function(data, all_columns){
get_key_columns(
get_parameter(data,"Relative contribution"),
"relative_contribution",
all_columns
)
}