R/weighted_incid.R

Defines functions weighted_incid

Documented in weighted_incid

##' Return the incidence time-series weighted by the reporting to
##' death delay
##'
##' Returns
##'
##' @param incid incidence time series as a T X 1 matrix
##' @param weights Discrete probability distribution of the reporting
##' to death delay
##' @return T X 1 matrix incidence weighted by the delay distribution. 
##' @export
##' @author Sangeeta Bhatia
weighted_incid <- function(incid, weights, trunc) {
  ndays <- nrow(incid)
  weights <- rev(weights)

  out <- matrix(NA, nrow = ndays, ncol = 1)

  for (idx in seq_len(ndays)) {
    fidx <- max(
      c(1, (idx - trunc))
    )
    out[idx, 1] <- t(incid[fidx:idx, ]) %*%
      weights[((trunc + 1) - (idx - fidx)):(trunc + 1)]
  }
  out
}
sangeetabhatia03/ascertainr documentation built on April 30, 2020, 10:14 a.m.