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 7.7e-05 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.77 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.581 seconds (Warm-up)
#> Chain 1:                0.617 seconds (Sampling)
#> Chain 1:                1.198 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.568 seconds (Warm-up)
#> Chain 2:                0.579 seconds (Sampling)
#> Chain 2:                1.147 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.691 seconds (Warm-up)
#> Chain 3:                0.613 seconds (Sampling)
#> Chain 3:                1.304 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.55 seconds (Warm-up)
#> Chain 4:                0.631 seconds (Sampling)
#> Chain 4:                1.181 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.14    0.06    1.40    2.59    4.17    5.07    6.01    8.17
#> rt_est            1.04    0.00    0.09    0.86    0.99    1.04    1.10    1.20
#> incid_est[1]    526.69   85.62 1539.79   13.30   64.77  159.10  407.01 3517.09
#> incid_est[2]      8.32    1.19   21.45    0.28    1.25    2.91    7.02   52.78
#> incid_est[3]     41.01    5.85  105.72    1.38    6.14   14.33   34.62  260.14
#> incid_est[4]     61.24    8.72  157.49    2.07    9.21   21.46   51.76  387.99
#> incid_est[5]     68.88    9.74  175.97    2.37   10.47   24.33   58.49  435.03
#> incid_est[6]     71.24    9.95  179.91    2.52   11.03   25.49   60.94  447.45
#> incid_est[7]     71.53    9.84  178.00    2.63   11.33   26.04   61.73  446.33
#> incid_est[8]     71.06    9.60  173.84    2.72   11.55   26.35   61.95  440.26
#> incid_est[9]     70.32    9.32  168.91    2.80   11.76   26.59   61.99  431.90
#> incid_est[10]    69.50    9.03  163.79    2.89   11.95   26.82   61.94  422.87
#> incid_est[11]    68.67    8.74  158.72    2.98   12.15   27.02   61.86  414.55
#> incid_est[12]    67.85    8.46  153.77    3.08   12.34   27.24   61.80  406.34
#> incid_est[13]    67.05    8.19  148.98    3.17   12.54   27.44   61.79  398.26
#> incid_est[14]    66.27    7.92  144.34    3.27   12.74   27.66   61.78  390.23
#> incid_est[15]    65.52    7.67  139.85    3.38   12.95   27.88   61.73  382.21
#> incid_est[16]    64.79    7.42  135.52    3.49   13.15   28.11   61.63  374.36
#> incid_est[17]    64.08    7.19  131.34    3.60   13.36   28.33   61.61  366.66
#> incid_est[18]    63.39    6.96  127.30    3.72   13.57   28.55   61.54  359.12
#> incid_est[19]    62.73    6.73  123.39    3.83   13.79   28.77   61.47  351.74
#> incid_est[20]    62.08    6.52  119.62    3.95   14.01   28.99   61.39  344.67
#> incid_est[21]    61.46    6.31  115.97    4.08   14.23   29.21   61.32  337.88
#> incid_est[22]    60.03    5.99  110.34    4.19   14.35   29.16   60.51  326.06
#> incid_est[23]    59.64    5.83  107.46    4.32   14.61   29.45   60.55  320.81
#> incid_est[24]    59.12    5.65  104.31    4.45   14.85   29.69   60.51  314.72
#> incid_est[25]    58.54    5.46  101.09    4.58   15.09   29.90   60.45  308.28
#> incid_est[26]    57.96    5.28   97.92    4.72   15.31   30.11   60.32  301.83
#> incid_est[27]    57.39    5.11   94.84    4.87   15.54   30.33   60.18  295.49
#> incid_est[28]    56.83    4.94   91.87    5.02   15.78   30.53   60.04  289.03
#> incid_est[29]    56.30    4.78   89.01    5.18   16.03   30.74   59.90  282.34
#> incid_est[30]    55.79    4.62   86.24    5.35   16.29   30.93   59.76  275.80
#> incid_est[31]    55.29    4.47   83.56    5.51   16.53   31.15   59.63  269.42
#> incid_est[32]    54.81    4.32   80.98    5.68   16.78   31.37   59.47  263.19
#> incid_est[33]    54.35    4.18   78.48    5.84   17.04   31.60   59.32  257.10
#> incid_est[34]    53.90    4.04   76.06    6.02   17.29   31.83   59.24  251.37
#> incid_est[35]    53.47    3.91   73.73    6.21   17.56   32.09   59.14  245.87
#> incid_est[36]    53.06    3.78   71.47    6.41   17.82   32.34   59.01  240.49
#> incid_est[37]    52.66    3.66   69.29    6.61   18.09   32.57   58.88  235.23
#> incid_est[38]    52.27    3.54   67.17    6.81   18.37   32.80   58.78  230.08
#> incid_est[39]    51.90    3.42   65.13    7.03   18.67   33.03   58.68  225.04
#> incid_est[40]    51.54    3.31   63.15    7.25   18.96   33.28   58.59  220.12
#> incid_est[41]    51.20    3.20   61.24    7.48   19.23   33.50   58.48  215.30
#> incid_est[42]    50.87    3.10   59.38    7.71   19.51   33.74   58.32  210.62
#> incid_est[43]    50.56    3.00   57.59    7.95   19.82   33.93   58.18  206.21
#> incid_est[44]    50.26    2.90   55.85    8.20   20.14   34.16   58.08  201.63
#> incid_est[45]    49.97    2.80   54.17    8.46   20.46   34.36   57.94  197.13
#> incid_est[46]    49.69    2.71   52.54    8.72   20.78   34.57   57.81  192.77
#> incid_est[47]    49.43    2.62   50.95    8.98   21.12   34.83   57.68  188.54
#> incid_est[48]    49.17    2.54   49.42    9.25   21.44   35.06   57.49  184.25
#> incid_est[49]    48.93    2.46   47.93    9.52   21.78   35.30   57.33  180.15
#> incid_est[50]    48.71    2.37   46.49    9.80   22.11   35.57   57.23  176.13
#> incid_est[51]    48.49    2.30   45.09   10.09   22.44   35.76   57.12  172.21
#> incid_est[52]    48.28    2.22   43.72   10.40   22.78   36.00   56.97  168.38
#> incid_est[53]    48.09    2.15   42.40   10.72   23.14   36.27   56.86  164.63
#> incid_est[54]    47.91    2.08   41.12   11.06   23.50   36.52   56.75  160.97
#> incid_est[55]    47.74    2.01   39.87   11.41   23.86   36.73   56.67  157.38
#> incid_est[56]    47.58    1.94   38.66   11.78   24.23   36.95   56.58  153.88
#> incid_est[57]    47.43    1.88   37.48   12.15   24.61   37.22   56.47  150.45
#> incid_est[58]    47.29    1.81   36.33   12.54   24.99   37.49   56.36  147.10
#> incid_est[59]    47.16    1.75   35.21   12.93   25.37   37.74   56.27  143.83
#> incid_est[60]    47.04    1.69   34.12   13.32   25.77   37.95   56.15  140.62
#> incid_est[61]    46.93    1.64   33.06   13.72   26.16   38.19   56.00  137.48
#> incid_est[62]    46.83    1.58   32.03   14.13   26.55   38.45   55.87  134.42
#> incid_est[63]    46.75    1.52   31.02   14.55   26.96   38.68   55.79  131.35
#> incid_est[64]    46.67    1.47   30.04   15.04   27.38   38.92   55.70  128.49
#> incid_est[65]    46.60    1.42   29.08   15.51   27.83   39.25   55.62  125.63
#> incid_est[66]    46.54    1.37   28.14   15.98   28.29   39.50   55.57  122.73
#> incid_est[67]    46.49    1.32   27.22   16.47   28.74   39.77   55.53  119.88
#> incid_est[68]    46.45    1.27   26.33   16.97   29.21   40.00   55.34  117.09
#> incid_est[69]    46.42    1.23   25.45   17.47   29.68   40.27   55.22  114.36
#> incid_est[70]    46.40    1.18   24.59   17.98   30.14   40.52   55.16  111.70
#> incid_est[71]    46.39    1.14   23.75   18.52   30.63   40.77   55.05  109.10
#> incid_est[72]    46.39    1.09   22.93   19.10   31.09   41.02   54.95  106.80
#> incid_est[73]    46.39    1.05   22.12   19.70   31.55   41.30   54.80  104.43
#> incid_est[74]    46.41    1.01   21.33   20.31   32.08   41.59   54.62  102.04
#> incid_est[75]    46.44    0.97   20.55   20.93   32.59   41.85   54.52  100.03
#> incid_est[76]    46.47    0.93   19.79   21.56   33.10   42.12   54.51   98.06
#> incid_est[77]    46.52    0.89   19.03   22.16   33.62   42.36   54.40   95.89
#> incid_est[78]    46.57    0.85   18.30   22.80   34.12   42.64   54.30   93.97
#> incid_est[79]    46.63    0.82   17.57   23.45   34.64   42.98   54.21   91.77
#> incid_est[80]    46.71    0.78   16.85   24.11   35.15   43.29   54.08   89.73
#> incid_est[81]    46.79    0.75   16.15   24.80   35.68   43.53   54.00   87.70
#> incid_est[82]    46.88    0.71   15.45   25.50   36.26   43.80   53.87   86.10
#> incid_est[83]    46.98    0.68   14.77   26.25   36.80   44.11   53.79   84.37
#> incid_est[84]    47.09    0.64   14.09   27.10   37.37   44.41   53.78   82.26
#> incid_est[85]    47.20    0.61   13.42   27.90   37.94   44.73   53.72   80.36
#> incid_est[86]    47.33    0.58   12.77   28.76   38.50   45.08   53.64   78.68
#> incid_est[87]    47.47    0.54   12.11   29.66   39.10   45.42   53.54   76.93
#> incid_est[88]    47.61    0.51   11.47   30.61   39.71   45.70   53.48   75.22
#> incid_est[89]    47.77    0.48   10.84   31.44   40.29   46.11   53.34   74.03
#> incid_est[90]    47.93    0.45   10.21   32.29   40.91   46.44   53.24   72.67
#> incid_est[91]    48.11    0.42    9.59   33.20   41.46   46.77   53.24   71.27
#> incid_est[92]    48.29    0.39    8.98   34.10   42.10   47.13   53.20   70.06
#> incid_est[93]    48.49    0.36    8.38   35.02   42.69   47.49   53.20   68.46
#> incid_est[94]    48.69    0.33    7.79   35.96   43.34   47.79   53.17   67.02
#> incid_est[95]    48.90    0.30    7.21   36.83   43.92   48.12   53.12   65.73
#> incid_est[96]    49.12    0.27    6.65   37.87   44.51   48.48   53.06   64.23
#> incid_est[97]    49.36    0.24    6.10   38.76   45.11   48.77   53.07   63.09
#> incid_est[98]    49.60    0.21    5.58   39.84   45.76   49.19   53.10   61.98
#> incid_est[99]    49.85    0.18    5.09   40.80   46.37   49.52   53.02   60.89
#> incid_est[100]   50.12    0.16    4.65   41.69   46.96   49.83   53.10   59.92
#> incid_est[101]   50.39    0.13    4.25   42.60   47.48   50.21   53.17   59.12
#> incid_est[102]   50.67    0.10    3.94   43.28   47.99   50.59   53.26   58.63
#> incid_est[103]   50.97    0.08    3.71   43.88   48.42   50.89   53.33   58.44
#> incid_est[104]   51.27    0.06    3.60   44.43   48.86   51.24   53.68   58.36
#> incid_est[105]   51.59    0.06    3.61   44.77   49.13   51.53   54.01   58.99
#> incid_est[106]   51.92    0.07    3.76   44.85   49.32   51.85   54.45   59.63
#> incid_est[107]   52.25    0.09    4.02   44.57   49.46   52.18   54.93   60.30
#> incid_est[108]   52.60    0.12    4.38   44.34   49.57   52.50   55.53   61.41
#> incid_est[109]   52.97    0.14    4.82   43.76   49.64   52.83   56.25   62.61
#> incid_est[110]   53.34    0.17    5.33   43.37   49.68   53.22   56.94   64.07
#> incid_est[111]   53.72    0.20    5.89   42.63   49.70   53.56   57.61   65.51
#> incid_est[112]   54.12    0.23    6.49   41.85   49.66   53.95   58.35   67.12
#> incid_est[113]   54.53    0.26    7.13   41.19   49.59   54.29   59.10   68.88
#> incid_est[114]   54.95    0.29    7.79   40.54   49.56   54.64   59.93   70.85
#> incid_est[115]   55.38    0.32    8.49   39.92   49.46   54.95   60.82   72.72
#> incid_est[116]   55.83    0.35    9.20   39.27   49.38   55.39   61.68   74.91
#> incid_est[117]   56.29    0.39    9.94   38.59   49.26   55.78   62.61   77.20
#> lp__           1507.15    0.04    1.11 1504.22 1506.77 1507.51 1507.91 1508.17
#>                n_eff Rhat
#> log_i0           526 1.01
#> rt_est           538 1.01
#> incid_est[1]     323 1.02
#> incid_est[2]     326 1.02
#> incid_est[3]     326 1.02
#> incid_est[4]     326 1.02
#> incid_est[5]     327 1.02
#> incid_est[6]     327 1.02
#> incid_est[7]     327 1.02
#> incid_est[8]     328 1.02
#> incid_est[9]     328 1.02
#> incid_est[10]    329 1.02
#> incid_est[11]    330 1.02
#> incid_est[12]    330 1.02
#> incid_est[13]    331 1.02
#> incid_est[14]    332 1.02
#> incid_est[15]    332 1.02
#> incid_est[16]    333 1.02
#> incid_est[17]    334 1.02
#> incid_est[18]    335 1.02
#> incid_est[19]    336 1.02
#> incid_est[20]    337 1.02
#> incid_est[21]    338 1.02
#> incid_est[22]    339 1.02
#> incid_est[23]    340 1.02
#> incid_est[24]    341 1.02
#> incid_est[25]    342 1.02
#> incid_est[26]    343 1.02
#> incid_est[27]    345 1.01
#> incid_est[28]    346 1.01
#> incid_est[29]    347 1.01
#> incid_est[30]    348 1.01
#> incid_est[31]    350 1.01
#> incid_est[32]    351 1.01
#> incid_est[33]    353 1.01
#> incid_est[34]    354 1.01
#> incid_est[35]    356 1.01
#> incid_est[36]    357 1.01
#> incid_est[37]    359 1.01
#> incid_est[38]    360 1.01
#> incid_est[39]    362 1.01
#> incid_est[40]    364 1.01
#> incid_est[41]    366 1.01
#> incid_est[42]    367 1.01
#> incid_est[43]    369 1.01
#> incid_est[44]    371 1.01
#> incid_est[45]    373 1.01
#> incid_est[46]    375 1.01
#> incid_est[47]    377 1.01
#> incid_est[48]    379 1.01
#> incid_est[49]    381 1.01
#> incid_est[50]    383 1.01
#> incid_est[51]    385 1.01
#> incid_est[52]    388 1.01
#> incid_est[53]    390 1.01
#> incid_est[54]    392 1.01
#> incid_est[55]    394 1.01
#> incid_est[56]    397 1.01
#> incid_est[57]    399 1.01
#> incid_est[58]    402 1.01
#> incid_est[59]    404 1.01
#> incid_est[60]    406 1.01
#> incid_est[61]    409 1.01
#> incid_est[62]    411 1.01
#> incid_est[63]    414 1.01
#> incid_est[64]    417 1.01
#> incid_est[65]    419 1.01
#> incid_est[66]    422 1.01
#> incid_est[67]    425 1.01
#> incid_est[68]    427 1.01
#> incid_est[69]    430 1.01
#> incid_est[70]    433 1.01
#> incid_est[71]    436 1.01
#> incid_est[72]    439 1.01
#> incid_est[73]    442 1.01
#> incid_est[74]    445 1.01
#> incid_est[75]    448 1.01
#> incid_est[76]    451 1.01
#> incid_est[77]    455 1.01
#> incid_est[78]    458 1.01
#> incid_est[79]    462 1.01
#> incid_est[80]    465 1.01
#> incid_est[81]    469 1.01
#> incid_est[82]    473 1.01
#> incid_est[83]    477 1.01
#> incid_est[84]    482 1.01
#> incid_est[85]    486 1.01
#> incid_est[86]    491 1.01
#> incid_est[87]    497 1.01
#> incid_est[88]    503 1.01
#> incid_est[89]    510 1.01
#> incid_est[90]    518 1.01
#> incid_est[91]    527 1.01
#> incid_est[92]    537 1.01
#> incid_est[93]    550 1.01
#> incid_est[94]    566 1.01
#> incid_est[95]    586 1.01
#> incid_est[96]    613 1.01
#> incid_est[97]    649 1.00
#> incid_est[98]    701 1.00
#> incid_est[99]    777 1.00
#> incid_est[100]   897 1.00
#> incid_est[101]  1095 1.00
#> incid_est[102]  1441 1.00
#> incid_est[103]  2094 1.00
#> incid_est[104]  3634 1.00
#> incid_est[105]  3719 1.00
#> incid_est[106]  2757 1.00
#> incid_est[107]  1905 1.00
#> incid_est[108]  1434 1.00
#> incid_est[109]  1156 1.00
#> incid_est[110]   987 1.00
#> incid_est[111]   881 1.00
#> incid_est[112]   810 1.00
#> incid_est[113]   761 1.00
#> incid_est[114]   726 1.00
#> incid_est[115]   700 1.00
#> incid_est[116]   680 1.00
#> incid_est[117]   665 1.00
#> lp__             640 1.00
#> 
#> Samples were drawn using NUTS(diag_e) at Sun Feb 23 04:34:19 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).