library(dplyr)
library(purrr)
devtools::load_all()

This analysis uses a daily incidence time series to estimate the overall infectivity at a given time. The relative risk profiles estimated in a previous step of the analysis pipeline are then weighted by infectivity.

Ebola params

incid <- here::here(params$cases) %>%
    readr::read_csv(n_max = params$onday) %>%
    select(date, params$sources)
Serial interval estimation over however many days worth of data we
have at this point.

```r
si <- EpiEstim::DiscrSI(k = 0:params$onday,
                        mu = params$simean,
                        sigma  = params$sisd) %>% round(3)

weights <- select(incid, params$sources) %>%
    map_dbl(~infectivity_at_source(.x, si, params$R) %>%
        `[`(params$onday))

Normalise weights

day <- params$onday
normalised <- weights / sum(weights)

Read in the relative risk profiles

relrisk_df <- purrr::map(params$risk,
                         ~ readr::read_csv(here::here(.x)))

Risk profile weighted by infectivity

## signf <- 7
## normalised <- signif(normalised, 7)


## wtd_rel_risk <- (normalised[1]  * rel_risk[[1]]$relative_flow) +
##     (normalised[2] * rel_risk[[2]]$relative_flow)

rel_risk <- map_dfc(relrisk_df, ~ .x$relative_flow)
wtd_rel_risk <- map2_dfc(rel_risk,
                         normalised,
                         ~ .x * .y) %>%
    rowSums(na.rm = TRUE)

wtd_risk_profile <- data.frame(flow_to = relrisk_df[[1]]$flow_to,
                               wtd_rel_risk = wtd_rel_risk)
readr::write_csv(x = wtd_risk_profile,
                 path = here::here(params$outfile))


annecori/mRIIDSprocessData documentation built on May 29, 2019, 1:16 p.m.