Case Study - Fitting SARS-CoV-2

library(intervalcalc)

Prepare the data

First, we’ll prepare some data:

dat <- prep_interval_data(nishiura)

Fit the Models

Now using the formatted data, we can pass the data to a series of or a particular distribution.

fits <- fit_interval_data(interval_data = dat, distribution = c("gamma", "lognormal"))

We can then inspect the outputs:

knitr::kable(fits$gamma$sumz, digits = 2)
variable mean median sd mad q5 q95 rhat ess_bulk ess_tail
mean_SI 4.78 4.74 0.53 0.49 3.99 5.71 1 5559.77 2831.91
sd_SI 2.69 2.63 0.49 0.43 2.01 3.59 1 5767.14 2527.93
knitr::kable(fits$lognormal$sumz, digits = 2)
variable mean median sd mad q5 q95 rhat ess_bulk ess_tail
mean_SI 4.58 4.54 0.52 0.49 3.82 5.50 1 5625.39 2926.98
sd_SI 2.77 2.66 0.64 0.57 1.94 3.96 1 5027.21 2860.47
fits$gamma$loo
#> $estimates
#>            Estimate        SE
#> elpd_loo -64.610845 3.6541095
#> p_loo      2.171795 0.5305752
#> looic    129.221691 7.3082189
#> 
#> $pointwise
#>              elpd_loo mcse_elpd_loo      p_loo    looic influence_pareto_k
#> log_lik[1]  -1.806464   0.002264893 0.02396319 3.612929       -0.060993477
#> log_lik[2]  -2.068682   0.005306539 0.09046674 4.137364        0.222498206
#> log_lik[3]  -1.830479   0.002196412 0.02289221 3.660959       -0.035166412
#> log_lik[4]  -2.078758   0.005464006 0.09484101 4.157515        0.158690002
#> log_lik[5]  -2.075751   0.005573051 0.09334323 4.151503        0.279970031
#> log_lik[6]  -3.035251   0.025730374 0.51967982 6.070503        0.555487516
#> log_lik[7]  -1.830642   0.002178357 0.02301240 3.661284        0.049294172
#> log_lik[8]  -2.068492   0.005479298 0.09160995 4.136984        0.310881006
#> log_lik[9]  -3.989165   0.007792193 0.21077244 7.978331        0.280180649
#> log_lik[10] -1.831193   0.002241732 0.02296319 3.662385       -0.042839035
#> log_lik[11] -1.806975   0.002342435 0.02421447 3.613949        0.143633760
#> log_lik[12] -1.831049   0.002283885 0.02341364 3.662098       -0.015314334
#> log_lik[13] -1.829117   0.002294826 0.02340209 3.658233       -0.003801884
#> log_lik[14] -1.808858   0.002344014 0.02461010 3.617716        0.211677113
#> log_lik[15] -1.804526   0.002187373 0.02360988 3.609052        0.142984771
#> log_lik[16] -3.486273   0.005678628 0.13471984 6.972546        0.256869141
#> log_lik[17] -3.489885   0.005517784 0.13590707 6.979771        0.130099761
#> log_lik[18] -1.807286   0.002354947 0.02499681 3.614572        0.161009797
#> log_lik[19] -1.831307   0.002228740 0.02319458 3.662615        0.027199200
#> log_lik[20] -1.807065   0.002330861 0.02482729 3.614130        0.031479053
#> log_lik[21] -3.484450   0.005610820 0.13661387 6.968901        0.097604357
#> log_lik[22] -1.829657   0.002309563 0.02331380 3.659314       -0.017268853
#> log_lik[23] -2.007800   0.002708199 0.03060905 4.015600       -0.111356284
#> log_lik[24] -3.483285   0.005665523 0.13286829 6.966569        0.304212692
#> log_lik[25] -2.628032   0.003432614 0.05586874 5.256063        0.251433720
#> log_lik[26] -2.625345   0.003262226 0.05487962 5.250690        0.059252714
#> log_lik[27] -1.807508   0.002248207 0.02470517 3.615016        0.154399750
#> log_lik[28] -2.627549   0.003400799 0.05649628 5.255099        0.194313032
#> 
#> $diagnostics
#> $diagnostics$pareto_k
#>  [1] -0.060993477  0.222498206 -0.035166412  0.158690002  0.279970031
#>  [6]  0.555487516  0.049294172  0.310881006  0.280180649 -0.042839035
#> [11]  0.143633760 -0.015314334 -0.003801884  0.211677113  0.142984771
#> [16]  0.256869141  0.130099761  0.161009797  0.027199200  0.031479053
#> [21]  0.097604357 -0.017268853 -0.111356284  0.304212692  0.251433720
#> [26]  0.059252714  0.154399750  0.194313032
#> 
#> $diagnostics$n_eff
#>  log_lik[1]  log_lik[2]  log_lik[3]  log_lik[4]  log_lik[5]  log_lik[6] 
#>    4957.730    4662.324    4895.280    4659.483    4673.876    1131.784 
#>  log_lik[7]  log_lik[8]  log_lik[9] log_lik[10] log_lik[11] log_lik[12] 
#>    4988.788    4481.970    4578.032    4667.193    4751.256    4617.700 
#> log_lik[13] log_lik[14] log_lik[15] log_lik[16] log_lik[17] log_lik[18] 
#>    4544.236    4801.100    5247.794    5315.606    5394.980    4850.263 
#> log_lik[19] log_lik[20] log_lik[21] log_lik[22] log_lik[23] log_lik[24] 
#>    4760.141    4841.903    5256.224    4472.469    4246.721    5259.481 
#> log_lik[25] log_lik[26] log_lik[27] log_lik[28] 
#>    5349.086    5580.340    5285.410    5292.074 
#> 
#> 
#> $psis_object
#> NULL
#> 
#> $elpd_loo
#> [1] -64.61085
#> 
#> $p_loo
#> [1] 2.171795
#> 
#> $looic
#> [1] 129.2217
#> 
#> $se_elpd_loo
#> [1] 3.654109
#> 
#> $se_p_loo
#> [1] 0.5305752
#> 
#> $se_looic
#> [1] 7.308219
#> 
#> attr(,"dims")
#> [1] 4000   28
#> attr(,"class")
#> [1] "psis_loo"                "importance_sampling_loo"
#> [3] "loo"

Determine Best Fit

loo::loo_compare(fits$gamma$loo, fits$lognormal$loo)
#>        elpd_diff se_diff
#> model2  0.0       0.0   
#> model1 -0.4       1.1