The metadata in locations such as population size, duration of stay in a given location, date of first and last cases, etc. can be useful in estimating the risk of spread, but not everyone will code their data with identical column names. To facilitate their use in the function estimate_risk_spread(), the epiflows object stores a dictionary of variables in a place called $vars. We can tell epiflows what variables are important when we create the object.

global_vars(..., set = FALSE, reset = FALSE)

Arguments

...

quoted varaibles to add to the default variables

set

when TRUE, the variables provided in ... will be added to the global variables. Defaults to FALSE

reset

when TRUE, the global variables are reset to the default variables listed above. Defaults to FALSE

Details

The default varaibles are:

  • coordinates: two columns specifying the lon and lat coordinates

  • pop_size: population size of each location

  • duration_stay: the average duration of stay for each location

  • first_date: the date of first recorded case

  • last_date: the date of the last recorded case

  • num_cases: the number of cases between the first and last date

See also

Examples

# see the default varaibles global_vars()
#> [1] "coordinates" "pop_size" "duration_stay" "first_date" #> [5] "last_date" "num_cases"
# Equivalent getOption("epiflows.vars")
#> [1] "coordinates" "pop_size" "duration_stay" "first_date" #> [5] "last_date" "num_cases"
# create an object, specifying these variables data("YF_locations") data("YF_flows") ef <- make_epiflows(flows = YF_flows, locations = YF_locations, pop_size = "location_population", duration_stay = "length_of_stay", num_cases = "num_cases_time_window", first_date = "first_date_cases", last_date = "last_date_cases" ) ef
#> #> /// Epidemiological Flows // #> #> // class: epiflows, epicontacts #> // 15 locations; 100 flows; directed #> // optional variables: pop_size, duration_stay, num_cases, first_date, last_date #> #> // locations #> #> # A tibble: 15 x 6 #> id location_popula… num_cases_time_… first_date_cases last_date_cases #> * <chr> <dbl> <dbl> <fct> <fct> #> 1 Espi… 3973697 2600 2017-01-04 2017-04-30 #> 2 Mina… 20997560 4870 2016-12-19 2017-04-20 #> 3 Rio … 16635996 170 2017-02-19 2017-05-10 #> 4 Sao … 44749699 200 2016-12-17 2017-04-20 #> 5 Sout… 86356952 7840 2016-12-17 2017-05-10 #> 6 Arge… NA NA <NA> <NA> #> 7 Chile NA NA <NA> <NA> #> 8 Germ… NA NA <NA> <NA> #> 9 Italy NA NA <NA> <NA> #> 10 Para… NA NA <NA> <NA> #> 11 Port… NA NA <NA> <NA> #> 12 Spain NA NA <NA> <NA> #> 13 Unit… NA NA <NA> <NA> #> 14 Unit… NA NA <NA> <NA> #> 15 Urug… NA NA <NA> <NA> #> # ... with 1 more variable: length_of_stay <dbl> #> #> // flows #> #> # A tibble: 100 x 3 #> from to n #> <chr> <chr> <dbl> #> 1 Espirito Santo Italy 2828. #> 2 Minas Gerais Italy 15714. #> 3 Rio de Janeiro Italy 8164. #> 4 Sao Paulo Italy 34039. #> 5 Southeast Brazil Italy 76282. #> 6 Espirito Santo Spain 3270. #> 7 Minas Gerais Spain 18176. #> 8 Rio de Janeiro Spain 9443. #> 9 Sao Paulo Spain 39371. #> 10 Southeast Brazil Spain 88231. #> # ... with 90 more rows #>
# You will receive an error if a variable is specified incorrectly YF_locations$random_variable <- runif(nrow(YF_locations)) try({ ef <- make_epiflows(flows = YF_flows, locations = YF_locations, Pop_size = "location_population", duration_stay = "length_of_stay", num_cases = "num_cases_time_window", first_date = "first_date_cases", last_date = "last_date_cases", random = "random_variable" ) })
# If you create a new method and need other varaibles, or just want a shorter # representation, they can be added to your options: global_vars("random", set = TRUE)
#> [1] "coordinates" "pop_size" "duration_stay" "first_date" #> [5] "last_date" "num_cases" "random"
YF_locations$random_variable <- runif(nrow(YF_locations)) ef <- make_epiflows(flows = YF_flows, locations = YF_locations, pop_size = "location_population", duration_stay = "length_of_stay", num_cases = "num_cases_time_window", first_date = "first_date_cases", last_date = "last_date_cases", random = "random_variable" ) # You can also reset the variables global_vars(reset = TRUE)
#> [1] "coordinates" "pop_size" "duration_stay" "first_date" #> [5] "last_date" "num_cases"