cases_within_radius: Check Cases Within Radius

View source: R/cases_within_radius.R

cases_within_radiusR Documentation

Check Cases Within Radius

Description

Based on the postcodes4_afstanden data set, this function determines the specified minimum number of cases within a certain radius.

Usage

cases_within_radius(
  data,
  radius_km = 10,
  minimum_cases = 10,
  column_count = NULL,
  ...
)

Arguments

data

data set containing a column 'postcode'

radius_km

radius in kilometres from each zip code. The search diameter is twice this number (since zip codes e.g. to the west and to the east are searched).

minimum_cases

minimum number of cases to search for

column_count

column name in data with the number of case counts, defaults to the first column with numeric values

...

ignored, allows for future extensions

Value

This function adds two columns ("cases_within_radius" ⁠<dbl>⁠ and "minimum_met" ⁠<lgl>⁠) to the input data.

Examples

library(dplyr, warn.conflicts = FALSE)

postcodes_friesland <- geo_postcodes4 |> 
  filter_geolocation(provincie == "Friesland") |> 
  pull(postcode)

# example with Norovirus cases:
noro <- data.frame(postcode = postcodes_friesland,
                   n = floor(runif(length(postcodes_friesland),
                                   min = 0, max = 3)))
head(noro)

radial_check <- cases_within_radius(noro, radius_km = 10, minimum_cases = 10)
head(radial_check)


# dplyr group support:
mdro <- data.frame(type = rep(c("ESBL", "MRSA", "VRE"), 20),
                   pc4 = postcodes_friesland[1:20],
                   n = floor(runif(60, min = 0, max = 3)))
mdro |> 
  group_by(type) |> 
  cases_within_radius()
  
  
# plotting support:
if (require("certeplot2")) {

  radial_check |>
    add_map() |>
    filter_geolocation(provincie == "Friesland") |>
    plot2(category = cases_within_radius,
          category.title = "Cases",
          datalabels = FALSE,
          colour_fill = "viridis")

}

certe-medical-epidemiology/certegis documentation built on Dec. 10, 2024, 6:27 a.m.