Skip to contents

This function simulates an epidemic using a renewal model based on the specified time-varying reproduction number (Rt), the serial interval distribution characterized by a gamma distribution, and an initial number of cases.

Usage

simulate_renewal_epidemic(Rt_fun, nt, mean_si, sd_si, i_0, X = NULL)

Arguments

Rt_fun

A function that takes a vector of time points and returns a vector of reproduction numbers (Rt) corresponding to those time points.

nt

An integer specifying the number of time points (duration of the epidemic simulation).

mean_si

A numeric value representing the mean of the serial interval distribution.

sd_si

A numeric value representing the standard deviation of the serial interval distribution.

i_0

An integer specifying the initial number of cases at time point 1.

X

An optional matrix of covariates with nt rows.

Value

A list containing the following components:

i_t

A numeric vector of the incidence of new cases at each time point.

lambda_t

A numeric vector of the total infectiousness at each time point.

w_dist

A numeric vector of the discretized serial interval distribution.

r_t

A numeric vector of the reproduction number (Rt) at each time point.

t

A numeric vector of the time points from 1 to nt.

Details

The renewal model is a common approach for simulating the spread of infectious diseases. The total infectiousness at each time point is computed as the convolution of past incidence with the serial interval distribution. The incidence at each time point is then simulated as a Poisson random variable with a mean equal to the product of the total infectiousness and the time-varying reproduction number.

Examples

