Retrieve MCMC convergence diagnostics for a rater fit

mcmc_diagnostics(fit, pars = c("pi", "theta"))

Arguments

fit

An rater mcmc_fit object.

pars

A character vector of parameter names to return. By default c("pi", "theta").

Value

A matrix where the columns represent different diagnostics and the rows are different parameters. Currently the first column contains the Rhat statistic and the second bulk effective samples size. The rownames contain the parameter names.

Details

MCMC diagnostics cannot be calculate for the z due to the marginalisation used to fit the models.

These MCMC diagnostics are intended as basic sanity check of the quality of the MCMC samples returned. Users who want more in depth diagnostics should consider using as_mcmc.list() to convert the samples to a coda::mcmc.list() object, or get_stanfit() to extract the underlying stanfit object.

References

Aki Vehtari, Andrew Gelman, Daniel Simpson, Bob Carpenter, and Paul-Christian Bürkner (2019). Rank-normalization, folding, and localization: An improved R-hat for assessing convergence of MCMC. arXiv preprint arXiv:1903.08008.

Examples

# \donttest{

fit <- rater(anesthesia, "dawid_skene")
#> 
#> SAMPLING FOR MODEL 'dawid_skene' NOW (CHAIN 1).
#> Chain 1: 
#> Chain 1: Gradient evaluation took 9.1e-05 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.91 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: 1.289 seconds (Warm-up)
#> Chain 1:                1.373 seconds (Sampling)
#> Chain 1:                2.662 seconds (Total)
#> Chain 1: 
#> 
#> SAMPLING FOR MODEL 'dawid_skene' NOW (CHAIN 2).
#> Chain 2: 
#> Chain 2: Gradient evaluation took 8.6e-05 seconds
#> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.86 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: 1.259 seconds (Warm-up)
#> Chain 2:                1.166 seconds (Sampling)
#> Chain 2:                2.425 seconds (Total)
#> Chain 2: 
#> 
#> SAMPLING FOR MODEL 'dawid_skene' NOW (CHAIN 3).
#> Chain 3: 
#> Chain 3: Gradient evaluation took 8.7e-05 seconds
#> Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0.87 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: 1.247 seconds (Warm-up)
#> Chain 3:                1.347 seconds (Sampling)
#> Chain 3:                2.594 seconds (Total)
#> Chain 3: 
#> 
#> SAMPLING FOR MODEL 'dawid_skene' NOW (CHAIN 4).
#> Chain 4: 
#> Chain 4: Gradient evaluation took 8.6e-05 seconds
#> Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0.86 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: 1.255 seconds (Warm-up)
#> Chain 4:                1.343 seconds (Sampling)
#> Chain 4:                2.598 seconds (Total)
#> Chain 4: 

