Skip to content

Commit 3c276d2

Browse files
committed
source commit: b425700
0 parents  commit 3c276d2

File tree

89 files changed

+17589
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+17589
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.quarto/

01-practical-activity-1.R

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# nolint start
2+
3+
# Practical 1
4+
# Activity 1
5+
6+
# Load packages ----------------------------------------------------------
7+
library(cleanepi)
8+
library(linelist)
9+
library(incidence2)
10+
library(tidyverse)
11+
12+
13+
# Adapt the data dictionary ----------------------------------------------
14+
15+
# replace 'variable_name' when you have the information
16+
dat_dictionary <- tibble::tribble(
17+
~options, ~values, ~grp, ~orders,
18+
"1", "male", "variable_name", 1L,
19+
"2", "female", "variable_name", 2L,
20+
"M", "male", "variable_name", 3L,
21+
"F", "female", "variable_name", 4L,
22+
"m", "male", "variable_name", 5L,
23+
"f", "female", "variable_name", 6L
24+
)
25+
26+
dat_dictionary
27+
28+
29+
# Read raw data ----------------------------------------------------------
30+
dat_raw <- readr::read_csv(
31+
#<COMPLETE>
32+
)
33+
34+
dat_raw
35+
36+
37+
# Clean and standardize data ---------------------------------------------
38+
39+
# how many cleanepi functions you used to get clean data?
40+
dat_clean <- dat_raw %>%
41+
cleanepi::#<COMPLETE>
42+
43+
dat_clean
44+
45+
46+
# Create time span variable ----------------------------------------------
47+
48+
# what time span unit better describe 'delay' from 'onset' to 'death'?
49+
dat_timespan <- dat_clean %>%
50+
cleanepi::timespan(
51+
#<COMPLETE>
52+
#<COMPLETE>
53+
#<COMPLETE>
54+
span_column_name = "timespan_variable",
55+
span_remainder_unit = NULL
56+
) %>%
57+
# skimr::skim(timespan_variable)
58+
# categorize the delay numerical variable
59+
dplyr::mutate(
60+
timespan_category = base::cut(
61+
x = timespan_variable,
62+
breaks = #<COMPLETE>,
63+
include.lowest = TRUE,
64+
right = FALSE
65+
)
66+
)
67+
68+
dat_timespan
69+
70+
71+
# nolint end

01-practical-activity-2.R

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# nolint start
2+
3+
# Practical 1
4+
# Activity 2
5+
6+
# Validate linelist ------------------------------------------------------
7+
8+
# activate Error message
9+
linelist::lost_tags_action(action = "error")
10+
# linelist::lost_tags_action(action = "warning")
11+
12+
# print tags types, names, and data to guide make_linelist
13+
linelist::tags_types()
14+
linelist::tags_names()
15+
dat_timespan
16+
17+
# does the age variable pass the validation step?
18+
dat_validate <- dat_timespan %>%
19+
# tag variables
20+
linelist::make_linelist(
21+
#<COMPLETE>
22+
occupation = "timespan_category" # categorical var.
23+
) %>%
24+
# validate linelist
25+
linelist::#<COMPLETE> %>%
26+
# test safeguard
27+
# dplyr::select(case_id, date_onset, sex)
28+
# INSTEAD
29+
linelist::tags_df()
30+
31+
32+
# Create incidence -------------------------------------------------------
33+
34+
# what is the most appropriate time-aggregate (days, months) to plot?
35+
dat_incidence <- dat_validate %>%
36+
# transform from individual-level to time-aggregate
37+
incidence2::incidence(
38+
date_index = #<COMPLETE>,
39+
groups = "occupation", #OR any categorical variable
40+
interval = #<COMPLETE>,
41+
complete_dates = TRUE
42+
)
43+
44+
45+
# Plot epicurve ----------------------------------------------------------
46+
47+
# does using arguments like 'fill', 'show_cases', 'angle', 'n_breaks' improve the plot?
48+
dat_incidence %>%
49+
plot(
50+
fill = "occupation", #<KEEP OR DROP>
51+
show_cases = TRUE, #<KEEP OR DROP>
52+
angle = 45, #<KEEP OR DROP>
53+
n_breaks = 5 #<KEEP OR DROP>
54+
)
55+
56+
# find plot() arguments at ?incidence2:::plot.incidence2()
57+
58+
# nolint end

