df_cases_ch1_23 <- df23 |>
filter(medi_cen %in% c("Bệnh viện Nhi đồng 1",
"Bênh viện Nhi Đồng 1",
"Bệnh viện Nhi Đồng 1"))
## fig 2C
ts_ch1 <- df_cases_ch1_23 %>%
group_by(adm_week,wave) %>%
count() %>%
ggplot(aes(x = adm_week, y = n,fill = wave))+
geom_col(alpha = 0.6,color="black")+
scale_x_date(date_breaks = "1 month",
date_labels = "%b %Y",
name = "Collection date",
limits = c(as.Date("2023-01-01"),as.Date("2023-12-31")))+
scale_y_continuous(limits = c(0,900),breaks = seq(0,900,le = 4))+
scale_fill_manual(values = c("#582C83FF","#FFC72CFF"))+
theme_minimal()+
annotate("rect", fill = "grey",
xmin = as.Date(c("2023-01-01","2023-04-05","2023-08-02","2023-12-06")),
xmax = as.Date(c("2023-01-15","2023-04-26","2023-08-30","2023-12-27")),
ymin = 0, ymax = Inf, alpha = .5)+
labs(y = "Cases")+
theme(axis.title.y = element_text(size = 18),
axis.title.x = element_blank(),
axis.ticks.x = element_blank(),
legend.position = "bottom",
plot.tag = element_text(face = "bold", size = 18),
axis.text.x = element_blank(),
axis.text.y = element_text(size = 18),
legend.text = element_text(size = 15),
legend.title = element_text(size = 18))+
guides(fill=guide_colourbar(barwidth=20),
color = "none")
## fig 2D
df_cases_count_ch1_23 <- df_cases_ch1_23 |>
group_by(age,time) |>
count() |>
ungroup()
fit_gau_bs_ch1 <- gam(n ~ s(age,bs = "bs") +
s(time,bs = "bs") +
ti(age, time, bs = c("bs", "bs")) , data = df_cases_count_ch1_23,
family = gaussian(link = "log"),method = "REML")
age_val <- seq(0,6,le = 365)
collection_date_val <- seq(min(df23$adm_week),
max(df23$adm_week), le = 365)
new_data2 <- expand.grid(age = age_val,
time = as.numeric(collection_date_val))
new_data2$pred_gau_bs_ch1 <- predict(fit_gau_bs_ch1, newdata = new_data2, type = "response")
hm_ch1 <- ggplot(new_data2) +
geom_raster(aes(x = as.Date(time), y = age, fill = pred_gau_bs_ch1),interpolate = TRUE) +
geom_line(
data = cohort_lines(),
aes(x = date, y = age, group = cohort,color = trend),
linewidth = 0.3,
alpha = 0.4
)+
scale_x_date(date_breaks = "1 month", date_labels = "%b") +
scale_fill_viridis_c(option = "turbo", n.breaks = 10) +
theme_minimal() +
labs(
x = "Admission date",
y = "Age (years)",
fill = "Number of\nadmissions",
tag = "D"
)+
theme_minimal()+
scale_y_reverse(name = "Age (years)",lim= rev(c(-0.5,6.5)),breaks = seq(-1,7))+
theme(axis.title.y = element_text(size = 18),
axis.title.x = element_blank(),
axis.ticks.x = element_blank(),
legend.position = "bottom",
plot.tag = element_text(face = "bold", size = 18),
axis.text.x = element_blank(),
axis.text.y = element_text(size = 18),
legend.text = element_text(size = 15),
legend.title = element_text(size = 18))+
guides(fill=guide_colourbar(barwidth=25),
color = "none")
## calculate atk rate as a function of time
df_sero <- df_sero |>
as_tibble() |>
mutate(collection = id |>
str_remove(".*-") |>
as.numeric() |>
divide_by(1e4) |>
round(),
col_date2 = as.numeric(col_date),
across(pos, ~ .x > 0))
outttt <- age_profile_constrained_cohort2(df_sero)
## fig 2E
atk_sero <- map2(head(outttt, -15),
tail(outttt,-15),
~ left_join(na.exclude(.x), na.exclude(.y), "cohort")|>
mutate(attack = (fit.y - fit.x) / (1 - fit.x),
date = as.Date(collection_time.y))) |>
bind_rows() |>
ggplot() +
geom_raster(aes(x=date, y=cohort,fill = attack),interpolate = TRUE)+
geom_line(
data = cohort_lines(seq(0,15,by=1)),
aes(x = date, y = age, group = cohort,color = trend),
linewidth = 0.25,
alpha = 0.3
)+
scale_fill_viridis_c(option = "turbo",name = "Attack rate")+
theme_void()+
scale_y_reverse(name = "Age (years)",lim= rev(c(0,14)),breaks = seq(0,14,by=2))+
scale_x_date(date_breaks = "1 month",
date_labels = "%b",
name = "Collection date in 2023",
limits = c(as.Date("2023-01-01"),as.Date("2023-12-31")))+
theme(axis.title.y = element_text(size = 18),
axis.title.x = element_text(size = 18),
axis.ticks.x = element_blank(),
plot.tag = element_text(face = "bold", size = 18),
axis.text.x = element_text(size = 18),
axis.text.y = element_text(size = 18),
legend.text = element_text(size = 15),
legend.title = element_text(size = 18))+
guides(color = "none")
## fig 2B
age_profile_sp_cm <- outttt |>
bind_rows() |>
mutate(col_date = as.Date(collection_time)) |>
filter(col_date %in% as.Date(c("2022-12-29","2023-04-11","2023-08-13","2023-12-31"))) |>
mutate(col_lab = format(col_date, format = "%b %Y"),
col_lab = factor(col_lab,levels = c("Dec 2022","Apr 2023","Aug 2023","Dec 2023"))) |>
ggplot(aes(x = cohort,y = fit))+
geom_line()+
geom_ribbon(aes(ymin = lwr,ymax = upr),fill = "blue", alpha = .3)+
geom_point(data = df_sero |>
mutate(col_lab = factor(col_time,levels = c("Dec 2022","Apr 2023",
"Aug 2023","Dec 2023"))),
aes(x = age, y = pos),shape = "|")+
facet_wrap(~ col_lab,nrow = 1)+
labs(y = "Seroprevalence (%)",x = "Age (years)",tag="B")+
scale_y_continuous(labels = scales::label_percent(scale = 100),limits = c(0,1))+
theme_bw()+
theme(axis.title.x = element_text(size = 18),
axis.text.x = element_text(size = 18),
legend.position = "none",
plot.tag = element_text(face = "bold", size = 18),
axis.title.y = element_text(size = 18),
axis.text.y = element_text(size = 18),
strip.text.x = element_text(size = 18))
## fig 1A
ouut <- list()
dat <- list()
for (i in 1:3){
dat[[i]] <- df_cases_ch1_23 |>
filter(adm_date >= as.Date(mean_collection_times[i]) &
adm_date <= as.Date(mean_collection_times[i+1]))
}
expected_incidence <- map2(head(outttt, -15),
tail(outttt,-15),
~ left_join(na.exclude(.x), na.exclude(.y), "cohort")|>
mutate(attack = (fit.y - fit.x) / (1 - fit.x),
date = as.Date(collection_time.y))) |>
bind_rows() |>
filter(date %in% as.Date(c("2023-04-11","2023-08-13","2023-12-31"))) |>
mutate(period = case_when(
date <= as.Date("2023-04-30") ~ "12/2022 - 4/2023",
date > as.Date("2023-04-30") & date <= as.Date("2023-08-31") ~ "4/2023 - 8/2023",
date > as.Date("2023-08-31") ~ "8/2023 - 12/2023"
)) |>
group_by(period) |>
group_split() |>
map(~ left_join(.x,expected_age_cm, by = join_by(cohort == age,period))) %>%
bind_rows(.id = "id") |>
mutate(sp_gap = fit.y-fit.x,
exp_inc = sp_gap*value)
exp_in_ch1 <- expected_incidence |>
ggplot()+
geom_line(aes(x = cohort,y = exp_inc))+
geom_histogram(data = dat %>% bind_rows(.id = "id") %>% filter(age1 >0),
aes(age1),binwidth = 0.5,
color = "white",fill = "black",alpha = 0.2)+
facet_wrap(~factor(id,labels = c("12/2022 - 4/2023",
"4/2023 - 8/2023",
"8/2023 - 12/2023")))+
labs(y = "Expected incidence",x = "Age (years)",tag = "A")+
coord_cartesian(ylim = c(0,1200))+
theme_bw()+
theme(
axis.text.x = element_text(size = 15),
axis.text.y = element_text(size = 18),
legend.text = element_text(size = 18),
plot.tag = element_text(face = "bold", size = 18),
axis.title.x = element_text(size = 18),
axis.title.y = element_text(size = 18),
legend.title = element_text(size = 18),
strip.text = element_text(size = 18),
panel.grid.minor.x = element_blank())