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.644 seconds (Warm-up)
#> Chain 1:                0.61 seconds (Sampling)
#> Chain 1:                1.254 seconds (Total)
#> Chain 1: 
#> 
#> SAMPLING FOR MODEL 'rti0_bayesian' NOW (CHAIN 2).
#> Chain 2: 
#> Chain 2: Gradient evaluation took 1.8e-05 seconds
#> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.18 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.571 seconds (Warm-up)
#> Chain 2:                0.703 seconds (Sampling)
#> Chain 2:                1.274 seconds (Total)
#> Chain 2: 
#> 
#> SAMPLING FOR MODEL 'rti0_bayesian' NOW (CHAIN 3).
#> Chain 3: 
#> Chain 3: Gradient evaluation took 1.8e-05 seconds
#> Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0.18 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.54 seconds (Warm-up)
#> Chain 3:                0.598 seconds (Sampling)
#> Chain 3:                1.138 seconds (Total)
#> Chain 3: 
#> 
#> SAMPLING FOR MODEL 'rti0_bayesian' NOW (CHAIN 4).
#> Chain 4: 
#> Chain 4: Gradient evaluation took 1.9e-05 seconds
#> Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0.19 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.56 seconds (Warm-up)
#> Chain 4:                0.606 seconds (Sampling)
#> Chain 4:                1.166 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.97    0.07   1.46    2.15    3.95    4.92    5.96    7.84
#> rt_est            1.05    0.00   0.09    0.88    0.99    1.05    1.12    1.24
#> incid_est[1]    417.36   48.73 946.14    8.59   52.19  137.53  385.97 2533.88
#> incid_est[2]      6.77    0.72  13.77    0.19    1.02    2.53    6.68   38.97
#> incid_est[3]     33.40    3.55  67.89    0.92    5.04   12.46   32.95  192.12
#> incid_est[4]     49.89    5.29 101.21    1.37    7.55   18.66   49.27  286.64
#> incid_est[5]     56.19    5.93 113.32    1.57    8.60   21.17   55.65  321.74
#> incid_est[6]     58.24    6.09 116.29    1.68    9.07   22.21   57.99  331.52
#> incid_est[7]     58.65    6.06 115.60    1.75    9.34   22.71   58.82  331.32
#> incid_est[8]     58.46    5.96 113.52    1.82    9.55   23.01   59.08  327.33
#> incid_est[9]     58.05    5.84 110.95    1.88    9.73   23.25   59.14  321.99
#> incid_est[10]    57.58    5.71 108.26    1.94    9.90   23.45   59.12  316.21
#> incid_est[11]    57.09    5.57 105.56    2.01   10.08   23.66   59.09  310.56
#> incid_est[12]    56.60    5.44 102.91    2.08   10.27   23.87   59.06  304.75
#> incid_est[13]    56.13    5.32 100.32    2.16   10.45   24.09   59.04  299.18
#> incid_est[14]    55.66    5.19  97.81    2.24   10.64   24.31   59.02  293.83
#> incid_est[15]    55.21    5.07  95.37    2.32   10.83   24.52   59.03  288.66
#> incid_est[16]    54.78    4.95  93.00    2.40   11.02   24.75   59.03  283.58
#> incid_est[17]    54.35    4.83  90.69    2.49   11.21   24.98   58.97  278.59
#> incid_est[18]    53.94    4.72  88.45    2.58   11.42   25.21   58.91  273.69
#> incid_est[19]    53.54    4.61  86.27    2.67   11.63   25.46   58.85  268.88
#> incid_est[20]    53.15    4.50  84.15    2.77   11.85   25.71   58.83  264.22
#> incid_est[21]    52.78    4.40  82.09    2.87   12.07   25.94   58.80  259.71
#> incid_est[22]    51.74    4.23  78.73    2.96   12.19   25.94   58.07  251.48
#> incid_est[23]    51.56    4.14  77.12    3.07   12.43   26.23   58.28  248.06
#> incid_est[24]    51.25    4.05  75.31    3.18   12.66   26.47   58.34  243.99
#> incid_est[25]    50.89    3.95  73.43    3.29   12.88   26.69   58.27  239.65
#> incid_est[26]    50.52    3.86  71.57    3.40   13.11   26.91   58.18  235.28
#> incid_est[27]    50.16    3.76  69.75    3.51   13.34   27.14   58.07  231.11
#> incid_est[28]    49.82    3.67  67.98    3.63   13.57   27.37   57.98  227.09
#> incid_est[29]    49.48    3.58  66.26    3.75   13.82   27.60   57.91  223.15
#> incid_est[30]    49.16    3.49  64.59    3.87   14.06   27.83   57.82  219.23
#> incid_est[31]    48.85    3.41  62.96    4.00   14.31   28.05   57.69  215.18
#> incid_est[32]    48.55    3.32  61.38    4.15   14.57   28.29   57.62  211.21
#> incid_est[33]    48.26    3.24  59.85    4.31   14.83   28.52   57.49  207.30
#> incid_est[34]    47.98    3.16  58.35    4.47   15.09   28.75   57.42  203.33
#> incid_est[35]    47.71    3.09  56.89    4.62   15.36   29.00   57.30  199.24
#> incid_est[36]    47.46    3.01  55.47    4.78   15.66   29.24   57.21  195.59
#> incid_est[37]    47.21    2.94  54.09    4.94   15.95   29.48   57.09  192.01
#> incid_est[38]    46.97    2.86  52.75    5.11   16.24   29.73   56.96  188.50
#> incid_est[39]    46.74    2.79  51.44    5.28   16.52   29.97   56.82  185.04
#> incid_est[40]    46.52    2.72  50.16    5.46   16.79   30.21   56.69  181.66
#> incid_est[41]    46.31    2.66  48.91    5.64   17.06   30.46   56.59  178.03
#> incid_est[42]    46.11    2.59  47.70    5.84   17.35   30.71   56.51  174.30
#> incid_est[43]    45.93    2.53  46.51    6.04   17.67   30.95   56.42  170.66
#> incid_est[44]    45.75    2.46  45.36    6.26   17.97   31.22   56.26  167.09
#> incid_est[45]    45.58    2.40  44.23    6.48   18.30   31.49   56.13  163.97
#> incid_est[46]    45.41    2.34  43.13    6.71   18.61   31.76   56.00  160.93
#> incid_est[47]    45.26    2.28  42.06    6.95   18.95   32.01   55.97  157.95
#> incid_est[48]    45.12    2.22  41.01    7.18   19.26   32.27   55.94  155.03
#> incid_est[49]    44.98    2.17  39.98    7.43   19.59   32.53   55.85  152.15
#> incid_est[50]    44.86    2.11  38.98    7.68   19.95   32.79   55.73  149.33
#> incid_est[51]    44.74    2.06  38.00    7.95   20.28   33.07   55.62  146.22
#> incid_est[52]    44.63    2.00  37.04    8.24   20.63   33.32   55.52  143.31
#> incid_est[53]    44.53    1.95  36.10    8.54   20.98   33.58   55.45  140.68
#> incid_est[54]    44.44    1.90  35.18    8.83   21.34   33.85   55.35  138.10
#> incid_est[55]    44.36    1.85  34.29    9.13   21.70   34.11   55.26  135.56
#> incid_est[56]    44.29    1.80  33.41    9.43   22.09   34.41   55.20  133.12
#> incid_est[57]    44.22    1.75  32.54    9.75   22.47   34.67   55.10  130.72
#> incid_est[58]    44.17    1.71  31.70   10.08   22.86   34.96   54.99  128.23
#> incid_est[59]    44.12    1.66  30.87   10.41   23.27   35.26   54.90  125.83
#> incid_est[60]    44.08    1.61  30.05   10.76   23.68   35.57   54.81  123.45
#> incid_est[61]    44.05    1.57  29.25   11.18   24.10   35.87   54.68  121.14
#> incid_est[62]    44.03    1.53  28.47   11.61   24.52   36.18   54.60  118.75
#> incid_est[63]    44.02    1.48  27.70   12.06   24.93   36.47   54.52  116.41
#> incid_est[64]    44.01    1.44  26.94   12.52   25.37   36.76   54.45  114.11
#> incid_est[65]    44.01    1.40  26.19   13.00   25.80   37.07   54.36  111.88
#> incid_est[66]    44.03    1.36  25.46   13.47   26.24   37.37   54.40  109.74
#> incid_est[67]    44.05    1.32  24.73   13.93   26.70   37.74   54.35  107.65
#> incid_est[68]    44.07    1.28  24.02   14.38   27.17   38.05   54.28  105.56
#> incid_est[69]    44.11    1.24  23.32   14.90   27.66   38.35   54.20  103.55
#> incid_est[70]    44.16    1.20  22.63   15.45   28.15   38.67   54.09  101.62
#> incid_est[71]    44.21    1.16  21.94   15.97   28.62   39.05   53.97   99.71
#> incid_est[72]    44.28    1.12  21.27   16.51   29.14   39.34   53.91   97.84
#> incid_est[73]    44.35    1.08  20.60   17.07   29.60   39.65   53.79   96.00
#> incid_est[74]    44.43    1.05  19.94   17.70   30.14   40.01   53.75   94.19
#> incid_est[75]    44.52    1.01  19.29   18.34   30.68   40.35   53.67   92.41
#> incid_est[76]    44.61    0.98  18.65   18.99   31.21   40.68   53.65   90.63
#> incid_est[77]    44.72    0.94  18.01   19.66   31.73   41.01   53.61   88.85
#> incid_est[78]    44.84    0.90  17.37   20.37   32.27   41.34   53.54   87.21
#> incid_est[79]    44.96    0.87  16.74   21.09   32.80   41.69   53.52   85.62
#> incid_est[80]    45.09    0.83  16.12   21.81   33.35   42.02   53.43   84.04
#> incid_est[81]    45.24    0.80  15.50   22.61   33.94   42.40   53.34   82.50
#> incid_est[82]    45.39    0.77  14.89   23.42   34.54   42.76   53.30   80.90
#> incid_est[83]    45.55    0.73  14.28   24.28   35.18   43.13   53.29   79.45
#> incid_est[84]    45.72    0.70  13.67   25.05   35.82   43.49   53.25   77.92
#> incid_est[85]    45.90    0.67  13.07   25.88   36.45   43.88   53.26   76.49
#> incid_est[86]    46.09    0.63  12.47   26.74   37.05   44.24   53.22   74.98
#> incid_est[87]    46.29    0.60  11.87   27.67   37.64   44.58   53.13   73.52
#> incid_est[88]    46.49    0.57  11.27   28.61   38.31   45.00   53.05   72.15
#> incid_est[89]    46.71    0.53  10.68   29.59   38.99   45.43   53.01   70.76
#> incid_est[90]    46.94    0.50  10.09   30.56   39.65   45.78   52.97   69.50
#> incid_est[91]    47.18    0.47   9.50   31.60   40.29   46.18   52.91   68.38
#> incid_est[92]    47.43    0.44   8.92   32.60   40.97   46.57   52.89   67.29
#> incid_est[93]    47.69    0.40   8.34   33.61   41.69   46.94   52.92   66.08
#> incid_est[94]    47.96    0.37   7.77   34.65   42.37   47.33   52.88   64.93
#> incid_est[95]    48.24    0.34   7.21   35.82   43.07   47.74   52.82   63.77
#> incid_est[96]    48.53    0.31   6.65   37.02   43.78   48.12   52.82   62.87
#> incid_est[97]    48.84    0.27   6.11   38.14   44.47   48.47   52.79   61.85
#> incid_est[98]    49.15    0.24   5.58   39.16   45.19   48.91   52.80   61.08
#> incid_est[99]    49.47    0.21   5.08   40.25   45.87   49.29   52.93   60.19
#> incid_est[100]   49.81    0.18   4.62   41.33   46.53   49.70   52.93   59.41
#> incid_est[101]   50.16    0.14   4.21   42.32   47.14   50.09   53.02   58.66
#> incid_est[102]   50.52    0.11   3.87   43.18   47.80   50.46   53.17   58.13
#> incid_est[103]   50.90    0.08   3.63   44.09   48.35   50.85   53.39   57.94
#> incid_est[104]   51.28    0.06   3.50   44.66   48.86   51.19   53.70   58.00
#> incid_est[105]   51.68    0.06   3.52   45.15   49.21   51.61   54.09   58.64
#> incid_est[106]   52.09    0.07   3.68   45.21   49.48   52.04   54.58   59.57
#> incid_est[107]   52.52    0.09   3.97   45.21   49.71   52.47   55.17   60.67
#> incid_est[108]   52.96    0.13   4.38   45.07   49.91   52.84   55.82   62.01
#> incid_est[109]   53.41    0.16   4.87   44.60   50.04   53.20   56.61   63.46
#> incid_est[110]   53.87    0.20   5.44   43.89   50.12   53.64   57.36   65.17
#> incid_est[111]   54.35    0.23   6.07   43.32   50.17   54.01   58.27   67.05
#> incid_est[112]   54.85    0.27   6.74   42.71   50.17   54.46   59.19   69.15
#> incid_est[113]   55.36    0.31   7.45   42.10   50.18   54.90   60.10   71.42
#> incid_est[114]   55.89    0.35   8.20   41.56   50.15   55.29   61.09   73.53
#> incid_est[115]   56.43    0.39   8.98   40.91   50.13   55.78   62.13   75.88
#> incid_est[116]   56.98    0.44   9.80   40.22   50.08   56.26   63.15   78.22
#> incid_est[117]   57.56    0.48  10.64   39.53   50.00   56.79   64.19   80.95
#> lp__           1507.16    0.04   1.02 1504.52 1506.77 1507.47 1507.88 1508.16
#>                n_eff Rhat
#> log_i0           397 1.01
#> rt_est           403 1.01
#> incid_est[1]     377 1.01
#> incid_est[2]     366 1.01
#> incid_est[3]     366 1.01
#> incid_est[4]     366 1.01
#> incid_est[5]     365 1.01
#> incid_est[6]     365 1.01
#> incid_est[7]     364 1.01
#> incid_est[8]     362 1.01
#> incid_est[9]     361 1.01
#> incid_est[10]    360 1.01
#> incid_est[11]    359 1.01
#> incid_est[12]    357 1.01
#> incid_est[13]    356 1.01
#> incid_est[14]    355 1.01
#> incid_est[15]    354 1.01
#> incid_est[16]    353 1.01
#> incid_est[17]    352 1.01
#> incid_est[18]    351 1.01
#> incid_est[19]    350 1.01
#> incid_est[20]    349 1.01
#> incid_est[21]    348 1.01
#> incid_est[22]    347 1.01
#> incid_est[23]    346 1.01
#> incid_est[24]    346 1.01
#> incid_est[25]    345 1.01
#> incid_est[26]    344 1.01
#> incid_est[27]    344 1.01
#> incid_est[28]    343 1.01
#> incid_est[29]    342 1.01
#> incid_est[30]    342 1.01
#> incid_est[31]    341 1.01
#> incid_est[32]    341 1.01
#> incid_est[33]    341 1.01
#> incid_est[34]    340 1.01
#> incid_est[35]    340 1.01
#> incid_est[36]    340 1.01
#> incid_est[37]    339 1.01
#> incid_est[38]    339 1.01
#> incid_est[39]    339 1.01
#> incid_est[40]    339 1.01
#> incid_est[41]    339 1.01
#> incid_est[42]    339 1.01
#> incid_est[43]    339 1.01
#> incid_est[44]    339 1.01
#> incid_est[45]    339 1.01
#> incid_est[46]    339 1.01
#> incid_est[47]    340 1.01
#> incid_est[48]    340 1.01
#> incid_est[49]    340 1.01
#> incid_est[50]    341 1.01
#> incid_est[51]    341 1.01
#> incid_est[52]    341 1.01
#> incid_est[53]    342 1.01
#> incid_est[54]    342 1.01
#> incid_est[55]    343 1.01
#> incid_est[56]    344 1.01
#> incid_est[57]    344 1.01
#> incid_est[58]    345 1.01
#> incid_est[59]    346 1.01
#> incid_est[60]    346 1.01
#> incid_est[61]    347 1.01
#> incid_est[62]    348 1.01
#> incid_est[63]    349 1.01
#> incid_est[64]    350 1.01
#> incid_est[65]    351 1.01
#> incid_est[66]    352 1.01
#> incid_est[67]    353 1.01
#> incid_est[68]    354 1.01
#> incid_est[69]    356 1.01
#> incid_est[70]    357 1.01
#> incid_est[71]    358 1.01
#> incid_est[72]    359 1.01
#> incid_est[73]    361 1.01
#> incid_est[74]    362 1.01
#> incid_est[75]    364 1.01
#> incid_est[76]    366 1.01
#> incid_est[77]    367 1.01
#> incid_est[78]    369 1.01
#> incid_est[79]    371 1.01
#> incid_est[80]    373 1.01
#> incid_est[81]    375 1.01
#> incid_est[82]    377 1.01
#> incid_est[83]    380 1.01
#> incid_est[84]    382 1.01
#> incid_est[85]    385 1.01
#> incid_est[86]    388 1.01
#> incid_est[87]    391 1.01
#> incid_est[88]    395 1.01
#> incid_est[89]    399 1.01
#> incid_est[90]    404 1.01
#> incid_est[91]    410 1.01
#> incid_est[92]    417 1.01
#> incid_est[93]    425 1.01
#> incid_est[94]    436 1.01
#> incid_est[95]    450 1.01
#> incid_est[96]    468 1.01
#> incid_est[97]    493 1.01
#> incid_est[98]    530 1.01
#> incid_est[99]    585 1.01
#> incid_est[100]   678 1.01
#> incid_est[101]   845 1.01
#> incid_est[102]  1189 1.00
#> incid_est[103]  1988 1.00
#> incid_est[104]  3387 1.00
#> incid_est[105]  3774 1.00
#> incid_est[106]  2928 1.00
#> incid_est[107]  1839 1.00
#> incid_est[108]  1225 1.00
#> incid_est[109]   935 1.00
#> incid_est[110]   770 1.00
#> incid_est[111]   675 1.00
#> incid_est[112]   614 1.01
#> incid_est[113]   573 1.01
#> incid_est[114]   544 1.01
#> incid_est[115]   522 1.01
#> incid_est[116]   506 1.01
#> incid_est[117]   493 1.01
#> lp__             537 1.01
#> 
#> Samples were drawn using NUTS(diag_e) at Fri Jan 24 04:29:03 2025.
#> 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).