-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterventions.R
43 lines (35 loc) · 1.14 KB
/
interventions.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
suppressPackageStartupMessages({
require(data.table)
require(lubridate)
})
.debug <- "."
.args <- if (interactive()) sprintf(c(
"%s/rawinterventions.csv", "%s/interventions.rds"
), .debug) else commandArgs(trailingOnly = TRUE)
# TODO: move over intervention start timing analysis
# dayeff: is the estimate of the day the intervention becomes effective
ref <- fread(.args[1])[
admin_level == "national" &
measure_stage == "new" &
enforcement %in% c("Required", "Monitored", "Not applicable") &
!(who_category %in% c(
"International travel measures", "Other measures", "Environmental measures"
))
]
first.days <- ref[,.(
date_start = mean(as.Date(date_start, "%m-%d-%y"))
),by=.(iso3=iso, who_category, who_subcategory, who_measure)]
res <- first.days[,
.(dayeff=mean(date_start)),
keyby=iso3
]
# presumed delay of intervention impact
offset <- 0
# days to censor around intervention for estimation
window <- 7
# days of intervention period to consider
est.window <- 30
res[, start := round_date(dayeff + offset, "day") ]
res[, end := start + window ] # ceiling date
res[, periodend := end + est.window ]
saveRDS(res, tail(.args, 1))