Skip to contents

This function allows the construction of convolution matrices which can be be combined with a vector of primary events to produce a vector of secondary events for example in the form of a renewal equation or to simulate reporting delays. Time-varying delays are supported as well as distribution padding (to allow for use in renewal equation like approaches).

Usage

convolution_matrix(dist, t, include_partial = FALSE)

Arguments

dist

A vector of list of vectors describing the distribution to be convolved as a probability mass function.

t

Integer value indicating the number of time steps to convolve over.

include_partial

Logical, defaults to FALSE. If TRUE, the convolution include partially complete secondary events.

Value

A matrix with each column indicating a primary event and each row indicating a secondary event.

Examples

# Simple convolution matrix with a static distribution
convolution_matrix(c(1, 2, 3), 10)
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#>  [1,]    0    0    0    0    0    0    0    0    0     0
#>  [2,]    0    0    0    0    0    0    0    0    0     0
#>  [3,]    3    2    1    0    0    0    0    0    0     0
#>  [4,]    0    3    2    1    0    0    0    0    0     0
#>  [5,]    0    0    3    2    1    0    0    0    0     0
#>  [6,]    0    0    0    3    2    1    0    0    0     0
#>  [7,]    0    0    0    0    3    2    1    0    0     0
#>  [8,]    0    0    0    0    0    3    2    1    0     0
#>  [9,]    0    0    0    0    0    0    3    2    1     0
#> [10,]    0    0    0    0    0    0    0    3    2     1
# Include partially reported convolutions
convolution_matrix(c(1, 2, 3), 10, include_partial = TRUE)
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#>  [1,]    1    0    0    0    0    0    0    0    0     0
#>  [2,]    2    1    0    0    0    0    0    0    0     0
#>  [3,]    3    2    1    0    0    0    0    0    0     0
#>  [4,]    0    3    2    1    0    0    0    0    0     0
#>  [5,]    0    0    3    2    1    0    0    0    0     0
#>  [6,]    0    0    0    3    2    1    0    0    0     0
#>  [7,]    0    0    0    0    3    2    1    0    0     0
#>  [8,]    0    0    0    0    0    3    2    1    0     0
#>  [9,]    0    0    0    0    0    0    3    2    1     0
#> [10,]    0    0    0    0    0    0    0    3    2     1
# Use a list of distributions
convolution_matrix(rep(list(c(1, 2, 3)), 10), 10)
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#>  [1,]    0    0    0    0    0    0    0    0    0     0
#>  [2,]    0    0    0    0    0    0    0    0    0     0
#>  [3,]    3    2    1    0    0    0    0    0    0     0
#>  [4,]    0    3    2    1    0    0    0    0    0     0
#>  [5,]    0    0    3    2    1    0    0    0    0     0
#>  [6,]    0    0    0    3    2    1    0    0    0     0
#>  [7,]    0    0    0    0    3    2    1    0    0     0
#>  [8,]    0    0    0    0    0    3    2    1    0     0
#>  [9,]    0    0    0    0    0    0    3    2    1     0
#> [10,]    0    0    0    0    0    0    0    3    2     1
# Use a time-varying list of distributions
convolution_matrix(c(rep(list(c(1, 2, 3)), 10), list(c(4, 5, 6))), 11)
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
#>  [1,]    0    0    0    0    0    0    0    0    0     0     0
#>  [2,]    0    0    0    0    0    0    0    0    0     0     0
#>  [3,]    3    2    1    0    0    0    0    0    0     0     0
#>  [4,]    0    3    2    1    0    0    0    0    0     0     0
#>  [5,]    0    0    3    2    1    0    0    0    0     0     0
#>  [6,]    0    0    0    3    2    1    0    0    0     0     0
#>  [7,]    0    0    0    0    3    2    1    0    0     0     0
#>  [8,]    0    0    0    0    0    3    2    1    0     0     0
#>  [9,]    0    0    0    0    0    0    3    2    1     0     0
#> [10,]    0    0    0    0    0    0    0    3    2     1     0
#> [11,]    0    0    0    0    0    0    0    0    3     2     4