STAPLE on binary matrix
staple_bin_mat(
x,
sens_init = 0.99999,
spec_init = 0.99999,
max_iter = 10000,
tol = .Machine$double.eps,
prior = "mean",
verbose = TRUE,
trace = 10,
drop_all_same = FALSE
)
x | a nxr matrix where there are n raters and r elements rated |
---|---|
sens_init | Initialize parameter for sensitivity (p) |
spec_init | Initialize parameter for specificity (q) |
max_iter | Maximum number of iterations to run |
tol | Tolerance for convergence |
prior | Either "mean" or a vector of prior probabilities, |
verbose | print diagnostic messages |
trace | Number for modulus to print out verbose iterations |
drop_all_same | drop all records where they are all the same. DO NOT use in practice, only for validation of past results |
List of output sensitivities, specificities, and vector of probabilities
n = 5
r = 1000
sens = c(0.8, 0.9, 0.8, 0.5, 0.8)
spec = c(0.9, 0.75, 0.99, 0.98, 0.92)
suppressWarnings(RNGversion("3.5.0"))
set.seed(20171120)
n_1 = 200
n_0 = r - n_1
truth = c(rep(0, n_0), rep(1, n_1))
pred_1 = rbinom(n = n, size = n_1, prob = sens)
pred_0 = rbinom(n = n, size = n_0, prob = spec)
pred_0 = sapply(pred_0, function(n) {
sample(c(rep(0, n), rep(1, n_0 -n)))
})
pred_1 = sapply(pred_1, function(n) {
sample(c(rep(1, n), rep(0, n_1 -n)))
})
pred = rbind(pred_0, pred_1)
true_sens = colMeans(pred[ truth == 1, ])
true_spec = colMeans(1-pred[ truth == 0, ])
x = t(pred)
staple_out = staple_bin_mat(x)
#> iter: 1, diff: 0.465230987394219
#> iter: 10, diff: 0.000389251248063993
#> iter: 20, diff: 6.3176305742374e-07
#> iter: 30, diff: 1.02407371471713e-09
#> iter: 40, diff: 1.65989444411707e-12
#> iter: 50, diff: 2.66453525910038e-15
#> Convergence!
testthat::expect_equal(staple_out$sensitivity,
c(0.781593858553476, 0.895868301462594,
0.760514086161722, 0.464483444340873,
0.765239314719065))
staple_out_prior = staple_bin_mat(x, prior = rep(0.5, r))
#> iter: 1, diff: 0.465231160212495
#> iter: 10, diff: 0.00518796579186032
#> iter: 20, diff: 0.000319714014913819
#> iter: 30, diff: 1.85314590984698e-05
#> iter: 40, diff: 1.0525804566841e-06
#> iter: 50, diff: 5.96097783356342e-08
#> iter: 60, diff: 3.37452188414744e-09
#> iter: 70, diff: 1.91023197260165e-10
#> iter: 80, diff: 1.08131281706392e-11
#> iter: 90, diff: 6.11954931173386e-13
#> iter: 100, diff: 3.48610029732299e-14
#> iter: 110, diff: 1.88737914186277e-15
#> Convergence!
testthat::expect_equal(staple_out_prior$sensitivity,
c(0.683572080864211, 0.821556768891859,
0.619166852992802, 0.389409921992467, 0.67042085955546))