rt_fun <- function(t) {
  1.5 * exp(-0.05 * t)
}
simulate_renewal_epidemic(rt_fun, 100, 5, 2, 10)
#>       t i_t        R_t     lambda_t       w_dist
#> 1     1  10 1.42684414 1.000000e+01 1.202812e-03
#> 2     2   0 1.35725613 1.202812e-02 3.121540e-02
#> 3     3   1 1.29106196 3.121540e-01 1.171737e-01
#> 4     4   2 1.22809613 1.172940e+00 1.943497e-01
#> 5     5   1 1.16820117 1.977118e+00 2.092807e-01
#> 6     6   0 1.11122733 2.273615e+00 1.731352e-01
#> 7     7   2 1.05703213 2.191264e+00 1.200194e-01
#> 8     8   2 1.00548007 1.917754e+00 7.330704e-02
#> 9     9   1 0.95644223 1.583953e+00 4.071768e-02
#> 10   10   2 0.90979599 1.380728e+00 2.100546e-02
#> 11   11   2 0.86542472 1.353204e+00 1.021454e-02
#> 12   12   2 0.82321745 1.398768e+00 4.732806e-03
#> 13   13   0 0.78306867 1.481441e+00 2.106387e-03
#> 14   14   0 0.74487796 1.595075e+00 9.060961e-04
#> 15   15   1 0.70854983 1.656625e+00 3.785690e-04
#> 16   16   1 0.67399345 1.528375e+00 1.542214e-04
#> 17   17   0 0.64112240 1.245436e+00 6.145378e-05
#> 18   18   0 0.60985449 9.893817e-01 2.401538e-05
#> 19   19   0 0.58011154 8.325695e-01 9.223817e-06
#> 20   20   0 0.55181916 6.984244e-01 3.488238e-06
#> 21   21   2 0.52490662 5.373851e-01 1.300919e-06
#> 22   22   0 0.49930663 3.722733e-01 4.790949e-07
#> 23   23   0 0.47495515 2.918871e-01 1.744290e-07
#> 24   24   0 0.45179132 3.646919e-01 6.284573e-08
#> 25   25   0 0.42975720 4.575370e-01 2.242704e-08
#> 26   26   1 0.40879769 4.527898e-01 7.933068e-09
#> 27   27   0 0.38886039 3.636594e-01 2.783419e-09
#> 28   28   0 0.36989545 2.785920e-01 9.692738e-10
#> 29   29   0 0.35185543 2.669968e-01 3.351808e-10
#> 30   30   0 0.33469524 2.771459e-01 1.151559e-10
#> 31   31   0 0.31837196 2.518534e-01 3.932399e-11
#> 32   32   0 0.30284478 1.937908e-01 1.335243e-11
#> 33   33   0 0.28807486 1.295745e-01 4.509726e-12
#> 34   34   0 0.27402529 7.755453e-02 1.515565e-12
#> 35   35   0 0.26066092 4.254312e-02 5.069278e-13
#> 36   36   0 0.24794833 2.176758e-02 1.688649e-13
#> 37   37   0 0.23585575 1.052483e-02 5.595524e-14
#> 38   38   0 0.22435293 4.856392e-03 1.854072e-14
#> 39   39   0 0.21341111 2.154664e-03 5.995204e-15
#> 40   40   0 0.20300292 9.246319e-04 1.998401e-15
#> 41   41   0 0.19310236 3.855768e-04 6.661338e-16
#> 42   42   0 0.18368464 1.568343e-04 2.220446e-16
#> 43   43   0 0.17472624 6.241584e-05 1.110223e-16
#> 44   44   0 0.16620474 2.436559e-05 0.000000e+00
#> 45   45   0 0.15809884 9.349972e-06 0.000000e+00
#> 46   46   0 0.15038827 3.533251e-06 0.000000e+00
#> 47   47   0 0.14305374 1.316840e-06 0.000000e+00
#> 48   48   0 0.13607693 4.846801e-07 0.000000e+00
#> 49   49   0 0.12944038 1.763738e-07 0.000000e+00
#> 50   50   0 0.12312750 6.351817e-08 0.000000e+00
#> 51   51   0 0.11712250 2.265805e-08 0.000000e+00
#> 52   52   0 0.11141037 8.011946e-09 0.000000e+00
#> 53   53   0 0.10597682 2.810200e-09 0.000000e+00
#> 54   54   0 0.10080827 9.783184e-10 0.000000e+00
#> 55   55   0 0.09589179 3.382201e-10 0.000000e+00
#> 56   56   0 0.09121509 1.161724e-10 0.000000e+00
#> 57   57   0 0.08676648 3.966261e-11 0.000000e+00
#> 58   58   0 0.08253483 1.346467e-11 0.000000e+00
#> 59   59   0 0.07850956 4.546918e-12 0.000000e+00
#> 60   60   0 0.07468060 1.527556e-12 0.000000e+00
#> 61   61   0 0.07103839 5.109246e-13 0.000000e+00
#> 62   62   0 0.06757380 1.701972e-13 0.000000e+00
#> 63   63   0 0.06427819 5.639933e-14 0.000000e+00
#> 64   64   0 0.06114331 1.876277e-14 0.000000e+00
#> 65   65   0 0.05816131 5.995204e-15 0.000000e+00
#> 66   66   0 0.05532475 1.998401e-15 0.000000e+00
#> 67   67   0 0.05262653 6.661338e-16 0.000000e+00
#> 68   68   0 0.05005990 2.220446e-16 0.000000e+00
#> 69   69   0 0.04761845 1.110223e-16 0.000000e+00
#> 70   70   0 0.04529608 0.000000e+00 0.000000e+00
#> 71   71   0 0.04308696 0.000000e+00 0.000000e+00
#> 72   72   0 0.04098558 0.000000e+00 0.000000e+00
#> 73   73   0 0.03898669 0.000000e+00 0.000000e+00
#> 74   74   0 0.03708529 0.000000e+00 0.000000e+00
#> 75   75   0 0.03527662 0.000000e+00 0.000000e+00
#> 76   76   0 0.03355616 0.000000e+00 0.000000e+00
#> 77   77   0 0.03191960 0.000000e+00 0.000000e+00
#> 78   78   0 0.03036287 0.000000e+00 0.000000e+00
#> 79   79   0 0.02888205 0.000000e+00 0.000000e+00
#> 80   80   0 0.02747346 0.000000e+00 0.000000e+00
#> 81   81   0 0.02613356 0.000000e+00 0.000000e+00
#> 82   82   0 0.02485901 0.000000e+00 0.000000e+00
#> 83   83   0 0.02364662 0.000000e+00 0.000000e+00
#> 84   84   0 0.02249337 0.000000e+00 0.000000e+00
#> 85   85   0 0.02139635 0.000000e+00 0.000000e+00
#> 86   86   0 0.02035284 0.000000e+00 0.000000e+00
#> 87   87   0 0.01936022 0.000000e+00 0.000000e+00
#> 88   88   0 0.01841601 0.000000e+00 0.000000e+00
#> 89   89   0 0.01751785 0.000000e+00 0.000000e+00
#> 90   90   0 0.01666349 0.000000e+00 0.000000e+00
#> 91   91   0 0.01585081 0.000000e+00 0.000000e+00
#> 92   92   0 0.01507775 0.000000e+00 0.000000e+00
#> 93   93   0 0.01434240 0.000000e+00 0.000000e+00
#> 94   94   0 0.01364292 0.000000e+00 0.000000e+00
#> 95   95   0 0.01297754 0.000000e+00 0.000000e+00
#> 96   96   0 0.01234462 0.000000e+00 0.000000e+00
#> 97   97   0 0.01174257 0.000000e+00 0.000000e+00
#> 98   98   0 0.01116987 0.000000e+00 0.000000e+00
#> 99   99   0 0.01062511 0.000000e+00 0.000000e+00
#> 100 100   0 0.01010692 0.000000e+00 0.000000e+00