Skip to contents

Function to be used with risk table to add risk columns. The risk table is designed to store all risks associated with a riskintro study.

Usage

add_risk(risk_table, risk_data, cols = NULL, scale = NULL, join_by = "eu_id")

Arguments

risk_table

a risk table initialised with risk_table()

risk_data

a data.frame or risk analysis table containing the risk column to be added to the risk table and the joining column (usually eu_id).

cols

risk columns in risk_data to add to risk_table.

scale

risk scale for cols in risk_data, should be a numeric vector of length 2. For example, c(0, 100).

join_by

Name of column to be used to join risk_data to risk_table.#'

Value

the intial risk table with the new risk column added.

See also

Other risk-table: remove_risk(), risk_table()

Examples


library(riskintrodata)
library(riskintroanalysis)

# Get epi_units dataset
tunisia_raw <- sf::read_sf(system.file(
  package = "riskintrodata",
  "samples", "tunisia", "epi_units", "tunisia_adm2_raw.gpkg"
))

# Apply mapping to prepare colnames and validate dataset
tunisia <- apply_mapping(
  tunisia_raw,
  mapping = mapping_epi_units(
    eu_name = "NAME_2",
    geometry = "geom"
  ),
  validate = TRUE
)
#>  All data in "epi_units" valided.

# Create risk table
rt <- risk_table(tunisia, scale = c(0, 100))

# Create risk
entry_points_fp <-
  system.file(
    package = "riskintrodata",
    "samples",
    "tunisia",
    "entry_points", "BORDER_CROSSING_POINTS.csv"
  )

entry_points <- readr::read_csv(entry_points_fp)
#> Rows: 110 Columns: 6
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (4): NAME, TYPE, MODE, SOURCES
#> dbl (2): LONGITUDE_X, LATITUDE_Y
#> 
#>  Use `spec()` to retrieve the full column specification for this data.
#>  Specify the column types or set `show_col_types = FALSE` to quiet this message.
entry_points <- apply_mapping(
  dataset = entry_points,
  mapping = mapping_entry_points(
    point_name = "NAME",
    lng = "LONGITUDE_X",
    lat = "LATITUDE_Y",
    mode = "MODE",
    type = "TYPE",
    sources = "SOURCES"
  ),
  validate = TRUE
)
#>  All data in "entry_points" valided.

ri_entry_points <- calc_entry_point_risk(
  entry_points = entry_points,
  epi_units = tunisia,
  emission_risk =
    calc_emission_risk(
      emission_risk_factors = get_wahis_erf(
        disease = "Anthrax",
        species = "Cattle",
        animal_category = "Domestic"
      )
    )
) |>
  rescale_risk_scores()
#>  All data in "emission_risk_factors" valided.
#>  WAHIS emission risk factors dataset has 65 entries for `disease = Anthrax`, `species = Cattle`, and `animal_category = Domestic`.
#> Warning: ! There are missing emission risk scores for the following countries:
#>  BIH missing for 1 entry points.
#>  BRN missing for 1 entry points.
#>  DZA missing for 44 entry points.
#>  ESP missing for 1 entry points.
#>  FRA missing for 1 entry points.
#>  HUN missing for 2 entry points.
#>  ISR missing for 1 entry points.
#>  LBY missing for 12 entry points.
#>  MAR missing for 1 entry points.
#>  NOR missing for 1 entry points.
#>  PER missing for 1 entry points.
#>  PHL missing for 1 entry points.
#>  VNM missing for 1 entry points.
#>  ZAF missing for 1 entry points.
#> Create new entries in the emission risk factor table using `erf_row()`
#> (`?riskintrodata::erf_row()`).

rt <- add_risk(risk_table = rt, risk_data = ri_entry_points)
rt
#> Simple feature collection with 268 features and 3 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 7.530076 ymin: 30.23681 xmax: 11.59826 ymax: 37.55986
#> Geodetic CRS:  WGS 84
#> # A tibble: 268 × 4
#>    eu_id    eu_name                                   geometry entry_points_risk
#>    <chr>    <chr>                           <MULTIPOLYGON [°]>             <dbl>
#>  1 eu-00001 Ariana Médina      (((10.13861 36.89453, 10.14495…                NA
#>  2 eu-00002 Ettadhamen         (((10.05585 36.84308, 10.06575…                NA
#>  3 eu-00003 Kalaat El Andalous (((10.13862 36.89416, 10.1329 …                NA
#>  4 eu-00004 Mnihla             (((10.1317 36.88428, 10.1317 3…                NA
#>  5 eu-00005 Raoued             (((10.16651 36.88694, 10.16422…                NA
#>  6 eu-00006 Sebkhet Ariana     (((10.27118 36.88874, 10.26842…                NA
#>  7 eu-00007 Sidi Thabet        (((10.01018 37.00285, 10.0102 …                NA
#>  8 eu-00008 Soukra             (((10.19313 36.85656, 10.19313…                NA
#>  9 eu-00009 Amdoun             (((9.141866 36.86897, 9.140129…                NA
#> 10 eu-00010 Béja Nord          (((9.086732 36.70221, 9.082556…                NA
#> # ℹ 258 more rows

rt <- remove_risk(rt, cols = "entry_points_risk")
rt
#> Simple feature collection with 268 features and 2 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 7.530076 ymin: 30.23681 xmax: 11.59826 ymax: 37.55986
#> Geodetic CRS:  WGS 84
#> # A tibble: 268 × 3
#>    eu_id    eu_name                                                     geometry
#>    <chr>    <chr>                                             <MULTIPOLYGON [°]>
#>  1 eu-00001 Ariana Médina      (((10.13861 36.89453, 10.14495 36.89476, 10.1512…
#>  2 eu-00002 Ettadhamen         (((10.05585 36.84308, 10.06575 36.85019, 10.0732…
#>  3 eu-00003 Kalaat El Andalous (((10.13862 36.89416, 10.1329 36.88994, 10.13283…
#>  4 eu-00004 Mnihla             (((10.1317 36.88428, 10.1317 36.88271, 10.1317 3…
#>  5 eu-00005 Raoued             (((10.16651 36.88694, 10.16422 36.88874, 10.1576…
#>  6 eu-00006 Sebkhet Ariana     (((10.27118 36.88874, 10.26842 36.88874, 10.2614…
#>  7 eu-00007 Sidi Thabet        (((10.01018 37.00285, 10.0102 37.00285, 10.01045…
#>  8 eu-00008 Soukra             (((10.19313 36.85656, 10.19313 36.85892, 10.1931…
#>  9 eu-00009 Amdoun             (((9.141866 36.86897, 9.140129 36.86767, 9.13747…
#> 10 eu-00010 Béja Nord          (((9.086732 36.70221, 9.082556 36.70772, 9.07813…
#> # ℹ 258 more rows