Skip to content

Instantly share code, notes, and snippets.

@avallecam
Last active July 11, 2024 22:58
Show Gist options
  • Save avallecam/58f2245cb2e1afff622d30f45647eb07 to your computer and use it in GitHub Desktop.
Save avallecam/58f2245cb2e1afff622d30f45647eb07 to your computer and use it in GitHub Desktop.
Usar {incidence2} y {dplyr} para adaptar datos de casos con {EpiNow2} y {cfr}
``` r
if(!require("pak")) install.packages("pak")
new_packages <- c(
"incidence2",
"outbreaks",
"tidyverse"
)
pak::pkg_install(new_packages)
library(incidence2)
library(outbreaks)
library(tidyverse)
# base de datos de casos (tambien llamada linelist)
mers_korea_2015$linelist %>% as_tibble()
#> # A tibble: 162 × 15
#> id age age_class sex place_infect reporting_ctry loc_hosp dt_onset
#> <chr> <int> <chr> <fct> <fct> <fct> <fct> <date>
#> 1 SK_1 68 60-69 M Middle East South Korea Pyeongt… 2015-05-11
#> 2 SK_2 63 60-69 F Outside Middl… South Korea Pyeongt… 2015-05-18
#> 3 SK_3 76 70-79 M Outside Middl… South Korea Pyeongt… 2015-05-20
#> 4 SK_4 46 40-49 F Outside Middl… South Korea Pyeongt… 2015-05-25
#> 5 SK_5 50 50-59 M Outside Middl… South Korea 365 Yeo… 2015-05-25
#> 6 SK_6 71 70-79 M Outside Middl… South Korea Pyeongt… 2015-05-24
#> 7 SK_7 28 20-29 F Outside Middl… South Korea Pyeongt… 2015-05-21
#> 8 SK_8 46 40-49 F Outside Middl… South Korea Seoul C… 2015-05-26
#> 9 SK_9 56 50-59 M Outside Middl… South Korea Pyeongt… NA
#> 10 SK_10 44 40-49 M Outside Middl… China Pyeongt… 2015-05-21
#> # ℹ 152 more rows
#> # ℹ 7 more variables: dt_report <date>, week_report <fct>, dt_start_exp <date>,
#> # dt_end_exp <date>, dt_diag <date>, outcome <fct>, dt_death <date>
mers_incidence <- mers_korea_2015$linelist %>%
# transformar de linelist a incidencia usando {incidence2}
incidence2::incidence(
date_index = "dt_onset",
complete_dates = TRUE
) %>%
# seleccionar y renonmbrar columnas usando {dplyr} para {EpiNow2}
dplyr::select(date = date_index, confirm = count)
mers_incidence
#> date confirm
#> 1 2015-05-11 1
#> 2 2015-05-12 0
#> 3 2015-05-13 0
#> 4 2015-05-14 0
#> 5 2015-05-15 0
#> 6 2015-05-16 0
#> 7 2015-05-17 1
#> 8 2015-05-18 1
#> 9 2015-05-19 0
#> 10 2015-05-20 5
#> 11 2015-05-21 6
#> 12 2015-05-22 2
#> 13 2015-05-23 4
#> 14 2015-05-24 2
#> 15 2015-05-25 3
#> 16 2015-05-26 1
#> 17 2015-05-27 2
#> 18 2015-05-28 1
#> 19 2015-05-29 3
#> 20 2015-05-30 5
#> 21 2015-05-31 10
#> 22 2015-06-01 16
#> 23 2015-06-02 11
#> 24 2015-06-03 7
#> 25 2015-06-04 12
#> 26 2015-06-05 9
#> 27 2015-06-06 7
#> 28 2015-06-07 7
#> 29 2015-06-08 6
#> 30 2015-06-09 1
#> 31 2015-06-10 6
#> 32 2015-06-11 3
#> 33 2015-06-12 0
#> 34 2015-06-13 2
#> 35 2015-06-14 0
#> 36 2015-06-15 1
```
<sup>Created on 2024-07-11 with [reprex v2.1.0](https://reprex.tidyverse.org)</sup>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment