R/calc_likelihood_weights.R

Defines functions calc_likelihood_weights

Documented in calc_likelihood_weights

#' Calculate likelihood weights.
#' @export
#' @param years A vector of the years that weights must be calculated for.
#' @param weight.rate The rate used to calculate the weights. Each year y is assigned weight proportional to (1 - weight.rate) ^ (- year).
#' @return A vector of weights. 
#' @examples 
#' calc_likelihood_weights(1980:2010, .05)
calc_likelihood_weights <- function(years, weight.rate) {
    stopifnot(years == sort(years))
    w <- weight.rate * (1 - weight.rate) ^ (max(years) - years)
    w <- w / max(w)
    if (max(w) / min(w) > 1e5)
        warning("Weight rate too large, may cause instability.")
    w
}
vkontis/maple documentation built on July 15, 2019, 5:08 p.m.