{"id":20131642,"url":"https://github.com/avallecam/incidenceflow","last_synced_at":"2025-08-24T17:37:30.302Z","repository":{"id":138785875,"uuid":"298454952","full_name":"avallecam/incidenceflow","owner":"avallecam","description":null,"archived":false,"fork":false,"pushed_at":"2021-07-08T19:14:52.000Z","size":111,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-13T08:47:05.642Z","etag":null,"topics":["incidence","outbreaks","tidyverse","workflow"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/avallecam.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":".github/SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-25T03:11:44.000Z","updated_at":"2021-07-08T19:14:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"5dcb6a7c-f9c9-46f5-b323-a7206d8909cc","html_url":"https://github.com/avallecam/incidenceflow","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avallecam%2Fincidenceflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avallecam%2Fincidenceflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avallecam%2Fincidenceflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avallecam%2Fincidenceflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avallecam","download_url":"https://codeload.github.com/avallecam/incidenceflow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241577072,"owners_count":19984940,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["incidence","outbreaks","tidyverse","workflow"],"created_at":"2024-11-13T20:49:42.063Z","updated_at":"2025-03-02T21:46:02.058Z","avatar_url":"https://github.com/avallecam.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\neditor_options: \n  chunk_output_type: console\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  warning = FALSE,\n  message = FALSE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\nknitr::opts_chunk$set(fig.width=10, fig.height=4)\noptions(tidyverse.quiet = TRUE)\n```\n\n\n\u003cbr\u003e\n**\u003cspan style=\"color: red;\"\u003eDisclaimer\u003c/span\u003e**\n\nThis package is a work in progress. It has been released to get feedback from \nusers that we can incorporate in future releases.\n\n# incidenceflow\n\n\u003c!-- badges: start --\u003e\n[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)\n[![CRAN status](https://www.r-pkg.org/badges/version/incidenceflow)](https://cran.r-project.org/package=incidenceflow)\n\u003c!-- badges: end --\u003e\n\nThe goal of `incidenceflow` is to provide tidy workflows using `incidence` and `EpiEstim` with `tidyverse` and `purrr`.\n\n## Installation\n\n\u003c!-- You can install the released version of incidenceflow from [CRAN](https://CRAN.R-project.org) with: --\u003e\n\n``` r\nif(!require(\"remotes\")) install.packages(\"remotes\")\nremotes::install_github(\"avallecam/incidenceflow\")\n```\n\n## Example\n\nHere are two basic examples which shows you how to solve common problems:\n\n```{r example}\nlibrary(incidenceflow)\n## basic example code\n```\n\n### Workflow 01\n\n- `get_info_tidy`: generates a tibble of `incidence::get_info()`. [click here for more information](https://www.repidemicsconsortium.org/incidence/index.html).\n- `tidy_incidence`: generates a complete summary tibble from incidence fit paramteter estimates\n- `glance_incidence`: generates a complete summary tibble from incidence fit model performance\n\n\n```{r}\n# packages ----------------------------------------------------------------\n\nif(!require(\"devtools\")) install.packages(\"devtools\")\n# if(!require(\"avallecam\")) devtools::install_github(\"avallecam/avallecam\") #improvements\n\nlibrary(tidyverse) #magrittr and purrr packages\nlibrary(lubridate) #ymd\nlibrary(outbreaks) #sample data\nlibrary(incidence) #core functions\n\n# example outbreak --------------------------------------------------------\n\ndat \u003c- ebola_sim$linelist$date_of_onset\ni.7 \u003c- incidence(dat, interval=7)\n# plot(i.7)\nf1 \u003c- fit(i.7[1:20])\nf2 \u003c- fit_optim_split(i.7)\n\n# broom like functions ----------------------------------------------------\n\n# tidy\nf1 %\u003e% tidy_incidence()\nf2 %\u003e% pluck(\"fit\") %\u003e% tidy_incidence()\n\n# glance\nf1 %\u003e% glance_incidence()\nf2 %\u003e% pluck(\"fit\") %\u003e% glance_incidence()\n\n\n# using purrr -------------------------------------------------------------\n\n# using purrr::map family function allows easy stratification\n# for gender and could be extrapolated to administrative levels\n# in country level analysis\n\nincidence_purrr \u003c- ebola_sim$linelist %\u003e% \n  as_tibble() %\u003e% \n  #filter observations explicitly before incidence()\n  filter(date_of_onset\u003clubridate::ymd(20141007)) %\u003e% \n  #stratify by any group of covariates\n  group_by(gender) %\u003e% \n  nest() %\u003e% \n  mutate(incidence_strata=map(.x = data,\n                              .f = ~incidence(.x %\u003e% pull(date_of_onset),\n                                              interval=7))) %\u003e% \n  mutate(strata_fit=map(.x = incidence_strata,\n                        .f = possibly(fit,NA_real_)\n                        )) %\u003e% \n  mutate(strata_fit_tidy=map(.x = strata_fit,\n                                  .f = possibly(tidy_incidence,tibble()))) %\u003e% \n  mutate(strata_fit_glance=map(.x = strata_fit,\n                                       .f = possibly(glance_incidence,tibble())))\n\n# keep only the tibbles\nincidence_purrr_tibble \u003c- incidence_purrr %\u003e% \n  select(-data,-incidence_strata,-strata_fit)\n\n# tidy_incidence output\nincidence_purrr_tibble %\u003e% \n  unnest(cols = c(strata_fit_tidy))\n\n# glance_incidence output\nincidence_purrr_tibble %\u003e% \n  unnest(cols = c(strata_fit_glance))\n```\n\n#### Run this as a `learnr` tutorial\n\n```r\n# install package\nif(!require(\"remotes\")) install.packages(\"remotes\")\nremotes::install_github(\"avallecam/incidenceflow\")\n# install learner and run tutorial\nif(!require(\"learnr\")) install.packages(\"learnr\")\nlearnr::run_tutorial(name = \"taller\",package = \"incidenceflow\")\n```\n\n\n### Workflow 02\n\n- `create_nest_dynamics`: estimate Rt per strata\n- `create_nest_summary`: create figure and tables of incidence and Rt\n\n```{r}\nlinelist_raw \u003c- ebola_sim$linelist %\u003e% \n  as_tibble() %\u003e% \n  #filter observations explicitly before incidence()\n  # filter(date_of_onset\u003clubridate::ymd(20141007)) %\u003e% \n  mutate(all=\"all\")\n\ndictionary \u003c- linelist_raw %\u003e% \n  count(all,gender) %\u003e% \n  rownames_to_column(var = \"code\")\n\n# linelist_raw %\u003e% \n#   group_by(gender) %\u003e% \n#   skimr::skim()\n```\n\n\n```{r}\ntime_delay_set = 7\n#### execute -------------------------------\n\nnest_dynamics \u003c- create_nest_dynamics(linelist = linelist_raw,\n                                      dictionary = dictionary,\n                                      strata_major = all,\n                                      strata_minor = gender,\n                                      strata_minor_code = code, # unico para diccionario\n                                      date_incidence_case = date_of_onset,\n                                      date_of_analysis_today=FALSE,\n                                      issue_number_set = 0)\n\nnest_dynamics #nest_dynamics %\u003e% glimpse()\n```\n\n```{r}\n#### nested figures -------------------------------\nnest_summary \u003c- create_nest_summary(nest_dynamics = nest_dynamics,\n                                    time_limit_fig02 = Inf)\n\nnest_summary #%\u003e% glimpse()\n```\n\n```{r}\n#### if a shapefile is available ----------------------\n# nest_summary \u003c- create_nest_summary_map(nest_dynamics = nest_dynamics,\n#                                                    geometry = ubigeo_geometria_per2,\n#                                                    strata_major=nm_pais,\n#                                                    strata_minor=nm_depa)\n```\n\n```{r,eval=FALSE,echo=FALSE}\n#### if you want to write it -------------------------\n# rt_write_rds(nest_summary = nest_summary,\n#              rute = \"\",\n#              name = \"admx\")\n```\n\n\n```{r}\nregion_name \u003c- \"all\"\n\nnest_summary %\u003e% \n  filter(strata_major==region_name) %\u003e% \n  pull(fig01) %\u003e% pluck(1)\nnest_summary %\u003e% \n  filter(strata_major==region_name) %\u003e% \n  pull(fig02) %\u003e% pluck(1)\nnest_summary %\u003e% \n  filter(strata_major==region_name) %\u003e% \n  pull(fig03) %\u003e% pluck(1)\n# nest_summary %\u003e% \n#   filter(strata_major==region_name) %\u003e% \n#   pull(fig04) %\u003e% pluck(1)\n\nnest_summary %\u003e% \n  filter(strata_major==region_name) %\u003e% \n  pull(tab01) %\u003e% pluck(1)\nnest_summary %\u003e% \n  filter(strata_major==region_name) %\u003e% \n  pull(tab02) %\u003e% pluck(1)\nnest_summary %\u003e% \n  filter(strata_major==region_name) %\u003e% \n  pull(tab03) %\u003e% pluck(1)\nnest_summary %\u003e% \n  filter(strata_major==region_name) %\u003e% \n  pull(tab04) %\u003e% pluck(1)\n```\n\n## Updated approaches\n\n- on incidence: https://github.com/reconhub/incidence2\n\n- on time-varying transmission: https://epiforecasts.io/EpiNow2/\n\n## To do list\n\n- Document functions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favallecam%2Fincidenceflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favallecam%2Fincidenceflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favallecam%2Fincidenceflow/lists"}