02-practical-activity-1.R

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# nolint start
2+
3+
# Practical 2
4+
# Activity 1
5+
6+
# Load packages -----------------------------------------------------------
7+
library(epiparameter)
8+
library(EpiNow2)
9+
library(tidyverse)
10+
11+
12+
# Read reported cases -----------------------------------------------------
13+
# for covid
14+
dat <- read_rds("paste/link/url/here/covid") %>%
15+
dplyr::select(date, confirm)
16+
# or
17+
# for ebola
18+
dat <- read_rds("paste/link/url/here/ebola") %>%
19+
dplyr::select(date, confirm = cases)
20+
21+
22+
# Define a generation time from {epiparameter} to {EpiNow2} ---------------
23+
24+
# access a serial interval
25+
ebola_serialint <- epiparameter::epiparameter_db(
26+
#<COMPLETE>
27+
)
28+
29+
# extract parameters from {epiparameter} object
30+
ebola_serialint_params <- epiparameter::#<COMPLETE>
31+
32+
# adapt {epiparameter} to {EpiNow2} distribution inferfase
33+
ebola_generationtime <- EpiNow2::#<COMPLETE>
34+
35+
36+
# Define the delays from infection to case report for {EpiNow2} -----------
37+
38+
# define delay from symptom onset to case report
39+
ebola_reportdelay <- EpiNow2::#<COMPLETE>
40+
41+
# define a delay from infection to symptom onset
42+
ebola_incubationtime <- epiparameter::epiparameter_db(
43+
#<COMPLETE>
44+
)
45+
46+
# incubation period: extract distribution parameters
47+
ebola_incubationtime_params <- epiparameter::#<COMPLETE>
48+
49+
# incubation period: discretize and extract maximum value (p = 99%)
50+
ebola_incubationtime_max <- ebola_incubationtime %>% #<COMPLETE>
51+
52+
# incubation period: adapt to {EpiNow2} distribution interface
53+
ebola_incubationtime_epinow <- EpiNow2::#<COMPLETE>
54+
55+
# print required input
56+
ebola_generationtime
57+
ebola_reportdelay
58+
ebola_incubationtime_epinow
59+
60+
61+
# Set the number of parallel cores for {EpiNow2} --------------------------
62+
withr::local_options(list(mc.cores = parallel::detectCores() - 1))
63+
64+
65+
# Estimate transmission using EpiNow2::epinow() ---------------------------
66+
# with EpiNow2::*_opts() functions for generation time, delays, and stan.
67+
estimates <- EpiNow2::epinow(
68+
data = dat,
69+
#<COMPLETE>
70+
stan = EpiNow2::stan_opts(samples = 1000, chains = 3)
71+
)
72+
73+
74+
# Print plot and summary table outputs ------------------------------------
75+
summary(estimates)
76+
plot(estimates)
77+
78+
79+
# nolint end

02-practical-activity-2.R

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# nolint start
2+
3+
# Practical 2
4+
# Activity 2
5+
6+
# Load packages -----------------------------------------------------------
7+
library(cfr)
8+
library(epiparameter)
9+
library(tidyverse)
10+
11+
12+
# Read reported cases -----------------------------------------------------
13+
disease_dat <- readr::read_rds(
14+
#<COMPLETE>
15+
)
16+
17+
disease_dat
18+
19+
20+
# Create incidence object ------------------------------------------------
21+
disease_incidence <- disease_dat %>%
22+
incidence2::incidence(
23+
#<COMPLETE>
24+
)
25+
26+
plot(disease_incidence)
27+
28+
29+
# Confirm {cfr} data input format ----------------------------------------
30+
31+
# does input data already adapted to {cfr} input?
32+
disease_adapted <- disease_dat
33+
# OR
34+
# does input data require to be adapted to {cfr}?
35+
disease_adapted <- disease_incidence %>%
36+
cfr::prepare_data(
37+
#<COMPLETE>
38+
)
39+
40+
disease_adapted
41+
42+
# Access delay distribution -----------------------------------------------
43+
disease_delay <- epiparameter::#<COMPLETE>
44+
45+
46+
# Estimate naive and adjusted CFR ----------------------------------------
47+
48+
# Estimate Static CFR
49+
disease_adapted %>%
50+
filter(
51+
#<COMPLETE>
52+
) %>%
53+
cfr::cfr_static()
54+
55+
# Estimate Static Delay-Adjusted CFR
56+
disease_adapted %>%
57+
filter(
58+
#<COMPLETE>
59+
) %>%
60+
cfr::cfr_static(
61+
delay_density = function(x) density(disease_delay, x)
62+
)
63+
64+
# nolint end

03-practical-activity-1.R

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# nolint start
2+
3+
# Practical 3
4+
# Activity 1
5+
6+
# Load packages -----------------------------------------------------------
7+
library(epicontacts)
8+
library(fitdistrplus)
9+
library(tidyverse)
10+
11+
12+
# Read linelist and contacts ----------------------------------------------
13+
dat_contacts <- readr::read_rds("link/to/contact/data/url")
14+
15+
dat_linelist <- readr::read_rds("link/to/linelist/data/url")
16+
17+
18+
# Create an epicontacts object -------------------------------------------
19+
epi_contacts <- epicontacts::#<COMPLETE>
20+
21+
# print output
22+
epi_contacts
23+
24+
# visualize the contact network
25+
contact_network <- epicontacts::#<COMPLETE>
26+
27+
# print output
28+
contact_network
29+
30+
31+
# Count secondary cases per subject in contacts and linelist --------
32+
secondary_cases <- epicontacts::#<COMPLETE>
33+
34+
# plot the histogram of secondary cases
35+
individual_reproduction_num <- secondary_cases %>%
36+
enframe() %>%
37+
ggplot(aes(value)) +
38+
geom_histogram(binwidth = 1) +
39+
labs(
40+
x = "Number of secondary cases",
41+
y = "Frequency"
42+
)
43+
44+
# print output
45+
individual_reproduction_num
46+
47+
48+
# Fit a negative binomial distribution -----------------------------------
49+
offspring_fit <- #<COMPLETE>
50+
51+
# print output
52+
offspring_fit
53+
54+
55+
# Estimate proportion of new cases from a cluster of secondary cases -----
56+
57+
# Set seed for random number generator
58+
set.seed(33)
59+
60+
# Estimate the proportion of new cases originating from
61+
# a transmission cluster of at least 5, 10, or 25 cases
62+
proportion_cases_by_cluster_size <- #<COMPLETE>
63+
64+
# print output
65+
proportion_cases_by_cluster_size
66+
67+
# nolint end

0 commit comments

Comments
 (0)