diff --git a/DESCRIPTION b/DESCRIPTION index 56decfd..657fe62 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -3,7 +3,7 @@ Type: Package Title: Extensions to endemic-epidemic timeseries modeling from package surveillance Version: 0.0.0.0.9014 Author: Johannes Bracher [aut, cre], the authors and contributors of the surveillance package, https://cran.r-project.org/package=surveillance [ctb] (substantial parts of the package consist of modified code from the surveillance package), R Core Team [ctb] (a few code segments are modified versions of code from base R) -Maintainer: Johannes Bracher +Maintainer: Johannes Bracher Description: Extending surveillance::hhh4 to allow for distributed lags, solutions for longterm prediction and (periodically) stationary moments. License: GPL-2 Encoding: UTF-8 @@ -11,7 +11,8 @@ LazyData: true Depends: R (>= 3.2.0), methods, grDevices, graphics, stats, utils, sp (>= 1.0-15), xtable (>= 1.7-0), polyCub (>= 0.4-3), surveillance Imports: surveillance, fanplot, MASS, Matrix, nlme, spatstat, - numDeriv + numDeriv, Rdpack +RdMacros: Rdpack RoxygenNote: 7.1.1 Suggests: knitr, rmarkdown diff --git a/NAMESPACE b/NAMESPACE index d22ad96..991b683 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -32,6 +32,9 @@ export(profile_par_lag) export(psi2size.hhh4lag) export(stationary_moments) export(unrestricted_lag) +export(weibull_lag) +importFrom(DiscreteWeibull,ddweibull) +importFrom(Rdpack,reprompt) importFrom(fanplot,fan) importFrom(nlme,fixef) importFrom(nlme,ranef) diff --git a/R/get_geom_lags.R b/R/get_geom_lags.R index e1ff912..e7f4bb0 100644 --- a/R/get_geom_lags.R +++ b/R/get_geom_lags.R @@ -145,7 +145,7 @@ linear_lag <- function (par_lag, min_lag, max_lag){ #' #' This function generates \eqn{Q} lag weights without a parametric constraint. The weights are obtained via #' a multinomial logit transformation where the first lag is the reference category. -#' @param par_lag theparameter vector of length \eqn{Q - 1} +#' @param par_lag the parameter vector of length \eqn{Q - 1} #' @param min_lag smallest lag to include; the support of the Poisson form starts only at \code{min_lag}. Defaults to 1. #' @param max_lag highest lag to include; higher lags are cut off and he remaining weights standardized. Defaults to 5. #' @export @@ -157,3 +157,32 @@ unrestricted_lag <- function(par_lag, min_lag, max_lag){ weights <- c(rep(0, min_lag - 1), weights0) return(weights) } + +#' Discrete Weibull lag function +#' +#' @description The discrete Weibull distribution has probability mass function \insertCite{NakagawaOsaki1975}{Rdpack} +#' \eqn{p(d; \kappa, \beta) = \kappa ^ {(d - 1) ^ \beta} - \kappa ^ {d ^ \beta}, d = 1, 2, \ldots} +#' which reduces to the geometric if \eqn{\beta = 1} (\code{geometric_lag}) and the discrete Raleigh distribution if \eqn{\beta = 2} \insertCite{Roy2004}{Rdpack} +#' +#' @param par_lag the parameter vector (must be of length 2) +#' @param min_lag smallest lag to include +#' @param max_lag highest lag to include +#' @references +#' \insertAllCited +#' @return the discrete Weibull lag distribution +#' @importFrom Rdpack reprompt +#' @importFrom DiscreteWeibull ddweibull +#' @export +#' @seealso geometric_lag poisson_lag ar2_lag linear_lag unrestricted_lag +weibull_lag <- function(par_lag, min_lag, max_lag){ + if(length(par_lag) != 2){ + stop("The starting value for par_lag needs to be 2") + } + p_lag <- exp(par_lag) / (1 + exp(par_lag)) + weights0 <- c(rep(0, min_lag - 1), + DiscreteWeibull::ddweibull((min_lag : max_lag) - + 1, p_lag[1], p_lag[2], + zero = TRUE)) + weights <- weights0 / sum(weights0) + return(weights) +} diff --git a/inst/REFERENCES.bib b/inst/REFERENCES.bib new file mode 100644 index 0000000..b565b70 --- /dev/null +++ b/inst/REFERENCES.bib @@ -0,0 +1,21 @@ +@article{NakagawaOsaki1975, + author = {Nakagawa, T. and Osaki, S.}, + journal = {IEEE Transactions on Reliability}, + title = {The Discrete {Weibull} Distribution}, + year = {1975}, + volume = {R-24}, + number = {5}, + pages = {300--301}, + doi = {10.1109/TR.1975.5214915} +} + +@article{Roy2004, + title = {Discrete {Rayleigh} distribution}, + author = {Roy, D.}, + journal = {IEEE Transactions on Reliability}, + volume = {53}, + number = {2}, + pages = {255--260}, + year = {2004}, + doi = {10.1109/TR.2004.829161} +} diff --git a/man/predictive_moments.Rd b/man/predictive_moments.Rd index e7e998c..74a9f15 100644 --- a/man/predictive_moments.Rd +++ b/man/predictive_moments.Rd @@ -34,7 +34,7 @@ order to save storage.} covariance matrices be returned?} \item{return_mu_decomposed}{logical: should an array with the -predictive means decomposed into the fidderent components be returned?} +predictive means decomposed into the different components be returned?} \item{return_M}{logical: should the matrix M containing the predictive first and (un-centered) second moments be returned?} diff --git a/man/unrestricted_lag.Rd b/man/unrestricted_lag.Rd index 638bc19..363a183 100644 --- a/man/unrestricted_lag.Rd +++ b/man/unrestricted_lag.Rd @@ -7,7 +7,7 @@ unrestricted_lag(par_lag, min_lag, max_lag) } \arguments{ -\item{par_lag}{theparameter vector of length \eqn{Q - 1}} +\item{par_lag}{the parameter vector of length \eqn{Q - 1}} \item{min_lag}{smallest lag to include; the support of the Poisson form starts only at \code{min_lag}. Defaults to 1.} diff --git a/man/weibull_lag.Rd b/man/weibull_lag.Rd new file mode 100644 index 0000000..9de3e8f --- /dev/null +++ b/man/weibull_lag.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_geom_lags.R +\name{weibull_lag} +\alias{weibull_lag} +\title{Discrete Weibull lag function} +\usage{ +weibull_lag(par_lag, min_lag, max_lag) +} +\arguments{ +\item{par_lag}{the parameter vector (must be of length 2)} + +\item{min_lag}{smallest lag to include} + +\item{max_lag}{highest lag to include} +} +\value{ +the discrete Weibull lag distribution +} +\description{ +The discrete Weibull distribution has probability mass function \insertCite{NakagawaOsaki1975}{Rdpack} +\eqn{p(d; \kappa, \beta) = \kappa ^ {(d - 1) ^ \beta} - \kappa ^ {d ^ \beta}, d = 1, 2, \ldots} +which reduces to the geometric if \eqn{\beta = 1} (\code{geometric_lag}) and the discrete Raleigh distribution if \eqn{\beta = 2} \insertCite{Roy2004}{Rdpack} +} +\references{ +\insertAllCited +} +\seealso{ +geometric_lag poisson_lag ar2_lag linear_lag unrestricted_lag +}