Using jointlyr

library(jointlyr)

Set up data

Incidence

incid <- c(45, 28, 91, 36, 43, 50, 77, 54, 44, 45)

Serial Interval Distribution

si_trunc <- 20
si_distr <- EpiEstim::discr_si(seq(0, si_trunc), 6.48, 3.83)
si_distr <- si_distr / sum(si_distr)
## Default args for iter and chains
jointlyr::jointly_estimate(10, 100, incid, si_distr)
#> 
#> SAMPLING FOR MODEL 'rti0_bayesian' NOW (CHAIN 1).
#> Chain 1: 
#> Chain 1: Gradient evaluation took 4.9e-05 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.49 seconds.
#> Chain 1: Adjust your expectations accordingly!
#> Chain 1: 
#> Chain 1: 
#> Chain 1: Iteration:    1 / 2000 [  0%]  (Warmup)
#> Chain 1: Iteration:  200 / 2000 [ 10%]  (Warmup)
#> Chain 1: Iteration:  400 / 2000 [ 20%]  (Warmup)
#> Chain 1: Iteration:  600 / 2000 [ 30%]  (Warmup)
#> Chain 1: Iteration:  800 / 2000 [ 40%]  (Warmup)
#> Chain 1: Iteration: 1000 / 2000 [ 50%]  (Warmup)
#> Chain 1: Iteration: 1001 / 2000 [ 50%]  (Sampling)
#> Chain 1: Iteration: 1200 / 2000 [ 60%]  (Sampling)
#> Chain 1: Iteration: 1400 / 2000 [ 70%]  (Sampling)
#> Chain 1: Iteration: 1600 / 2000 [ 80%]  (Sampling)
#> Chain 1: Iteration: 1800 / 2000 [ 90%]  (Sampling)
#> Chain 1: Iteration: 2000 / 2000 [100%]  (Sampling)
#> Chain 1: 
#> Chain 1:  Elapsed Time: 0.57 seconds (Warm-up)
#> Chain 1:                0.679 seconds (Sampling)
#> Chain 1:                1.249 seconds (Total)
#> Chain 1: 
#> 
#> SAMPLING FOR MODEL 'rti0_bayesian' NOW (CHAIN 2).
#> Chain 2: 
#> Chain 2: Gradient evaluation took 1.9e-05 seconds
#> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.19 seconds.
#> Chain 2: Adjust your expectations accordingly!
#> Chain 2: 
#> Chain 2: 
#> Chain 2: Iteration:    1 / 2000 [  0%]  (Warmup)
#> Chain 2: Iteration:  200 / 2000 [ 10%]  (Warmup)
#> Chain 2: Iteration:  400 / 2000 [ 20%]  (Warmup)
#> Chain 2: Iteration:  600 / 2000 [ 30%]  (Warmup)
#> Chain 2: Iteration:  800 / 2000 [ 40%]  (Warmup)
#> Chain 2: Iteration: 1000 / 2000 [ 50%]  (Warmup)
#> Chain 2: Iteration: 1001 / 2000 [ 50%]  (Sampling)
#> Chain 2: Iteration: 1200 / 2000 [ 60%]  (Sampling)
#> Chain 2: Iteration: 1400 / 2000 [ 70%]  (Sampling)
#> Chain 2: Iteration: 1600 / 2000 [ 80%]  (Sampling)
#> Chain 2: Iteration: 1800 / 2000 [ 90%]  (Sampling)
#> Chain 2: Iteration: 2000 / 2000 [100%]  (Sampling)
#> Chain 2: 
#> Chain 2:  Elapsed Time: 0.562 seconds (Warm-up)
#> Chain 2:                0.677 seconds (Sampling)
#> Chain 2:                1.239 seconds (Total)
#> Chain 2: 
#> 
#> SAMPLING FOR MODEL 'rti0_bayesian' NOW (CHAIN 3).
#> Chain 3: 
#> Chain 3: Gradient evaluation took 1.9e-05 seconds
#> Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0.19 seconds.
#> Chain 3: Adjust your expectations accordingly!
#> Chain 3: 
#> Chain 3: 
#> Chain 3: Iteration:    1 / 2000 [  0%]  (Warmup)
#> Chain 3: Iteration:  200 / 2000 [ 10%]  (Warmup)
#> Chain 3: Iteration:  400 / 2000 [ 20%]  (Warmup)
#> Chain 3: Iteration:  600 / 2000 [ 30%]  (Warmup)
#> Chain 3: Iteration:  800 / 2000 [ 40%]  (Warmup)
#> Chain 3: Iteration: 1000 / 2000 [ 50%]  (Warmup)
#> Chain 3: Iteration: 1001 / 2000 [ 50%]  (Sampling)
#> Chain 3: Iteration: 1200 / 2000 [ 60%]  (Sampling)
#> Chain 3: Iteration: 1400 / 2000 [ 70%]  (Sampling)
#> Chain 3: Iteration: 1600 / 2000 [ 80%]  (Sampling)
#> Chain 3: Iteration: 1800 / 2000 [ 90%]  (Sampling)
#> Chain 3: Iteration: 2000 / 2000 [100%]  (Sampling)
#> Chain 3: 
#> Chain 3:  Elapsed Time: 0.623 seconds (Warm-up)
#> Chain 3:                0.685 seconds (Sampling)
#> Chain 3:                1.308 seconds (Total)
#> Chain 3: 
#> 
#> SAMPLING FOR MODEL 'rti0_bayesian' NOW (CHAIN 4).
#> Chain 4: 
#> Chain 4: Gradient evaluation took 1.8e-05 seconds
#> Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0.18 seconds.
#> Chain 4: Adjust your expectations accordingly!
#> Chain 4: 
#> Chain 4: 
#> Chain 4: Iteration:    1 / 2000 [  0%]  (Warmup)
#> Chain 4: Iteration:  200 / 2000 [ 10%]  (Warmup)
#> Chain 4: Iteration:  400 / 2000 [ 20%]  (Warmup)
#> Chain 4: Iteration:  600 / 2000 [ 30%]  (Warmup)
#> Chain 4: Iteration:  800 / 2000 [ 40%]  (Warmup)
#> Chain 4: Iteration: 1000 / 2000 [ 50%]  (Warmup)
#> Chain 4: Iteration: 1001 / 2000 [ 50%]  (Sampling)
#> Chain 4: Iteration: 1200 / 2000 [ 60%]  (Sampling)
#> Chain 4: Iteration: 1400 / 2000 [ 70%]  (Sampling)
#> Chain 4: Iteration: 1600 / 2000 [ 80%]  (Sampling)
#> Chain 4: Iteration: 1800 / 2000 [ 90%]  (Sampling)
#> Chain 4: Iteration: 2000 / 2000 [100%]  (Sampling)
#> Chain 4: 
#> Chain 4:  Elapsed Time: 0.591 seconds (Warm-up)
#> Chain 4:                0.613 seconds (Sampling)
#> Chain 4:                1.204 seconds (Total)
#> Chain 4:
#> Inference for Stan model: rti0_bayesian.
#> 4 chains, each with iter=2000; warmup=1000; thin=1; 
#> post-warmup draws per chain=1000, total post-warmup draws=4000.
#> 
#>                   mean se_mean     sd    2.5%     25%     50%     75%   97.5%
#> log_i0            4.99    0.06   1.39    2.34    4.02    4.98    5.94    7.64
#> rt_est            1.05    0.00   0.09    0.89    0.99    1.05    1.11    1.22
#> incid_est[1]    387.88   35.09 874.61   10.43   55.72  145.26  378.32 2075.90
#> incid_est[2]      6.35    0.52  12.73    0.22    1.08    2.66    6.55   32.51
#> incid_est[3]     31.29    2.54  62.73    1.10    5.34   13.13   32.30  160.28
#> incid_est[4]     46.75    3.79  93.51    1.66    8.00   19.66   48.30  239.19
#> incid_est[5]     52.68    4.25 104.71    1.90    9.11   22.30   54.58  268.65
#> incid_est[6]     54.64    4.36 107.45    2.02    9.60   23.38   56.87  277.11
#> incid_est[7]     55.08    4.34 106.81    2.11    9.88   23.88   57.70  277.33
#> incid_est[8]     54.96    4.27 104.88    2.19   10.09   24.19   58.03  274.43
#> incid_est[9]     54.64    4.18 102.51    2.26   10.28   24.44   58.11  270.41
#> incid_est[10]    54.25    4.08 100.02    2.34   10.47   24.67   58.13  266.02
#> incid_est[11]    53.85    3.99  97.52    2.42   10.65   24.89   58.13  261.56
#> incid_est[12]    53.46    3.89  95.08    2.50   10.84   25.09   58.11  257.12
#> incid_est[13]    53.07    3.80  92.69    2.59   11.03   25.30   58.09  253.10
#> incid_est[14]    52.70    3.71  90.37    2.67   11.22   25.52   58.08  249.13
#> incid_est[15]    52.33    3.62  88.12    2.77   11.42   25.75   58.06  245.22
#> incid_est[16]    51.98    3.54  85.93    2.86   11.63   25.97   58.04  241.37
#> incid_est[17]    51.63    3.45  83.80    2.96   11.84   26.18   58.03  237.58
#> incid_est[18]    51.30    3.37  81.74    3.06   12.05   26.42   58.01  233.90
#> incid_est[19]    50.98    3.29  79.73    3.16   12.25   26.65   57.99  230.32
#> incid_est[20]    50.67    3.22  77.77    3.27   12.47   26.88   57.96  226.79
#> incid_est[21]    50.37    3.14  75.88    3.38   12.69   27.12   57.90  223.32
#> incid_est[22]    49.45    3.02  72.78    3.47   12.81   27.09   57.23  216.72
#> incid_est[23]    49.32    2.96  71.30    3.60   13.06   27.40   57.41  214.01
#> incid_est[24]    49.08    2.90  69.63    3.72   13.30   27.65   57.43  210.59
#> incid_est[25]    48.79    2.83  67.91    3.85   13.53   27.88   57.37  206.98
#> incid_est[26]    48.49    2.76  66.19    3.97   13.76   28.11   57.29  203.50
#> incid_est[27]    48.20    2.69  64.52    4.11   13.99   28.32   57.21  200.06
#> incid_est[28]    47.92    2.63  62.90    4.24   14.23   28.52   57.09  196.68
#> incid_est[29]    47.65    2.57  61.32    4.39   14.47   28.74   57.05  193.36
#> incid_est[30]    47.39    2.50  59.78    4.53   14.71   28.99   56.98  190.09
#> incid_est[31]    47.14    2.44  58.29    4.69   14.96   29.23   56.91  186.88
#> incid_est[32]    46.90    2.39  56.84    4.84   15.21   29.45   56.78  183.72
#> incid_est[33]    46.67    2.33  55.43    5.00   15.46   29.67   56.68  180.61
#> incid_est[34]    46.44    2.27  54.06    5.17   15.69   29.87   56.64  177.56
#> incid_est[35]    46.23    2.22  52.72    5.34   15.98   30.08   56.60  174.56
#> incid_est[36]    46.03    2.17  51.42    5.52   16.25   30.32   56.55  171.59
#> incid_est[37]    45.83    2.12  50.15    5.71   16.53   30.56   56.47  168.58
#> incid_est[38]    45.64    2.07  48.92    5.90   16.80   30.79   56.38  165.64
#> incid_est[39]    45.47    2.02  47.72    6.10   17.09   31.01   56.33  162.74
#> incid_est[40]    45.30    1.97  46.55    6.30   17.38   31.23   56.28  159.89
#> incid_est[41]    45.13    1.92  45.41    6.51   17.68   31.46   56.20  157.14
#> incid_est[42]    44.98    1.88  44.29    6.72   17.96   31.71   56.13  154.33
#> incid_est[43]    44.84    1.83  43.21    6.93   18.26   31.97   56.06  151.64
#> incid_est[44]    44.70    1.79  42.15    7.16   18.55   32.24   55.98  149.25
#> incid_est[45]    44.57    1.74  41.12    7.40   18.85   32.49   55.92  146.84
#> incid_est[46]    44.45    1.70  40.11    7.63   19.16   32.74   55.83  144.31
#> incid_est[47]    44.34    1.66  39.13    7.88   19.49   33.00   55.77  141.71
#> incid_est[48]    44.23    1.62  38.17    8.15   19.82   33.25   55.70  139.17
#> incid_est[49]    44.14    1.58  37.23    8.42   20.17   33.49   55.59  136.66
#> incid_est[50]    44.05    1.55  36.31    8.69   20.52   33.75   55.50  134.20
#> incid_est[51]    43.97    1.51  35.41    8.96   20.89   34.01   55.43  131.93
#> incid_est[52]    43.89    1.47  34.54    9.27   21.25   34.29   55.35  129.76
#> incid_est[53]    43.83    1.43  33.68    9.58   21.61   34.61   55.27  127.63
#> incid_est[54]    43.77    1.40  32.83    9.91   21.99   34.89   55.20  125.41
#> incid_est[55]    43.72    1.36  32.01   10.23   22.36   35.16   55.12  123.23
#> incid_est[56]    43.68    1.33  31.20   10.56   22.74   35.46   55.07  121.22
#> incid_est[57]    43.65    1.30  30.41   10.91   23.12   35.73   55.00  119.23
#> incid_est[58]    43.62    1.26  29.64   11.27   23.52   36.05   54.87  117.27
#> incid_est[59]    43.60    1.23  28.87   11.65   23.92   36.29   54.79  115.34
#> incid_est[60]    43.59    1.20  28.13   12.05   24.32   36.59   54.69  113.48
#> incid_est[61]    43.58    1.17  27.39   12.45   24.73   36.88   54.59  111.63
#> incid_est[62]    43.59    1.14  26.67   12.86   25.14   37.17   54.49  109.81
#> incid_est[63]    43.60    1.11  25.96   13.27   25.57   37.48   54.40  108.00
#> incid_est[64]    43.62    1.08  25.26   13.72   25.98   37.78   54.38  106.24
#> incid_est[65]    43.64    1.05  24.57   14.18   26.41   38.06   54.35  104.50
#> incid_est[66]    43.68    1.02  23.90   14.66   26.83   38.31   54.26  102.85
#> incid_est[67]    43.72    0.99  23.23   15.16   27.27   38.59   54.19  101.11
#> incid_est[68]    43.77    0.96  22.57   15.64   27.70   38.90   54.16   99.34
#> incid_est[69]    43.82    0.93  21.92   16.15   28.18   39.20   54.09   97.54
#> incid_est[70]    43.89    0.91  21.28   16.65   28.67   39.51   53.99   95.78
#> incid_est[71]    43.96    0.88  20.65   17.20   29.15   39.81   53.93   94.05
#> incid_est[72]    44.04    0.85  20.02   17.76   29.61   40.09   53.90   92.37
#> incid_est[73]    44.13    0.83  19.40   18.35   30.13   40.39   53.82   90.67
#> incid_est[74]    44.22    0.80  18.79   18.95   30.63   40.71   53.75   89.04
#> incid_est[75]    44.33    0.77  18.19   19.52   31.11   41.03   53.67   87.43
#> incid_est[76]    44.44    0.75  17.59   20.17   31.61   41.34   53.66   85.84
#> incid_est[77]    44.56    0.72  16.99   20.81   32.13   41.65   53.60   84.29
#> incid_est[78]    44.69    0.70  16.40   21.46   32.65   41.99   53.53   82.73
#> incid_est[79]    44.82    0.67  15.81   22.13   33.22   42.29   53.41   81.36
#> incid_est[80]    44.97    0.64  15.23   22.85   33.78   42.63   53.37   79.81
#> incid_est[81]    45.12    0.62  14.65   23.60   34.35   42.92   53.30   78.30
#> incid_est[82]    45.28    0.59  14.08   24.37   34.95   43.23   53.26   76.93
#> incid_est[83]    45.45    0.57  13.51   25.16   35.57   43.53   53.21   75.68
#> incid_est[84]    45.63    0.54  12.94   25.99   36.14   43.84   53.10   74.56
#> incid_est[85]    45.81    0.52  12.37   26.84   36.74   44.22   53.04   73.45
#> incid_est[86]    46.01    0.49  11.81   27.71   37.37   44.58   52.97   72.36
#> incid_est[87]    46.21    0.47  11.25   28.63   37.99   44.92   52.90   71.15
#> incid_est[88]    46.43    0.44  10.69   29.52   38.64   45.29   52.86   70.04
#> incid_est[89]    46.65    0.42  10.13   30.46   39.28   45.62   52.80   68.96
#> incid_est[90]    46.88    0.39   9.57   31.35   39.95   45.92   52.73   67.78
#> incid_est[91]    47.12    0.37   9.02   32.29   40.61   46.30   52.66   66.68
#> incid_est[92]    47.37    0.34   8.47   33.24   41.28   46.67   52.58   65.56
#> incid_est[93]    47.63    0.32   7.93   34.18   41.93   46.98   52.55   64.49
#> incid_est[94]    47.90    0.29   7.39   35.25   42.60   47.38   52.54   63.75
#> incid_est[95]    48.18    0.27   6.86   36.35   43.29   47.73   52.49   62.83
#> incid_est[96]    48.47    0.24   6.34   37.43   43.99   48.12   52.50   62.14
#> incid_est[97]    48.77    0.21   5.83   38.38   44.65   48.48   52.54   61.19
#> incid_est[98]    49.08    0.19   5.34   39.37   45.29   48.86   52.51   60.40
#> incid_est[99]    49.40    0.16   4.88   40.39   45.94   49.25   52.55   59.66
#> incid_est[100]   49.74    0.14   4.45   41.34   46.55   49.64   52.65   58.95
#> incid_est[101]   50.08    0.11   4.08   42.38   47.21   49.97   52.80   58.46
#> incid_est[102]   50.43    0.09   3.78   43.42   47.81   50.36   53.01   58.16
#> incid_est[103]   50.80    0.07   3.57   44.26   48.30   50.77   53.16   58.15
#> incid_est[104]   51.18    0.06   3.47   44.71   48.79   51.11   53.55   58.15
#> incid_est[105]   51.56    0.06   3.51   44.94   49.19   51.50   53.93   58.62
#> incid_est[106]   51.97    0.07   3.68   45.06   49.45   51.86   54.36   59.50
#> incid_est[107]   52.38    0.10   3.97   44.96   49.55   52.23   54.98   60.40
#> incid_est[108]   52.80    0.12   4.36   44.62   49.78   52.64   55.60   61.94
#> incid_est[109]   53.24    0.15   4.84   44.32   49.88   53.00   56.34   63.44
#> incid_est[110]   53.69    0.18   5.38   43.91   49.98   53.44   57.17   65.01
#> incid_est[111]   54.16    0.21   5.98   43.49   50.03   53.83   58.01   66.83
#> incid_est[112]   54.64    0.25   6.62   42.87   49.97   54.31   58.93   68.78
#> incid_est[113]   55.13    0.28   7.31   42.26   49.98   54.71   59.75   70.62
#> incid_est[114]   55.63    0.32   8.02   41.67   49.92   55.17   60.60   72.63
#> incid_est[115]   56.15    0.35   8.77   41.04   49.82   55.59   61.57   74.91
#> incid_est[116]   56.69    0.39   9.55   40.42   49.74   56.05   62.52   77.42
#> incid_est[117]   57.24    0.43  10.36   39.78   49.73   56.44   63.52   79.78
#> lp__           1507.20    0.03   0.98 1504.58 1506.83 1507.51 1507.91 1508.17
#>                n_eff Rhat
#> log_i0           533 1.01
#> rt_est           528 1.01
#> incid_est[1]     621 1.00
#> incid_est[2]     608 1.00
#> incid_est[3]     608 1.00
#> incid_est[4]     608 1.00
#> incid_est[5]     608 1.00
#> incid_est[6]     607 1.00
#> incid_est[7]     605 1.00
#> incid_est[8]     604 1.00
#> incid_est[9]     602 1.00
#> incid_est[10]    600 1.00
#> incid_est[11]    599 1.00
#> incid_est[12]    597 1.00
#> incid_est[13]    595 1.00
#> incid_est[14]    594 1.00
#> incid_est[15]    592 1.00
#> incid_est[16]    590 1.00
#> incid_est[17]    589 1.00
#> incid_est[18]    587 1.00
#> incid_est[19]    586 1.00
#> incid_est[20]    584 1.00
#> incid_est[21]    583 1.00
#> incid_est[22]    581 1.00
#> incid_est[23]    579 1.00
#> incid_est[24]    578 1.00
#> incid_est[25]    577 1.00
#> incid_est[26]    575 1.00
#> incid_est[27]    574 1.00
#> incid_est[28]    573 1.00
#> incid_est[29]    571 1.00
#> incid_est[30]    570 1.00
#> incid_est[31]    569 1.00
#> incid_est[32]    568 1.00
#> incid_est[33]    566 1.00
#> incid_est[34]    565 1.00
#> incid_est[35]    564 1.01
#> incid_est[36]    563 1.01
#> incid_est[37]    562 1.01
#> incid_est[38]    561 1.01
#> incid_est[39]    560 1.01
#> incid_est[40]    559 1.01
#> incid_est[41]    558 1.01
#> incid_est[42]    558 1.01
#> incid_est[43]    557 1.01
#> incid_est[44]    556 1.01
#> incid_est[45]    555 1.01
#> incid_est[46]    555 1.01
#> incid_est[47]    554 1.01
#> incid_est[48]    553 1.01
#> incid_est[49]    553 1.01
#> incid_est[50]    552 1.01
#> incid_est[51]    552 1.01
#> incid_est[52]    551 1.01
#> incid_est[53]    551 1.01
#> incid_est[54]    550 1.01
#> incid_est[55]    550 1.01
#> incid_est[56]    550 1.01
#> incid_est[57]    550 1.01
#> incid_est[58]    549 1.01
#> incid_est[59]    549 1.01
#> incid_est[60]    549 1.01
#> incid_est[61]    549 1.01
#> incid_est[62]    549 1.01
#> incid_est[63]    549 1.01
#> incid_est[64]    549 1.01
#> incid_est[65]    549 1.01
#> incid_est[66]    549 1.01
#> incid_est[67]    549 1.01
#> incid_est[68]    550 1.01
#> incid_est[69]    550 1.01
#> incid_est[70]    550 1.01
#> incid_est[71]    551 1.01
#> incid_est[72]    551 1.01
#> incid_est[73]    552 1.01
#> incid_est[74]    553 1.01
#> incid_est[75]    553 1.01
#> incid_est[76]    554 1.01
#> incid_est[77]    555 1.01
#> incid_est[78]    556 1.01
#> incid_est[79]    558 1.01
#> incid_est[80]    559 1.01
#> incid_est[81]    561 1.01
#> incid_est[82]    563 1.01
#> incid_est[83]    565 1.01
#> incid_est[84]    568 1.01
#> incid_est[85]    571 1.00
#> incid_est[86]    574 1.00
#> incid_est[87]    578 1.00
#> incid_est[88]    583 1.00
#> incid_est[89]    589 1.00
#> incid_est[90]    596 1.00
#> incid_est[91]    605 1.00
#> incid_est[92]    615 1.00
#> incid_est[93]    629 1.00
#> incid_est[94]    646 1.00
#> incid_est[95]    670 1.00
#> incid_est[96]    701 1.00
#> incid_est[97]    745 1.00
#> incid_est[98]    809 1.00
#> incid_est[99]    908 1.00
#> incid_est[100]  1065 1.00
#> incid_est[101]  1336 1.00
#> incid_est[102]  1829 1.00
#> incid_est[103]  2712 1.00
#> incid_est[104]  3822 1.00
#> incid_est[105]  3648 1.00
#> incid_est[106]  2495 1.00
#> incid_est[107]  1695 1.00
#> incid_est[108]  1257 1.00
#> incid_est[109]  1016 1.00
#> incid_est[110]   873 1.00
#> incid_est[111]   781 1.00
#> incid_est[112]   717 1.01
#> incid_est[113]   675 1.01
#> incid_est[114]   647 1.01
#> incid_est[115]   624 1.01
#> incid_est[116]   606 1.01
#> incid_est[117]   592 1.01
#> lp__             831 1.00
#> 
#> Samples were drawn using NUTS(diag_e) at Mon Nov 25 04:40:55 2024.
#> For each parameter, n_eff is a crude measure of effective sample size,
#> and Rhat is the potential scale reduction factor on split chains (at 
#> convergence, Rhat=1).