# Calculate the diagnostics for all parameters.
mcmc_diagnostics(fit)
#>                     Rhat ess_bulk
#> pi[1]          1.0018273 6055.999
#> pi[2]          1.0001419 6580.682
#> pi[3]          1.0001501 7151.012
#> pi[4]          1.0003663 6008.685
#> theta[1, 1, 1] 1.0014529 8161.159
#> theta[1, 1, 2] 1.0012636 7965.062
#> theta[1, 1, 3] 1.0019893 5234.546
#> theta[1, 1, 4] 1.0017338 5986.097
#> theta[1, 2, 1] 1.0018204 5409.573
#> theta[1, 2, 2] 1.0006776 6695.709
#> theta[1, 2, 3] 1.0009396 6323.355
#> theta[1, 2, 4] 1.0000723 5031.910
#> theta[1, 3, 1] 0.9995299 4836.205
#> theta[1, 3, 2] 1.0006257 4029.515
#> theta[1, 3, 3] 1.0001494 4672.475
#> theta[1, 3, 4] 1.0001164 4220.497
#> theta[1, 4, 1] 1.0023103 4997.412
#> theta[1, 4, 2] 1.0003346 4390.737
#> theta[1, 4, 3] 1.0004038 3701.129
#> theta[1, 4, 4] 1.0006139 5637.457
#> theta[2, 1, 1] 1.0031657 7193.152
#> theta[2, 1, 2] 1.0016071 6803.099
#> theta[2, 1, 3] 1.0001820 5738.755
#> theta[2, 1, 4] 0.9994624 6104.235
#> theta[2, 2, 1] 1.0013124 7351.279
#> theta[2, 2, 2] 1.0014571 7103.073
#> theta[2, 2, 3] 0.9994460 7361.043
#> theta[2, 2, 4] 1.0007077 5605.896
#> theta[2, 3, 1] 0.9994511 4830.737
#> theta[2, 3, 2] 0.9998629 5747.660
#> theta[2, 3, 3] 1.0007484 6784.919
#> theta[2, 3, 4] 0.9997595 5549.956
#> theta[2, 4, 1] 1.0006032 5110.703
#> theta[2, 4, 2] 0.9998371 5671.314
#> theta[2, 4, 3] 1.0020247 5192.602
#> theta[2, 4, 4] 1.0019755 6237.913
#> theta[3, 1, 1] 1.0011201 6336.828
#> theta[3, 1, 2] 1.0004837 5267.385
#> theta[3, 1, 3] 1.0004642 5047.024
#> theta[3, 1, 4] 1.0012416 5287.046
#> theta[3, 2, 1] 1.0006048 6470.084
#> theta[3, 2, 2] 1.0031838 7473.881
#> theta[3, 2, 3] 1.0010497 7384.199
#> theta[3, 2, 4] 1.0011604 5930.923
#> theta[3, 3, 1] 1.0003183 5433.234
#> theta[3, 3, 2] 1.0002249 6203.814
#> theta[3, 3, 3] 1.0003849 7290.607
#> theta[3, 3, 4] 1.0008237 7306.952
#> theta[3, 4, 1] 0.9997439 5338.567
#> theta[3, 4, 2] 1.0014513 6134.783
#> theta[3, 4, 3] 1.0005160 4407.851
#> theta[3, 4, 4] 0.9992845 5604.757
#> theta[4, 1, 1] 1.0010008 6924.151
#> theta[4, 1, 2] 0.9995517 5869.042
#> theta[4, 1, 3] 1.0000108 6029.904
#> theta[4, 1, 4] 1.0003029 5626.040
#> theta[4, 2, 1] 1.0006443 5878.394
#> theta[4, 2, 2] 0.9999701 7113.984
#> theta[4, 2, 3] 0.9997918 7384.971
#> theta[4, 2, 4] 1.0006153 5655.828
#> theta[4, 3, 1] 0.9998746 5130.667
#> theta[4, 3, 2] 1.0029073 4584.428
#> theta[4, 3, 3] 1.0014609 5408.682
#> theta[4, 3, 4] 1.0004236 4525.865
#> theta[4, 4, 1] 1.0021068 5213.131
#> theta[4, 4, 2] 1.0005998 4625.539
#> theta[4, 4, 3] 1.0006687 5338.809
#> theta[4, 4, 4] 1.0006896 5654.885
#> theta[5, 1, 1] 1.0003175 7764.500
#> theta[5, 1, 2] 1.0001262 5226.319
#> theta[5, 1, 3] 1.0008976 5051.683
#> theta[5, 1, 4] 0.9999921 7185.263
#> theta[5, 2, 1] 1.0010104 7680.802
#> theta[5, 2, 2] 1.0021106 7199.743
#> theta[5, 2, 3] 0.9999315 5522.709
#> theta[5, 2, 4] 1.0015147 4696.391
#> theta[5, 3, 1] 1.0024536 5456.319
#> theta[5, 3, 2] 1.0003604 6098.296
#> theta[5, 3, 3] 1.0007127 6177.672
#> theta[5, 3, 4] 1.0002020 6135.085
#> theta[5, 4, 1] 1.0000917 5851.338
#> theta[5, 4, 2] 1.0001935 5811.550
#> theta[5, 4, 3] 1.0017356 4840.976
#> theta[5, 4, 4] 1.0016193 6117.394

# Calculate the diagnostics just for the pi parameter.
mcmc_diagnostics(fit, pars = "pi")
#>           Rhat ess_bulk
#> pi[1] 1.001827 6055.999
#> pi[2] 1.000142 6580.682
#> pi[3] 1.000150 7151.012
#> pi[4] 1.000366 6008.685

# }