An epiflows object contains a pair of data frames that provide information about locations and flows between locations.

make_epiflows(...)

# S3 method for data.frame
make_epiflows(flows, locations = NULL, from = 1L,
  to = 2L, n = 3L, id = 1L, ...)

# S3 method for integer
make_epiflows(inflow, outflow, focus, locations,
  id = 1L, ...)

# S3 method for numeric
make_epiflows(inflow, outflow, focus, locations,
  id = 1L, ...)

Arguments

...

Any number of varaibles that can be used for mapping or modelling. See global_vars() and get_vars() for details.

flows

a data frame where each row represents a flow from one location to the next. This must have at least three columns:

  • Where the flow started (as specified in from, below)

  • Where the flow ended (as specified in to, below)

  • How many cases were involved (as specified in n, below)

locations

a data frame where each row represents a location. This can have any number of columns specifying useful metadata about the location, but it must contain at least one column specifying the location ID used in the flows data frame (as specified by the id argument, below).

from

the column in the flows data frame indicating where the flow started. This can be an integer or character. Default is the first column.

to

the column in the flows data frame indicating where the flow terminated. This can be an integer or character. Default is the second column.

n

the column in the flows data frame indicating how many cases were contained in the flow. This can be an integer or character. Default is the third column.

id

The column to use for the identifier in the locations data frame. This defaults to the first column.

inflow

a named integer or numeric vector specifying the number of cases flowing into a location specified by focus.

outflow

a named integer or numeric vector specifying the number of cases flowing from a location specified by focus.

focus

a character vector specifying the focal location for integer input. This is necessary for integer input to make clear what "outflow" and "inflow" are relative to.

Value

An epiflows object in list format with four elements:

  • locations (accessible via get_locations()): a data frame of locations with first column 'id' containing character vector of unique identifiers.

  • flows (accessible via get_flows()): data.frame of flows with first two columns named 'from' and 'to' indicating directed flows between two locations, and a third column named 'n', specifying the number of cases in each

  • vars (accessible via get_vars()). This contains a named list of available variables that can be used in further plotting and/or modelling. Default variables are found in global_vars():

    • 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

Details

The epiflows object can be constructed using simply a list of locations with optional metadata (similar to a linelist) and a list of flows that describes the number of cases flowing from one location to another. Optional metadata such as coordinates and duration of stay can be included in the linelist for use in estimate_risk_spread() or map_epiflows().

Developer note: object structure

Because a flow of cases from one location to another can be thought of as a contact with a wider scope, the epiflows object inherits from the epicontacts object, constructed via epicontacts::make_epicontacts(). This means that all the methods for subsetting an object of class epicontacts also applies to epiflows, including the use of the function epicontacts::thin(). One caveat is that, internally, the names of the elements within the object do not match the terminology used in epiflows.

See also

global_vars() for definitions of global variables, estimate_risk_spread() for modelling, plot.epiflows() for plotting, add_coordinates() for adding coordinates, get_vars() for accession of metadata, get_locations() to access the locations data frame, get_flows() to access the flows data frame.

Examples

