Skip to content

Commit 9fdc31b

Browse files
committed
Tiers version release
1 parent 3612969 commit 9fdc31b

10 files changed

Lines changed: 81401 additions & 3 deletions

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ nature/figures/*.pdf
8484
nature/results/*.RDS
8585
nature/figures/*.csv
8686
nature/results/*.csv
87-
88-
87+
tiers/figures
88+
tiers/results
89+
tiers/stan_models/*.rds
8990

9091
# Python
9192
# Byte-compiled / optimized / DLL files

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@
33
Code for modelling estimated deaths and infections for COVID-19 from ["Estimating the effects of non-pharmaceutical interventions on COVID-19 in Europe"](https://www.nature.com/articles/s41586-020-2405-7), Flaxman, Mishra, Gandy et al, Nature, 2020, the published version of our original [Report 13](https://www.imperial.ac.uk/mrc-global-infectious-disease-analysis/covid-19/report-13-europe-npi-impact/).
44

55
If you are looking for the individual based model used in Imperial's [Report 9, Ferguson, Laydon, Nedjati-Gilani et al](https://www.imperial.ac.uk/mrc-global-infectious-disease-analysis/covid-19/report-9-impact-of-npis-on-covid-19/), please look [here](https://github.com/mrc-ide/covid-sim).
6-
## Version 11 Release [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4461896.svg)](https://doi.org/10.5281/zenodo.4461896)
76

7+
## Version 12 Release [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4461896.svg)](https://doi.org/10.5281/zenodo.4461896)
8+
9+
This is the release related to our [Tiers paper](https://www.medrxiv.org/content/10.1101/2021.02.23.21252277v1), where we use latent factor model to estimate the effectiveness of tiers systems in England. **Peer reviewed version to be out soon.** All other code is still the same for previous releases.
10+
11+
To reproduce results of the paper either from Rstudio ``source("tiers/spline_LFA.R")`` or from the command line ``Rscript tiers/spline_LFA.R``.
12+
13+
The instructions for reproducing European report , Italy report , Brazil report , USA report , Nature, IFR, USA age specific report, Nature Communincations, and Science paper are the same as earlier (Look at version 3, version 4, version 5, version 6, version 7, version 8, version 9, version 10 and version 11). This release is specific to [Tiers paper](https://www.medrxiv.org/content/10.1101/2021.02.23.21252277v1).
814

15+
This release has been checked on macOS Catalina version 10.15.6/7 and Ubuntu version 18.04.2.
16+
17+
**The authors of version 12 Release are Daniel J Laydon, Swapnil Mishra, and Samir Bhatt**
18+
19+
## Version 11 Release [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4461896.svg)](https://doi.org/10.5281/zenodo.4461896)
920

1021
This is the release related to our [Science paper](https://science.sciencemag.org/content/early/2021/02/01/science.abe8372), where we use age-specific mobility data to estimate the epidemic in the USA by accounting for age-specific heterogeneity. All other code is still the same for previous releases.
1122

1.02 MB
Binary file not shown.

tiers/data/all_statc_combined.csv

Lines changed: 340 additions & 0 deletions
Large diffs are not rendered by default.

tiers/data/npis_23Mar_02Dec.csv

Lines changed: 80326 additions & 0 deletions
Large diffs are not rendered by default.

tiers/data/rt_covars_combined.rds

759 KB
Binary file not shown.
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
# No need to run this file; it is just provided for sake of giving an idea to people
2+
# what was done in paper in terms of pre-processing
3+
library(tidyr)
4+
library(dplyr)
5+
library(readr)
6+
library(janitor)
7+
library(lubridate)
8+
library(magrittr)
9+
library(ggpubr)
10+
library(tidyr)
11+
library(readxl)
12+
library(tools)
13+
library(ggplot2)
14+
library(flextable)
15+
library(stringr)
16+
library(here)
17+
18+
# Import .rds
19+
DATA <- read.csv(file = here('tiers/data/npis_23Mar_02Dec.csv'))
20+
DATA$date = as.Date(DATA$date, format = '%d/%m/%Y')
21+
22+
Earliest = TRUE # if true, assessing which interventions consitute tier X based on earliest date that Tier X introduced. If false, then based on latest date that Tier X applies.
23+
#Earliest = FALSE # if true, assessing which interventions consitute tier X based on earliest date that Tier X introduced. If false, then based on latest date that Tier X applies.
24+
25+
Interventions = c(
26+
27+
"limited_to_groups_of_6_indoors" ,
28+
"limited_to_groups_of_6_outdoors" ,
29+
"curfew_of_10pm_for_hospitality_venues" ,
30+
"instruction_to_work_from_home_where_possible" ,
31+
"travel_discouraged" ,
32+
"no_indoor_mixing" ,
33+
"overnight_stays_discouraged" ,
34+
"residents_cannot_leave_the_local_area" ,
35+
"non-essential_retail_closures" ,
36+
"schools_closed" ,
37+
"places_of_worship_closed" ,
38+
"weddings_not_allowed" ,
39+
"organised_sport_not_allowed" ,
40+
"tourist_attractions_closed" ,
41+
"gyms_closed" ,
42+
"public_buildings_closed" ,
43+
"personal_care_contact_services_closed" ,
44+
"arts_venues_closed" ,
45+
"sit-down_hospitality_closed_takeaway_only" ,
46+
"pubs_and_bars_closed_table_service_only" ,
47+
"essential_travel_only"
48+
)
49+
50+
# tibbles (apparently) better so re-write below you become familiar
51+
DATA = as.data.frame(DATA)
52+
str(DATA$date)
53+
54+
# how many ltlas?
55+
N_LTLAs = length(unique(DATA$ltla))
56+
57+
## Define nested tiers
58+
DATA$tier_3_nested = DATA$tier_3
59+
DATA$tier_2_nested = DATA$tier_2 + DATA$tier_3
60+
DATA$tier_1_nested = DATA$tier_1 + DATA$tier_2 + DATA$tier_3
61+
DATA$Tier = DATA$tier_1_nested + DATA$tier_2_nested + DATA$tier_3_nested
62+
63+
# Subset to post 11th September
64+
DATA_postSept = DATA[DATA$date >= as.Date("2020-09-11"),]
65+
66+
# check defs
67+
#TierDF = data.frame(date = DATA_postSept$date, TierCat = DATA_postSept$Tier,
68+
# tier_1 = DATA_postSept$tier_1, tier_2 = DATA_postSept$tier_2, tier_3 = DATA_postSept$tier_3,
69+
# tier_1_nested = DATA_postSept$tier_1_nested, tier_2_nested = DATA_postSept$tier_2_nested, tier_3_nested = DATA_postSept$tier_3_nested)
70+
## Statements below should be false.
71+
#all(DATA$tier_1[which(DATA$tier_2 == 1)] == 1)
72+
#all(DATA$tier_1[which(DATA$tier_3 == 1)] == 1)
73+
#all(DATA$tier_2[which(DATA$tier_3 == 1)] == 1)
74+
## Statements below should be true
75+
#all(DATA$tier_1_nested[which(DATA$tier_2_nested == 1)] == 1)
76+
#all(DATA$tier_1_nested[which(DATA$tier_3_nested == 1)] == 1)
77+
#all(DATA$tier_2_nested[which(DATA$tier_3_nested == 1)] == 1)
78+
79+
80+
# which interventions are included in Tiers 1, 2, and 3, at first date Tier introduced? i.e. for each ltla, which interventions are on when tier 1 is on, when tier 2 is on etc.
81+
Nested_Tier = 1
82+
ltla_index = 2
83+
84+
Tier_List = list()
85+
Tier_List[[1]] = matrix (0, nrow = length(Interventions), ncol = N_LTLAs)
86+
Tier_List[[2]] = matrix (0, nrow = length(Interventions), ncol = N_LTLAs)
87+
Tier_List[[3]] = matrix (0, nrow = length(Interventions), ncol = N_LTLAs)
88+
89+
for (Nested_Tier in 1:3) colnames(Tier_List[[Nested_Tier]]) = unique(DATA_postSept$ltla)
90+
91+
Interventions_ColNames = gsub("-", ".", Interventions) ## account for hypens in colnames.
92+
#all(Interventions %in% colnames(DATA))
93+
#all(Interventions_ColNames %in% colnames(DATA))
94+
95+
for (ltla_index in 1:N_LTLAs)
96+
{
97+
# subset to this LTLA
98+
DATA_ltla = DATA_postSept[DATA_postSept$ltla == unique(DATA_postSept$ltla)[ltla_index], ]
99+
100+
for (Nested_Tier in 1:3)
101+
if (any(DATA_ltla$Tier >= Nested_Tier)) # if this ltla was ever in this nested tier
102+
{
103+
EarliestDate = min(DATA_ltla$date[DATA_ltla$Tier >= Nested_Tier])
104+
LatestDate = max(DATA_ltla$date[DATA_ltla$Tier >= Nested_Tier])
105+
106+
if (Earliest) Date_dummy = EarliestDate else Date_dummy = LatestDate
107+
108+
# which interventions turned on at earliest/latest date? Add these to matrix
109+
Tier_List[[Nested_Tier]][which(DATA_ltla[DATA_ltla$date == Date_dummy, Interventions_ColNames] == 1), ltla_index] = 1
110+
}
111+
}
112+
113+
114+
#### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### ####
115+
#### Make plots of interventions by region and tier.
116+
#### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### ####
117+
118+
dir.create(here("tiers/figures/"), showWarnings = FALSE)
119+
120+
AllPlotsInSameFigure = TRUE
121+
#AllPlotsInSameFigure = FALSE
122+
123+
if (Earliest) Suffix = "_Earliest" else Suffix = "_Latest"
124+
125+
if (AllPlotsInSameFigure)
126+
{
127+
pdf(here(paste0("tiers/figures/IntsByRegion_Tiers_123", Suffix, ".pdf")), height = 10, width = 24)
128+
par(mfrow = c(1,3), mar = c(10.1, 25.1, 4.1, 2.1))
129+
CEXLAB = 2; CEX_Text = 1.75; CEXMAIN = 2.5; CEXAXIS = 1.75
130+
131+
} else { CEXLAB = 1.25; CEX_Text = 1; CEXMAIN = 1; CEXAXIS = 1 }
132+
133+
if (AllPlotsInSameFigure) Alpha = 1 else Alpha = 0.6
134+
135+
COLS = c("green", "orange", "red")
136+
adjCOLS = adjustcolor(c("green", "orange", "red"), alpha.f = Alpha)
137+
138+
labs <- gsub("_", " ", Interventions)
139+
140+
141+
# Tier 1 only
142+
if (!AllPlotsInSameFigure)
143+
{
144+
png(here(paste0("tiers/figures/IntsByRegion_Tier_1", Suffix, ".png")), units = "in", res = 200, height = 10, width = 7.5)
145+
par(mar = c(8.1, 13.1, 4.1, 2.1))
146+
LetterChar = ""
147+
} else LetterChar = "(A) "
148+
x <- barplot(rowSums(Tier_List[[1]]), horiz = TRUE, col = adjCOLS[1], border = NA, cex.main = CEXMAIN, cex.axis = CEXAXIS,
149+
main = paste0(LetterChar, "Interventions by region (Tier 1)"), xlab = "Num LTLAs where intervention applied", cex.lab = CEXLAB)
150+
text(x = -7, y = x, labs, xpd = TRUE, srt = 45, adj = 1, cex = CEX_Text)
151+
if (!AllPlotsInSameFigure) dev.off()
152+
153+
# Tier 2 only
154+
if (!AllPlotsInSameFigure)
155+
{
156+
png(here(paste0("tiers/figures/IntsByRegion_Tier_2", Suffix, ".png")), units = "in", res = 200, height = 10, width = 7.5)
157+
par(mar = c(8.1, 13.1, 4.1, 2.1))
158+
LetterChar = ""
159+
} else LetterChar = "(B) "
160+
x <- barplot(rowSums(Tier_List[[2]]), horiz = TRUE, col = adjCOLS[2], border = NA, cex.main = CEXMAIN,cex.axis = CEXAXIS,
161+
main = paste0(LetterChar, "Interventions by region (Tier 2)"), xlab = "Num LTLAs where intervention applied", cex.lab = CEXLAB)
162+
text(x = -7, y = x, labs, xpd = TRUE, srt = 45, adj = 1, cex = CEX_Text)
163+
if (!AllPlotsInSameFigure) dev.off()
164+
165+
# Tier 3 only
166+
if (!AllPlotsInSameFigure)
167+
{
168+
png(here(paste0("tiers/figures/IntsByRegion_Tier_3", Suffix, ".png")), units = "in", res = 200, height = 10, width = 7.5)
169+
par(mar = c(8.1, 13.1, 4.1, 2.1))
170+
LetterChar = ""
171+
} else LetterChar = "(C) "
172+
x <- barplot(rowSums(Tier_List[[3]]), horiz = TRUE, col = adjCOLS[3], border = NA, cex.main = CEXMAIN,cex.axis = CEXAXIS,
173+
main = paste0(LetterChar, "Interventions by region (Tier 3)"), xlab = "Num LTLAs where intervention applied", cex.lab = CEXLAB)
174+
text(x = -1, y = x, labs, xpd = TRUE, srt = 45, adj = 1, cex = CEX_Text)
175+
if (!AllPlotsInSameFigure) dev.off()
176+
177+
if (AllPlotsInSameFigure) dev.off()
178+
179+
180+
181+
182+
#### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### ####
183+
#### With above plots, define which Ints comprise Tiers 1, 2, and 3. Distinction clearest when using Earliest date.
184+
#### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### ####
185+
186+
Tier_1_ints = c(
187+
"limited_to_groups_of_6_indoors" ,
188+
"limited_to_groups_of_6_outdoors" ,
189+
"curfew_of_10pm_for_hospitality_venues" ,
190+
"instruction_to_work_from_home_where_possible" )
191+
Tier_2_ints = c(
192+
"limited_to_groups_of_6_indoors" ,
193+
"limited_to_groups_of_6_outdoors" ,
194+
"curfew_of_10pm_for_hospitality_venues" ,
195+
"instruction_to_work_from_home_where_possible" ,
196+
"travel_discouraged" ,
197+
"no_indoor_mixing" ,
198+
"overnight_stays_discouraged" )
199+
Tier_3_ints = c(
200+
"limited_to_groups_of_6_indoors" ,
201+
"limited_to_groups_of_6_outdoors" ,
202+
"curfew_of_10pm_for_hospitality_venues" ,
203+
"instruction_to_work_from_home_where_possible" ,
204+
"travel_discouraged" ,
205+
"no_indoor_mixing" ,
206+
"overnight_stays_discouraged" ,
207+
"residents_cannot_leave_the_local_area" ,
208+
"pubs_and_bars_closed_table_service_only" )
209+
210+
211+
#### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### ####
212+
#### back-date tiers in full dataset
213+
#### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### ####
214+
215+
DATA$tier_1_BD_nested = rep(0, dim(DATA)[1])
216+
DATA$tier_2_BD_nested = rep(0, dim(DATA)[1])
217+
DATA$tier_3_BD_nested = rep(0, dim(DATA)[1])
218+
219+
for (row in 1:dim(DATA)[1])
220+
{
221+
if (all(DATA[row, Tier_1_ints] == 1)) DATA$tier_1_BD_nested[row] = 1
222+
if (all(DATA[row, Tier_2_ints] == 1)) DATA$tier_2_BD_nested[row] = 1
223+
if (all(DATA[row, Tier_3_ints] == 1)) DATA$tier_3_BD_nested[row] = 1
224+
}
225+
DATA$Tier_BD = DATA$tier_1_BD_nested + DATA$tier_2_BD_nested + DATA$tier_3_BD_nested
226+
227+
# the above are nested defintiions. Make non-nested version for downstream flexibility
228+
DATA$tier_1_BD = DATA$tier_1_BD_nested
229+
DATA$tier_2_BD = DATA$tier_2_BD_nested
230+
DATA$tier_3_BD = DATA$tier_3_BD_nested
231+
232+
DATA$tier_1_BD[which(DATA$tier_2_BD_nested == 1)] = 0
233+
DATA$tier_1_BD[which(DATA$tier_3_BD_nested == 1)] = 0
234+
DATA$tier_2_BD[which(DATA$tier_3_BD_nested == 1)] = 0
235+
236+
DATA$date <- format(DATA$date, "%d/%m/%Y")
237+
write.csv(DATA, file = here("tiers/data/npis_23Mar_02Dec.csv"),row.names = FALSE)
238+

tiers/no_need_to_run/create_data.R

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# No need to run this file; it is just provided for sake of giving an idea to people
2+
# what was done in paper in terms of pre-processing
3+
library(tidyr)
4+
library(dplyr)
5+
library(readr)
6+
library(janitor)
7+
library(lubridate)
8+
library(magrittr)
9+
library(ggpubr)
10+
library(tidyr)
11+
library(readxl)
12+
library(tools)
13+
library(ggplot2)
14+
library(flextable)
15+
library(stringr)
16+
library(here)
17+
library(zoo)
18+
19+
# read rt values
20+
rt_all <-
21+
readRDS(here('tiers/data/aggregates_infections_rt.rds')) %>%
22+
filter(type == 'R') %>%
23+
mutate(Rt_se = ((log(CIup) - log(CIlow))/3.29),
24+
value = log(value)) %>%
25+
select(area, value, period_start, Rt_se) %>%
26+
na.omit() %>%
27+
rename(Rt = value, ltla = area, date = period_start)
28+
29+
# read npis
30+
npis <-
31+
read_csv(here('tiers/data/npis_23Mar_02Dec.csv')) %>%
32+
select(-c(X1,index, source_record)) %>%
33+
mutate(date = as.Date(date, format = '%d/%m/%Y')) %>%
34+
complete(date = seq.Date(as.Date('2020-03-23'), max(rt_all$date), by="day"), nesting(ltla, region, utla)) %>%
35+
arrange(ltla, date) %>%
36+
mutate_all(na.locf)
37+
38+
# read static combined
39+
static <-
40+
read_csv(here('tiers/data/all_statc_combined.csv')) %>%
41+
rename(ltla = LTLA19NM)
42+
data <-
43+
left_join(npis, rt_all) %>%
44+
left_join(static)
45+
# saveRDS(data,here('rt_covars_combined.rds'))

0 commit comments

Comments
 (0)