@@ -182,216 +182,15 @@ Write your answers to the questions above:
182182
183183##### Ebola (sample)
184184
185- ``` {r}
186- #| warning: false
187- #| eval: false
188-
189- # Load packages -----------------------------------------------------------
190- library(epiparameter)
191- library(EpiNow2)
192- library(tidyverse)
193-
194- # Read reported cases -----------------------------------------------------
195- dat_ebola <- readr::read_rds(
196- "https://epiverse-trace.github.io/tutorials-middle/data/ebola_35days.rds" #<DIFFERENT PER GROUP>
197- ) %>%
198- dplyr::select(date, confirm = cases)
199-
200- # Define a generation time from {epiparameter} to {EpiNow2} ---------------
201-
202- # access a serial interval
203- ebola_serialint <- epiparameter::epiparameter_db(
204- disease = "ebola",
205- epi_name = "serial",
206- single_epiparameter = TRUE
207- )
208-
209- # extract parameters from {epiparameter} object
210- ebola_serialint_params <- epiparameter::get_parameters(ebola_serialint)
211-
212- # adapt {epiparameter} to {EpiNow2} distribution inferfase
213- # preferred
214- ebola_generationtime <- EpiNow2::Gamma(
215- shape = ebola_serialint_params["shape"],
216- scale = ebola_serialint_params["scale"]
217- )
218- # or
219- ebola_generationtime <- EpiNow2::Gamma(
220- mean = ebola_serialint$summary_stats$mean,
221- sd = ebola_serialint$summary_stats$sd
222- )
223-
224-
225- # Define the delays from infection to case report for {EpiNow2} -----------
226-
227- # define delay from symptom onset to case report
228- # or reporting delay
229- ebola_reportdelay <- EpiNow2::LogNormal(
230- meanlog = EpiNow2::Normal(mean = 1.4, sd = 0.5),
231- sdlog = EpiNow2::Normal(mean = 0.25, sd = 0.2),
232- max = 5
233- )
234-
235- # define a delay from infection to symptom onset
236- # or incubation period
237- ebola_incubationtime <- epiparameter::epiparameter_db(
238- disease = "ebola",
239- epi_name = "incubation",
240- single_epiparameter = TRUE
241- )
242-
243- # incubation period: extract distribution parameters
244- ebola_incubationtime_params <- epiparameter::get_parameters(
245- ebola_incubationtime
246- )
247-
248- # incubation period: discretize and extract maximum value (p = 99%)
249- # preferred
250- ebola_incubationtime_max <- ebola_incubationtime %>%
251- epiparameter::discretise() %>%
252- quantile(p = 0.99)
253- # or
254- ebola_incubationtime_max <- ebola_incubationtime %>%
255- quantile(p = 0.99) %>%
256- base::round()
257-
258- # incubation period: adapt to {EpiNow2} distribution interface
259- ebola_incubationtime_epinow <- EpiNow2::Gamma(
260- shape = ebola_incubationtime_params["shape"],
261- scale = ebola_incubationtime_params["scale"],
262- max = ebola_incubationtime_max
263- )
264-
265- # collect required input
266- ebola_generationtime
267- ebola_reportdelay
268- ebola_incubationtime_epinow
269-
270-
271- # Set the number of parallel cores for {EpiNow2} --------------------------
272- withr::local_options(list(mc.cores = parallel::detectCores() - 1))
273-
274-
275- # Estimate transmission using EpiNow2::epinow() ---------------------------
276- # with EpiNow2::*_opts() functions for generation time, delays, and stan.
277- ebola_estimates <- EpiNow2::epinow(
278- data = dat_ebola,
279- generation_time = EpiNow2::generation_time_opts(ebola_generationtime),
280- delays = EpiNow2::delay_opts(ebola_incubationtime_epinow + ebola_reportdelay),
281- stan = EpiNow2::stan_opts(samples = 1000, chains = 3)
282- )
283-
185+ ``` {r, file = "fig/02-practical-instructor-1-G2.R", eval = FALSE}
284186
285- # Print plot and summary table outputs ------------------------------------
286- summary(ebola_estimates)
287- plot(ebola_estimates)
288187```
289188
290- ##### COVID (sample)
291-
292- ``` {r}
293- #| warning: false
294- #| eval: false
295-
296- # Load packages -----------------------------------------------------------
297- library(epiparameter)
298- library(EpiNow2)
299- library(tidyverse)
300-
301- # Read reported cases -----------------------------------------------------
302- dat_covid <- read_rds(
303- "https://epiverse-trace.github.io/tutorials-middle/data/covid_30days.rds" #<DIFFERENT PER GROUP>
304- ) %>%
305- dplyr::select(date, confirm)
306-
307- # Define a generation time from {epiparameter} to {EpiNow2} ---------------
308-
309- # access a serial interval
310- covid_serialint <- epiparameter::epiparameter_db(
311- disease = "covid",
312- epi_name = "serial",
313- single_epiparameter = TRUE
314- )
315-
316- # extract parameters from {epiparameter} object
317- covid_serialint_params <- epiparameter::get_parameters(covid_serialint)
318-
319- # adapt {epiparameter} to {EpiNow2} distribution inferfase
320- # preferred
321- covid_generationtime <- EpiNow2::LogNormal(
322- meanlog = covid_serialint_params["meanlog"],
323- sdlog = covid_serialint_params["sdlog"]
324- )
325- # or
326- covid_generationtime <- EpiNow2::LogNormal(
327- mean = covid_serialint$summary_stats$mean,
328- sd = covid_serialint$summary_stats$sd
329- )
330-
331-
332- # Define the delays from infection to case report for {EpiNow2} -----------
333-
334- # define delay from symptom onset to case report
335- # or reporting delay
336- covid_reportdelay <- EpiNow2::Gamma(
337- mean = EpiNow2::Normal(mean = 2, sd = 0.5),
338- sd = EpiNow2::Normal(mean = 1, sd = 0.5),
339- max = 5
340- )
341-
342- # define a delay from infection to symptom onset
343- # or incubation period
344- covid_incubationtime <- epiparameter::epiparameter_db(
345- disease = "covid",
346- epi_name = "incubation",
347- single_epiparameter = TRUE
348- )
349-
350- # incubation period: extract distribution parameters
351- covid_incubationtime_params <- epiparameter::get_parameters(
352- covid_incubationtime
353- )
354-
355- # incubation period: discretize and extract maximum value (p = 99%)
356- # preferred
357- covid_incubationtime_max <- covid_incubationtime %>%
358- epiparameter::discretise() %>%
359- quantile(p = 0.99)
360- # or
361- ebola_incubationtime_max <- covid_incubationtime %>%
362- quantile(p = 0.99) %>%
363- base::round()
364-
365- # incubation period: adapt to {EpiNow2} distribution interface
366- covid_incubationtime_epinow <- EpiNow2::LogNormal(
367- meanlog = covid_incubationtime_params["meanlog"],
368- sdlog = covid_incubationtime_params["sdlog"],
369- max = covid_incubationtime_max
370- )
371-
372- # collect required input
373- covid_generationtime
374- covid_reportdelay
375- covid_incubationtime_epinow
376189
190+ ##### COVID (sample)
377191
378- # Set the number of parallel cores for {EpiNow2} --------------------------
379- withr::local_options(list(mc.cores = parallel::detectCores() - 1))
380-
381-
382- # Estimate transmission using EpiNow2::epinow() ---------------------------
383- # with EpiNow2::*_opts() functions for generation time, delays, and stan.
384- covid_estimates <- EpiNow2::epinow(
385- data = dat_covid,
386- generation_time = EpiNow2::generation_time_opts(covid_generationtime),
387- delays = EpiNow2::delay_opts(covid_reportdelay + covid_incubationtime_epinow),
388- stan = EpiNow2::stan_opts(samples = 1000, chains = 3)
389- )
390-
192+ ``` {r, file = "fig/02-practical-instructor-1-G1.R", eval = FALSE}
391193
392- # Print plot and summary table outputs ------------------------------------
393- summary(covid_estimates)
394- plot(covid_estimates)
395194```
396195
397196#### Outputs
@@ -647,156 +446,14 @@ Write your answers to the questions above:
647446
648447##### COVID (sample)
649448
650- ``` {r}
651- #| warning: false
652- #| eval: false
653-
654- # Load packages -----------------------------------------------------------
655- library(cfr)
656- library(epiparameter)
657- library(tidyverse)
658-
659-
660- # Read reported cases -----------------------------------------------------
661- covid_dat <- read_rds(
662- "https://epiverse-trace.github.io/tutorials-middle/data/diamond_70days.rds"
663- )
664-
665- covid_dat
666-
667-
668- # Create incidence object ------------------------------------------------
669- covid_incidence <- covid_dat %>%
670- incidence2::incidence(
671- date_index = "date",
672- counts = c("cases", "deaths"),
673- complete_dates = TRUE
674- )
675-
676- plot(covid_incidence)
677-
678-
679- # Confirm {cfr} data input format ----------------------------------------
680-
681- # does input data already adapted to {cfr} input? Yes.
682- covid_adapted <- covid_dat
683- # does input data require to be adapted to {cfr}? No.
684- # covid_adapted <- covid_incidence %>%
685- # cfr::prepare_data(
686- # cases = "cases",
687- # deaths = "deaths"
688- # )
689-
690- covid_adapted
691-
692- # Access delay distribution -----------------------------------------------
693- covid_delay <- epiparameter::epiparameter_db(
694- disease = "covid",
695- epi_name = "onset-to-death",
696- single_epiparameter = TRUE
697- )
698-
699-
700- # Estimate naive and adjusted CFR ----------------------------------------
701-
702- # Estimate Static Delay-Adjusted CFR
703- covid_dat %>%
704- filter(
705- date < ymd(20200301)
706- ) %>%
707- cfr::cfr_static()
449+ ``` {r, file = "fig/02-practical-instructor-2-G1.R", eval = FALSE}
708450
709- # Estimate Static Delay-Adjusted CFR
710- covid_dat %>%
711- filter(
712- date < ymd(20200301)
713- ) %>%
714- cfr::cfr_static(
715- delay_density = function(x) density(covid_delay, x)
716- )
717-
718-
719- # CFR estimates in whole data --------------------------------------------
720-
721- # Estimate Static Delay-Adjusted CFR
722- covid_dat %>%
723- cfr::cfr_static()
724-
725- # Estimate Static Delay-Adjusted CFR
726- covid_dat %>%
727- cfr::cfr_static(
728- delay_density = function(x) density(covid_delay, x)
729- )
730451```
731452
732453##### MERS (sample)
733454
734- ``` {r}
735- #| warning: false
736- #| eval: false
737-
738- # Load packages -----------------------------------------------------------
739- library(cfr)
740- library(epiparameter)
741- library(tidyverse)
742-
743-
744- # Read reported cases -----------------------------------------------------
745- mers_dat <- readr::read_rds(
746- "https://epiverse-trace.github.io/tutorials-middle/data/mers_linelist.rds"
747- )
748-
749- mers_dat
750-
751-
752- # Create incidence object ------------------------------------------------
753- mers_incidence <- mers_dat %>%
754- incidence2::incidence(
755- date_index = c("dt_onset", "dt_death"),
756- complete_dates = TRUE
757- )
758-
759- plot(mers_incidence)
760-
761-
762- # Confirm {cfr} data input format ----------------------------------------
763-
764- # does input data already adapted to {cfr} input? No.
765- # mers_adapted <- mers_dat
766- # does input data require to be adapted to {cfr}? Yes.
767- mers_adapted <- mers_incidence %>%
768- cfr::prepare_data(
769- cases = "dt_onset",
770- deaths = "dt_death"
771- )
772-
773- mers_adapted
774-
775- # Access delay distribution -----------------------------------------------
776- mers_delay <- epiparameter::epiparameter_db(
777- disease = "mers",
778- epi_name = "onset-to-death",
779- single_epiparameter = TRUE
780- )
781-
782-
783- # Estimate naive and adjusted CFR ----------------------------------------
784-
785- # Estimate Static CFR
786- mers_adapted %>%
787- # filter(
788- # #<COMPLETE>
789- # ) %>%
790- cfr::cfr_static()
455+ ``` {r, file = "fig/02-practical-instructor-2-G2.R", eval = FALSE}
791456
792- # Estimate Static Delay-Adjusted CFR
793- mers_adapted %>%
794- # filter(
795- # #<COMPLETE>
796- # ) %>%
797- cfr::cfr_static(
798- delay_density = function(x) density(mers_delay, x)
799- )
800457```
801458
802459#### Outputs
0 commit comments