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 5.4e-05 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.54 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.575 seconds (Warm-up)
#> Chain 1:                0.718 seconds (Sampling)
#> Chain 1:                1.293 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.561 seconds (Warm-up)
#> Chain 2:                0.579 seconds (Sampling)
#> Chain 2:                1.14 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.566 seconds (Warm-up)
#> Chain 3:                0.674 seconds (Sampling)
#> Chain 3:                1.24 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.522 seconds (Warm-up)
#> Chain 4:                0.619 seconds (Sampling)
#> Chain 4:                1.141 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            5.08    0.07    1.47    2.40    4.02    5.05    6.06    7.96
#> rt_est            1.05    0.00    0.09    0.87    0.98    1.05    1.11    1.22
#> incid_est[1]    496.14   65.67 1370.73   11.07   55.88  155.30  426.28 2872.86
#> incid_est[2]      7.91    0.92   19.20    0.24    1.09    2.83    7.34   43.86
#> incid_est[3]     39.00    4.55   94.61    1.17    5.36   13.97   36.17  216.18
#> incid_est[4]     58.23    6.78  140.95    1.75    8.04   20.92   54.09  322.51
#> incid_est[5]     65.53    7.58  157.54    2.01    9.15   23.71   61.10  361.89
#> incid_est[6]     67.82    7.76  161.15    2.14    9.65   24.83   63.63  372.76
#> incid_est[7]     68.17    7.68  159.54    2.23    9.93   25.33   64.49  372.59
#> incid_est[8]     67.79    7.51  155.93    2.31   10.14   25.64   64.70  368.06
#> incid_est[9]     67.16    7.31  151.64    2.39   10.33   25.88   64.69  361.75
#> incid_est[10]    66.46    7.10  147.19    2.47   10.51   26.09   64.62  354.95
#> incid_est[11]    65.73    6.88  142.76    2.55   10.69   26.28   64.55  348.07
#> incid_est[12]    65.02    6.68  138.45    2.64   10.87   26.48   64.46  341.25
#> incid_est[13]    64.33    6.48  134.27    2.72   11.07   26.66   64.35  334.53
#> incid_est[14]    63.65    6.29  130.22    2.81   11.27   26.87   64.25  327.94
#> incid_est[15]    62.99    6.10  126.31    2.90   11.46   27.08   64.15  321.80
#> incid_est[16]    62.35    5.92  122.53    3.00   11.67   27.28   64.05  315.78
#> incid_est[17]    61.73    5.75  118.88    3.10   11.87   27.51   63.99  309.86
#> incid_est[18]    61.13    5.58  115.35    3.20   12.08   27.75   63.93  304.06
#> incid_est[19]    60.55    5.41  111.94    3.31   12.30   27.94   63.89  298.37
#> incid_est[20]    59.98    5.26  108.65    3.42   12.52   28.14   63.81  292.78
#> incid_est[21]    59.43    5.10  105.47    3.53   12.73   28.35   63.72  287.30
#> incid_est[22]    58.11    4.86  100.51    3.62   12.85   28.30   62.87  277.59
#> incid_est[23]    57.79    4.74   98.00    3.75   13.11   28.60   62.91  273.37
#> incid_est[24]    57.33    4.61   95.25    3.87   13.34   28.85   62.85  268.45
#> incid_est[25]    56.81    4.48   92.43    4.00   13.56   29.10   62.73  263.22
#> incid_est[26]    56.29    4.34   89.66    4.13   13.80   29.33   62.57  257.98
#> incid_est[27]    55.78    4.21   86.97    4.27   14.04   29.56   62.40  252.82
#> incid_est[28]    55.28    4.09   84.36    4.41   14.29   29.77   62.19  247.77
#> incid_est[29]    54.81    3.97   81.85    4.55   14.55   29.98   61.97  242.82
#> incid_est[30]    54.34    3.85   79.42    4.70   14.81   30.19   61.78  237.97
#> incid_est[31]    53.90    3.73   77.08    4.85   15.05   30.42   61.63  233.20
#> incid_est[32]    53.46    3.62   74.81    5.01   15.30   30.67   61.47  228.38
#> incid_est[33]    53.05    3.52   72.61    5.18   15.55   30.92   61.28  223.69
#> incid_est[34]    52.64    3.41   70.49    5.35   15.82   31.13   61.07  219.52
#> incid_est[35]    52.25    3.32   68.44    5.52   16.10   31.35   60.87  215.13
#> incid_est[36]    51.88    3.22   66.45    5.70   16.38   31.57   60.69  210.83
#> incid_est[37]    51.52    3.13   64.53    5.87   16.64   31.77   60.59  206.63
#> incid_est[38]    51.17    3.03   62.67    6.06   16.93   31.98   60.51  202.51
#> incid_est[39]    50.83    2.95   60.86    6.25   17.23   32.23   60.38  198.47
#> incid_est[40]    50.50    2.86   59.11    6.46   17.55   32.46   60.21  194.51
#> incid_est[41]    50.19    2.78   57.42    6.67   17.85   32.68   60.00  190.69
#> incid_est[42]    49.89    2.70   55.78    6.88   18.14   32.90   59.84  186.79
#> incid_est[43]    49.61    2.62   54.19    7.10   18.44   33.14   59.63  183.13
#> incid_est[44]    49.33    2.55   52.65    7.32   18.75   33.37   59.45  179.44
#> incid_est[45]    49.07    2.47   51.16    7.56   19.08   33.59   59.32  175.83
#> incid_est[46]    48.81    2.40   49.71    7.79   19.40   33.84   59.18  172.32
#> incid_est[47]    48.57    2.33   48.30    8.04   19.72   34.08   59.04  168.88
#> incid_est[48]    48.34    2.27   46.93    8.30   20.05   34.31   58.93  165.50
#> incid_est[49]    48.13    2.20   45.60    8.57   20.39   34.54   58.78  162.19
#> incid_est[50]    47.92    2.14   44.31    8.85   20.74   34.79   58.64  158.95
#> incid_est[51]    47.72    2.08   43.06    9.13   21.09   35.06   58.49  155.77
#> incid_est[52]    47.53    2.02   41.83    9.43   21.46   35.30   58.35  152.66
#> incid_est[53]    47.36    1.96   40.65    9.73   21.84   35.54   58.24  149.61
#> incid_est[54]    47.19    1.90   39.49   10.05   22.22   35.79   58.12  146.62
#> incid_est[55]    47.04    1.85   38.37   10.37   22.60   36.06   57.98  143.69
#> incid_est[56]    46.89    1.79   37.27   10.71   23.00   36.34   57.80  140.82
#> incid_est[57]    46.76    1.74   36.20   11.05   23.40   36.58   57.65  137.97
#> incid_est[58]    46.63    1.69   35.16   11.41   23.79   36.83   57.51  135.25
#> incid_est[59]    46.52    1.64   34.14   11.78   24.15   37.12   57.37  132.55
#> incid_est[60]    46.41    1.60   33.15   12.16   24.55   37.41   57.19  129.90
#> incid_est[61]    46.32    1.55   32.18   12.56   24.97   37.72   57.04  127.31
#> incid_est[62]    46.23    1.50   31.23   12.96   25.37   38.00   56.93  124.69
#> incid_est[63]    46.15    1.46   30.31   13.38   25.79   38.27   56.82  122.09
#> incid_est[64]    46.09    1.41   29.40   13.82   26.20   38.52   56.74  119.54
#> incid_est[65]    46.03    1.37   28.51   14.26   26.62   38.80   56.57  117.07
#> incid_est[66]    45.98    1.33   27.64   14.72   27.03   39.04   56.48  114.93
#> incid_est[67]    45.94    1.29   26.79   15.20   27.50   39.34   56.42  112.79
#> incid_est[68]    45.92    1.25   25.96   15.68   27.94   39.61   56.27  110.54
#> incid_est[69]    45.90    1.21   25.14   16.18   28.41   39.86   56.19  108.33
#> incid_est[70]    45.89    1.17   24.34   16.70   28.88   40.09   56.02  106.17
#> incid_est[71]    45.89    1.13   23.55   17.24   29.39   40.39   55.95  104.05
#> incid_est[72]    45.89    1.09   22.77   17.79   29.88   40.67   55.88  101.97
#> incid_est[73]    45.91    1.05   22.01   18.36   30.36   40.99   55.69   99.94
#> incid_est[74]    45.94    1.02   21.26   18.95   30.88   41.22   55.63   97.94
#> incid_est[75]    45.98    0.98   20.52   19.56   31.35   41.58   55.60   95.98
#> incid_est[76]    46.02    0.95   19.79   20.16   31.84   41.86   55.47   94.06
#> incid_est[77]    46.08    0.91   19.07   20.83   32.37   42.18   55.30   92.19
#> incid_est[78]    46.14    0.88   18.36   21.47   32.90   42.45   55.16   90.34
#> incid_est[79]    46.22    0.84   17.66   22.17   33.47   42.79   55.02   88.54
#> incid_est[80]    46.30    0.81   16.96   22.91   34.06   43.08   54.95   86.78
#> incid_est[81]    46.39    0.78   16.28   23.64   34.65   43.39   54.80   85.04
#> incid_est[82]    46.50    0.74   15.60   24.36   35.27   43.70   54.72   83.32
#> incid_est[83]    46.61    0.71   14.93   25.09   35.86   44.02   54.50   81.42
#> incid_est[84]    46.73    0.68   14.27   25.91   36.40   44.33   54.43   79.84
#> incid_est[85]    46.86    0.64   13.61   26.82   36.98   44.66   54.36   78.34
#> incid_est[86]    47.00    0.61   12.95   27.68   37.59   44.97   54.21   76.84
#> incid_est[87]    47.16    0.58   12.31   28.56   38.25   45.30   54.10   75.34
#> incid_est[88]    47.32    0.55   11.67   29.44   38.92   45.62   54.05   73.84
#> incid_est[89]    47.49    0.52   11.03   30.28   39.54   45.98   53.89   72.36
#> incid_est[90]    47.67    0.48   10.40   31.24   40.16   46.32   53.86   70.92
#> incid_est[91]    47.86    0.45    9.77   32.18   40.84   46.65   53.75   69.62
#> incid_est[92]    48.06    0.42    9.15   33.10   41.51   46.97   53.66   68.19
#> incid_est[93]    48.28    0.39    8.54   34.18   42.13   47.30   53.51   67.14
#> incid_est[94]    48.50    0.36    7.93   35.24   42.78   47.68   53.42   65.94
#> incid_est[95]    48.73    0.32    7.34   36.32   43.49   48.03   53.28   64.82
#> incid_est[96]    48.98    0.29    6.75   37.45   44.17   48.32   53.23   63.65
#> incid_est[97]    49.23    0.26    6.18   38.37   44.88   48.70   53.14   62.38
#> incid_est[98]    49.50    0.23    5.64   39.49   45.54   49.10   53.06   61.30
#> incid_est[99]    49.78    0.19    5.12   40.60   46.22   49.50   53.04   60.45
#> incid_est[100]   50.07    0.16    4.64   41.61   46.84   49.87   53.07   59.68
#> incid_est[101]   50.37    0.13    4.22   42.57   47.41   50.26   53.09   59.00
#> incid_est[102]   50.68    0.10    3.87   43.26   48.02   50.62   53.19   58.48
#> incid_est[103]   51.00    0.08    3.63   43.99   48.49   50.96   53.36   58.44
#> incid_est[104]   51.34    0.06    3.51   44.57   48.91   51.28   53.68   58.50
#> incid_est[105]   51.69    0.06    3.54   44.95   49.22   51.57   54.01   58.99
#> incid_est[106]   52.05    0.07    3.71   45.03   49.49   51.85   54.50   59.66
#> incid_est[107]   52.42    0.10    4.01   45.03   49.68   52.18   55.08   60.68
#> incid_est[108]   52.80    0.13    4.43   44.66   49.84   52.53   55.72   62.02
#> incid_est[109]   53.20    0.17    4.93   44.41   49.74   52.94   56.45   63.55
#> incid_est[110]   53.62    0.20    5.50   43.84   49.72   53.35   57.16   65.15
#> incid_est[111]   54.04    0.24    6.12   43.18   49.66   53.77   57.98   66.92
#> incid_est[112]   54.48    0.28    6.79   42.62   49.59   54.20   58.85   68.70
#> incid_est[113]   54.94    0.31    7.49   41.90   49.51   54.63   59.79   70.50
#> incid_est[114]   55.40    0.35    8.23   41.29   49.47   54.98   60.67   72.39
#> incid_est[115]   55.89    0.40    9.00   40.64   49.36   55.44   61.59   74.50
#> incid_est[116]   56.38    0.44    9.79   39.90   49.28   55.85   62.61   76.71
#> incid_est[117]   56.90    0.49   10.61   39.19   49.12   56.24   63.66   78.92
#> lp__           1507.14    0.04    1.05 1504.36 1506.69 1507.46 1507.90 1508.17
#>                n_eff Rhat
#> log_i0           391 1.01
#> rt_est           382 1.01
#> incid_est[1]     436 1.01
#> incid_est[2]     432 1.01
#> incid_est[3]     432 1.01
#> incid_est[4]     432 1.01
#> incid_est[5]     432 1.01
#> incid_est[6]     432 1.01
#> incid_est[7]     431 1.01
#> incid_est[8]     431 1.01
#> incid_est[9]     431 1.01
#> incid_est[10]    430 1.01
#> incid_est[11]    430 1.01
#> incid_est[12]    430 1.01
#> incid_est[13]    429 1.01
#> incid_est[14]    429 1.01
#> incid_est[15]    429 1.01
#> incid_est[16]    428 1.01
#> incid_est[17]    428 1.01
#> incid_est[18]    428 1.01
#> incid_est[19]    428 1.01
#> incid_est[20]    427 1.01
#> incid_est[21]    427 1.01
#> incid_est[22]    427 1.01
#> incid_est[23]    427 1.01
#> incid_est[24]    427 1.01
#> incid_est[25]    426 1.01
#> incid_est[26]    426 1.01
#> incid_est[27]    426 1.01
#> incid_est[28]    426 1.01
#> incid_est[29]    426 1.01
#> incid_est[30]    426 1.01
#> incid_est[31]    426 1.01
#> incid_est[32]    426 1.01
#> incid_est[33]    426 1.01
#> incid_est[34]    426 1.01
#> incid_est[35]    426 1.01
#> incid_est[36]    426 1.01
#> incid_est[37]    426 1.01
#> incid_est[38]    426 1.01
#> incid_est[39]    427 1.01
#> incid_est[40]    427 1.01
#> incid_est[41]    427 1.01
#> incid_est[42]    427 1.01
#> incid_est[43]    427 1.01
#> incid_est[44]    428 1.01
#> incid_est[45]    428 1.01
#> incid_est[46]    428 1.01
#> incid_est[47]    428 1.01
#> incid_est[48]    429 1.01
#> incid_est[49]    429 1.01
#> incid_est[50]    429 1.01
#> incid_est[51]    430 1.01
#> incid_est[52]    430 1.01
#> incid_est[53]    431 1.01
#> incid_est[54]    431 1.01
#> incid_est[55]    431 1.01
#> incid_est[56]    431 1.01
#> incid_est[57]    431 1.01
#> incid_est[58]    432 1.01
#> incid_est[59]    432 1.01
#> incid_est[60]    432 1.01
#> incid_est[61]    432 1.01
#> incid_est[62]    432 1.01
#> incid_est[63]    432 1.01
#> incid_est[64]    433 1.01
#> incid_est[65]    433 1.01
#> incid_est[66]    433 1.01
#> incid_est[67]    433 1.01
#> incid_est[68]    434 1.01
#> incid_est[69]    434 1.01
#> incid_est[70]    434 1.01
#> incid_est[71]    435 1.01
#> incid_est[72]    435 1.01
#> incid_est[73]    435 1.01
#> incid_est[74]    436 1.01
#> incid_est[75]    436 1.01
#> incid_est[76]    437 1.01
#> incid_est[77]    438 1.01
#> incid_est[78]    438 1.01
#> incid_est[79]    439 1.01
#> incid_est[80]    440 1.01
#> incid_est[81]    441 1.01
#> incid_est[82]    442 1.01
#> incid_est[83]    443 1.01
#> incid_est[84]    445 1.01
#> incid_est[85]    447 1.01
#> incid_est[86]    449 1.01
#> incid_est[87]    452 1.01
#> incid_est[88]    455 1.01
#> incid_est[89]    458 1.01
#> incid_est[90]    463 1.01
#> incid_est[91]    469 1.01
#> incid_est[92]    476 1.01
#> incid_est[93]    486 1.01
#> incid_est[94]    498 1.01
#> incid_est[95]    514 1.00
#> incid_est[96]    537 1.00
#> incid_est[97]    569 1.00
#> incid_est[98]    617 1.00
#> incid_est[99]    691 1.00
#> incid_est[100]   815 1.00
#> incid_est[101]  1048 1.00
#> incid_est[102]  1457 1.00
#> incid_est[103]  2309 1.00
#> incid_est[104]  3563 1.00
#> incid_est[105]  3754 1.00
#> incid_est[106]  2574 1.00
#> incid_est[107]  1564 1.00
#> incid_est[108]  1109 1.00
#> incid_est[109]   872 1.00
#> incid_est[110]   740 1.00
#> incid_est[111]   659 1.00
#> incid_est[112]   605 1.00
#> incid_est[113]   569 1.00
#> incid_est[114]   542 1.00
#> incid_est[115]   511 1.00
#> incid_est[116]   487 1.00
#> incid_est[117]   468 1.00
#> lp__             656 1.01
#> 
#> Samples were drawn using NUTS(diag_e) at Tue Aug 27 05:09:47 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).