knitr::opts_chunk$set( collapse = TRUE, warning = FALSE, message = FALSE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" ) knitr::opts_chunk$set(fig.width=10, fig.height=4) options(tidyverse.quiet = TRUE)
Disclaimer
This package is a work in progress. It has been released to get feedback from users that we can incorporate in future releases.
The goal of incidenceflow
is to provide tidy workflows using incidence
and EpiEstim
with tidyverse
and purrr
.
if(!require("remotes")) install.packages("remotes") remotes::install_github("avallecam/incidenceflow")
Here are two basic examples which shows you how to solve common problems:
library(incidenceflow) ## basic example code
get_info_tidy
: generates a tibble of incidence::get_info()
. click here for more information.tidy_incidence
: generates a complete summary tibble from incidence fit paramteter estimatesglance_incidence
: generates a complete summary tibble from incidence fit model performance# packages ---------------------------------------------------------------- if(!require("devtools")) install.packages("devtools") # if(!require("avallecam")) devtools::install_github("avallecam/avallecam") #improvements library(tidyverse) #magrittr and purrr packages library(lubridate) #ymd library(outbreaks) #sample data library(incidence) #core functions # example outbreak -------------------------------------------------------- dat <- ebola_sim$linelist$date_of_onset i.7 <- incidence(dat, interval=7) # plot(i.7) f1 <- fit(i.7[1:20]) f2 <- fit_optim_split(i.7) # broom like functions ---------------------------------------------------- # tidy f1 %>% tidy_incidence() f2 %>% pluck("fit") %>% tidy_incidence() # glance f1 %>% glance_incidence() f2 %>% pluck("fit") %>% glance_incidence() # using purrr ------------------------------------------------------------- # using purrr::map family function allows easy stratification # for gender and could be extrapolated to administrative levels # in country level analysis incidence_purrr <- ebola_sim$linelist %>% as_tibble() %>% #filter observations explicitly before incidence() filter(date_of_onset<lubridate::ymd(20141007)) %>% #stratify by any group of covariates group_by(gender) %>% nest() %>% mutate(incidence_strata=map(.x = data, .f = ~incidence(.x %>% pull(date_of_onset), interval=7))) %>% mutate(strata_fit=map(.x = incidence_strata, .f = possibly(fit,NA_real_) )) %>% mutate(strata_fit_tidy=map(.x = strata_fit, .f = possibly(tidy_incidence,tibble()))) %>% mutate(strata_fit_glance=map(.x = strata_fit, .f = possibly(glance_incidence,tibble()))) # keep only the tibbles incidence_purrr_tibble <- incidence_purrr %>% select(-data,-incidence_strata,-strata_fit) # tidy_incidence output incidence_purrr_tibble %>% unnest(cols = c(strata_fit_tidy)) # glance_incidence output incidence_purrr_tibble %>% unnest(cols = c(strata_fit_glance))
learnr
tutorial# install package if(!require("remotes")) install.packages("remotes") remotes::install_github("avallecam/incidenceflow") # install learner and run tutorial if(!require("learnr")) install.packages("learnr") learnr::run_tutorial(name = "taller",package = "incidenceflow")
create_nest_dynamics
: estimate Rt per stratacreate_nest_summary
: create figure and tables of incidence and Rtlinelist_raw <- ebola_sim$linelist %>% as_tibble() %>% #filter observations explicitly before incidence() # filter(date_of_onset<lubridate::ymd(20141007)) %>% mutate(all="all") dictionary <- linelist_raw %>% count(all,gender) %>% rownames_to_column(var = "code") # linelist_raw %>% # group_by(gender) %>% # skimr::skim()
time_delay_set = 7 #### execute ------------------------------- nest_dynamics <- create_nest_dynamics(linelist = linelist_raw, dictionary = dictionary, strata_major = all, strata_minor = gender, strata_minor_code = code, # unico para diccionario date_incidence_case = date_of_onset, date_of_analysis_today=FALSE, issue_number_set = 0) nest_dynamics #nest_dynamics %>% glimpse()
#### nested figures ------------------------------- nest_summary <- create_nest_summary(nest_dynamics = nest_dynamics, time_limit_fig02 = Inf) nest_summary #%>% glimpse()
#### if a shapefile is available ---------------------- # nest_summary <- create_nest_summary_map(nest_dynamics = nest_dynamics, # geometry = ubigeo_geometria_per2, # strata_major=nm_pais, # strata_minor=nm_depa)
#### if you want to write it ------------------------- # rt_write_rds(nest_summary = nest_summary, # rute = "", # name = "admx")
region_name <- "all" nest_summary %>% filter(strata_major==region_name) %>% pull(fig01) %>% pluck(1) nest_summary %>% filter(strata_major==region_name) %>% pull(fig02) %>% pluck(1) nest_summary %>% filter(strata_major==region_name) %>% pull(fig03) %>% pluck(1) # nest_summary %>% # filter(strata_major==region_name) %>% # pull(fig04) %>% pluck(1) nest_summary %>% filter(strata_major==region_name) %>% pull(tab01) %>% pluck(1) nest_summary %>% filter(strata_major==region_name) %>% pull(tab02) %>% pluck(1) nest_summary %>% filter(strata_major==region_name) %>% pull(tab03) %>% pluck(1) nest_summary %>% filter(strata_major==region_name) %>% pull(tab04) %>% pluck(1)
on incidence: https://github.com/reconhub/incidence2
on time-varying transmission: https://epiforecasts.io/EpiNow2/
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.