## Load data data(YF_flows) data(YF_locations) YF_flows
#> from to n #> 1 Espirito Santo Italy 2827.572 #> 2 Minas Gerais Italy 15714.103 #> 3 Rio de Janeiro Italy 8163.938 #> 4 Sao Paulo Italy 34038.681 #> 5 Southeast Brazil Italy 76281.763 #> 6 Espirito Santo Spain 3270.500 #> 7 Minas Gerais Spain 18175.655 #> 8 Rio de Janeiro Spain 9442.787 #> 9 Sao Paulo Spain 39370.707 #> 10 Southeast Brazil Spain 88231.000 #> 11 Espirito Santo Portugal 3264.182 #> 12 Minas Gerais Portugal 18140.543 #> 13 Rio de Janeiro Portugal 9424.545 #> 14 Sao Paulo Portugal 39294.650 #> 15 Southeast Brazil Portugal 88060.554 #> 16 Espirito Santo Germany 1897.668 #> 17 Minas Gerais Germany 10546.202 #> 18 Rio de Janeiro Germany 5479.062 #> 19 Sao Paulo Germany 22844.371 #> 20 Southeast Brazil Germany 51194.959 #> 21 Espirito Santo United Kingdom 1985.482 #> 22 Minas Gerais United Kingdom 11034.228 #> 23 Rio de Janeiro United Kingdom 5732.606 #> 24 Sao Paulo United Kingdom 23901.496 #> 25 Southeast Brazil United Kingdom 53564.010 #> 26 Espirito Santo United States of America 13597.386 #> 27 Minas Gerais United States of America 75566.853 #> 28 Rio de Janeiro United States of America 39259.202 #> 29 Sao Paulo United States of America 163687.109 #> 30 Southeast Brazil United States of America 366827.995 #> 31 Espirito Santo Argentina 5898.905 #> 32 Minas Gerais Argentina 32782.895 #> 33 Rio de Janeiro Argentina 17031.678 #> 34 Sao Paulo Argentina 71011.787 #> 35 Southeast Brazil Argentina 159139.665 #> 36 Espirito Santo Chile 2794.168 #> 37 Minas Gerais Chile 15528.462 #> 38 Rio de Janeiro Chile 8067.493 #> 39 Sao Paulo Chile 33636.561 #> 40 Southeast Brazil Chile 75380.598 #> 41 Espirito Santo Uruguay 2629.526 #> 42 Minas Gerais Uruguay 14613.472 #> 43 Rio de Janeiro Uruguay 7592.129 #> 44 Sao Paulo Uruguay 31654.581 #> 45 Southeast Brazil Uruguay 70938.918 #> 46 Espirito Santo Paraguay 1164.344 #> 47 Minas Gerais Paraguay 6470.791 #> 48 Rio de Janeiro Paraguay 3361.766 #> 49 Sao Paulo Paraguay 14016.531 #> 50 Southeast Brazil Paraguay 31411.489 #> 51 Italy Espirito Santo 1566.257 #> 52 Spain Espirito Santo 1170.954 #> 53 Portugal Espirito Santo 1258.379 #> 54 Germany Espirito Santo 1740.967 #> 55 United Kingdom Espirito Santo 1467.435 #> 56 United States of America Espirito Santo 4464.246 #> 57 Argentina Espirito Santo 16125.229 #> 58 Chile Espirito Santo 2375.037 #> 59 Uruguay Espirito Santo 2072.586 #> 60 Paraguay Espirito Santo 2340.148 #> 61 Italy Minas Gerais 9196.588 #> 62 Spain Minas Gerais 6875.487 #> 63 Portugal Minas Gerais 7388.819 #> 64 Germany Minas Gerais 10222.433 #> 65 United Kingdom Minas Gerais 8616.336 #> 66 United States of America Minas Gerais 26212.701 #> 67 Argentina Minas Gerais 94682.455 #> 68 Chile Minas Gerais 13945.500 #> 69 Uruguay Minas Gerais 12169.597 #> 70 Paraguay Minas Gerais 13740.640 #> 71 Italy Rio de Janeiro 4812.885 #> 72 Spain Rio de Janeiro 3598.175 #> 73 Portugal Rio de Janeiro 3866.818 #> 74 Germany Rio de Janeiro 5349.744 #> 75 United Kingdom Rio de Janeiro 4509.219 #> 76 United States of America Rio de Janeiro 13717.991 #> 77 Argentina Rio de Janeiro 49550.524 #> 78 Chile Rio de Janeiro 7298.151 #> 79 Uruguay Rio de Janeiro 6368.761 #> 80 Paraguay Rio de Janeiro 7190.941 #> 81 Italy Sao Paulo 19950.571 #> 82 Spain Sao Paulo 14915.302 #> 83 Portugal Sao Paulo 16028.896 #> 84 Germany Sao Paulo 22175.981 #> 85 United Kingdom Sao Paulo 18691.803 #> 86 United States of America Sao Paulo 56864.386 #> 87 Argentina Sao Paulo 205398.888 #> 88 Chile Sao Paulo 30252.597 #> 89 Uruguay Sao Paulo 26400.052 #> 90 Paraguay Sao Paulo 29808.186 #> 91 Italy Southeast Brazil 41998.783 #> 92 Spain Southeast Brazil 31398.827 #> 93 Portugal Southeast Brazil 33743.100 #> 94 Germany Southeast Brazil 46683.586 #> 95 United Kingdom Southeast Brazil 39348.898 #> 96 United States of America Southeast Brazil 119707.601 #> 97 Argentina Southeast Brazil 432393.802 #> 98 Chile Southeast Brazil 63686.009 #> 99 Uruguay Southeast Brazil 55575.856 #> 100 Paraguay Southeast Brazil 62750.462
YF_locations
#> location_code location_population num_cases_time_window #> 1 Espirito Santo 3973697 2600 #> 2 Minas Gerais 20997560 4870 #> 3 Rio de Janeiro 16635996 170 #> 4 Sao Paulo 44749699 200 #> 5 Southeast Brazil 86356952 7840 #> 6 Argentina NA NA #> 7 Chile NA NA #> 8 Germany NA NA #> 9 Italy NA NA #> 10 Paraguay NA NA #> 11 Portugal NA NA #> 12 Spain NA NA #> 13 United Kingdom NA NA #> 14 United States of America NA NA #> 15 Uruguay NA NA #> first_date_cases last_date_cases length_of_stay #> 1 2017-01-04 2017-04-30 NA #> 2 2016-12-19 2017-04-20 NA #> 3 2017-02-19 2017-05-10 NA #> 4 2016-12-17 2017-04-20 NA #> 5 2016-12-17 2017-05-10 NA #> 6 <NA> <NA> 10.9 #> 7 <NA> <NA> 10.3 #> 8 <NA> <NA> 22.3 #> 9 <NA> <NA> 30.1 #> 10 <NA> <NA> 7.3 #> 11 <NA> <NA> 27.2 #> 12 <NA> <NA> 27.2 #> 13 <NA> <NA> 19.5 #> 14 <NA> <NA> 18.5 #> 15 <NA> <NA> 8.0
## Use both to create the epiflows object. 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 #>
# Access variable information get_pop_size(ef)
#> Espirito Santo Minas Gerais Rio de Janeiro #> 3973697 20997560 16635996 #> Sao Paulo Southeast Brazil Argentina #> 44749699 86356952 NA #> Chile Germany Italy #> NA NA NA #> Paraguay Portugal Spain #> NA NA NA #> United Kingdom United States of America Uruguay #> NA NA NA
get_vars(ef, "duration_stay")
#> id length_of_stay #> 1 Espirito Santo NA #> 2 Minas Gerais NA #> 3 Rio de Janeiro NA #> 4 Sao Paulo NA #> 5 Southeast Brazil NA #> 6 Argentina 10.9 #> 7 Chile 10.3 #> 8 Germany 22.3 #> 9 Italy 30.1 #> 10 Paraguay 7.3 #> 11 Portugal 27.2 #> 12 Spain 27.2 #> 13 United Kingdom 19.5 #> 14 United States of America 18.5 #> 15 Uruguay 8.0
get_vars(ef, "num_cases")
#> id num_cases_time_window #> 1 Espirito Santo 2600 #> 2 Minas Gerais 4870 #> 3 Rio de Janeiro 170 #> 4 Sao Paulo 200 #> 5 Southeast Brazil 7840 #> 6 Argentina NA #> 7 Chile NA #> 8 Germany NA #> 9 Italy NA #> 10 Paraguay NA #> 11 Portugal NA #> 12 Spain NA #> 13 United Kingdom NA #> 14 United States of America NA #> 15 Uruguay NA
data(YF_Brazil) (inflows <- YF_Brazil$T_O["Espirito Santo", , drop = TRUE])
#> Italy Spain Portugal #> 1566.257 1170.954 1258.379 #> Germany United Kingdom United States of America #> 1740.967 1467.435 4464.246 #> Argentina Chile Uruguay #> 16125.229 2375.037 2072.586 #> Paraguay #> 2340.148
(outflows <- YF_Brazil$T_D["Espirito Santo", , drop = TRUE])
#> Italy Spain Portugal #> 2827.572 3270.500 3264.182 #> Germany United Kingdom United States of America #> 1897.668 1985.482 13597.386 #> Argentina Chile Uruguay #> 5898.905 2794.168 2629.526 #> Paraguay #> 1164.344
(locations <- subset(YF_Brazil$states, location_code == "Espirito Santo", drop = FALSE))
#> location_code location_population num_cases_time_window #> Espirito Santo Espirito Santo 3973697 2600 #> first_date_cases last_date_cases #> Espirito Santo 2017-01-04 2017-04-30
los <- data.frame(location_code = names(YF_Brazil$length_of_stay), length_of_stay = YF_Brazil$length_of_stay, stringsAsFactors = FALSE ) locations <- merge(x = locations, y = los, by = "location_code", all = TRUE) ef <- make_epiflows(inflow = inflows, outflow = outflows, focus = "Espirito Santo", locations = 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 #> // 11 locations; 20 flows; directed #> // optional variables: pop_size, duration_stay, num_cases, first_date, last_date #> #> // locations #> #> # A tibble: 11 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 Italy NA NA <NA> <NA> #> 3 Spain NA NA <NA> <NA> #> 4 Port… NA NA <NA> <NA> #> 5 Germ… NA NA <NA> <NA> #> 6 Unit… NA NA <NA> <NA> #> 7 Unit… NA NA <NA> <NA> #> 8 Arge… NA NA <NA> <NA> #> 9 Chile NA NA <NA> <NA> #> 10 Urug… NA NA <NA> <NA> #> 11 Para… NA NA <NA> <NA> #> # ... with 1 more variable: length_of_stay <dbl> #> #> // flows #> #> # A tibble: 20 x 3 #> from to n #> <chr> <chr> <dbl> #> 1 Espirito Santo Italy 2828. #> 2 Espirito Santo Spain 3270. #> 3 Espirito Santo Portugal 3264. #> 4 Espirito Santo Germany 1898. #> 5 Espirito Santo United Kingdom 1985. #> 6 Espirito Santo United States of America 13597. #> 7 Espirito Santo Argentina 5899. #> 8 Espirito Santo Chile 2794. #> 9 Espirito Santo Uruguay 2630. #> 10 Espirito Santo Paraguay 1164. #> 11 Italy Espirito Santo 1566. #> 12 Spain Espirito Santo 1171. #> 13 Portugal Espirito Santo 1258. #> 14 Germany Espirito Santo 1741. #> 15 United Kingdom Espirito Santo 1467. #> 16 United States of America Espirito Santo 4464. #> 17 Argentina Espirito Santo 16125. #> 18 Chile Espirito Santo 2375. #> 19 Uruguay Espirito Santo 2073. #> 20 Paraguay Espirito Santo 2340. #>