set.seed(123) #allow reproducible results
sim<-10e6 #Monte Carlo simulations
sens<-c(0.6, 0.8) #two diagnostic test sensitivities
no.of.diag.test<-length(sens)
x = matrix(NA, nrow=sim, ncol=(no.of.diag.test)) #empty matrix to collect results
#Independent Bernoulli random generation. The probability is the sensitivity, so if a 1 is generated this is considered a success. Do this for the battery of tests. Repeat a large number of times.
for(i in 1: no.of.diag.test ){ #perform simulations
x[,i] = rbinom(sim, size = 1 , prob = sens[i])
}
head(x) #examine first rows of simulations
[,1] [,2]
[1,] 1 1
[2,] 0 1
[3,] 1 1
[4,] 0 1
[5,] 0 1
[6,] 1 1
y<-rowSums(x) #how many of the parallel tests were positive/negative
1-length(y[y==0])/sim #1 - number of times all tests are negative, sensitivity
[1] 0.9200041
1- prod(1-sens)
[1] 0.92
spec<-c(0.99,0.94,0.9,0.87,0.68) #mixture of specificities
no.of.diag.test<-length(spec)
x = matrix(NA, nrow=sim, ncol=(no.of.diag.test)) #empty matrix to collect results
#The probability is 1-specificity, so if a 1 is generated this is considered a failure. Do this for the battery of tests. Repeat a large number of times.
for(i in 1: no.of.diag.test ){ #perform simulations
x[,i] = rbinom(sim, size = 1 , prob = 1-spec[i])
}
head(x) #examine first rows of simulations
[,1] [,2] [,3] [,4] [,5]
[1,] 0 0 0 0 1
[2,] 0 0 0 0 0
[3,] 0 0 0 0 1
[4,] 0 0 1 0 1
[5,] 0 0 0 0 0
[6,] 0 0 0 0 1
y<-rowSums(x) #how many of the parallel tests were positive/negative
length(y[y==0])/sim #proportion negative
[1] 0.4954899
prod(spec)
[1] 0.4954887
https://books.google.co.uk/books?id=NJ0uu9xTiIIC&pg=PA54&lpg=PA54&dq=sensitivity+of+3+parallel+tests&source=bl&ots=kSMLwgAsxW&sig=C-PXbjRGiPRCT8_8qMHXxYhZauM&hl=en&sa=X&ved=0CE4Q6AEwB2oVChMIl_DB5ZD_xwIVhEIUCh1bowBU#v=onepage&q=sensitivity%20of%203%20parallel%20tests&f=false Clinical Epidemiology: The Essentials By Robert H. Fletcher, Suzanne W. Fletcher
http://ocw.jhsph.edu/courses/FundEpi/PDFs/Lecture11.pdf
http://www.ajronline.org/doi/abs/10.2214/ajr.184.1.01840014
http://radiopaedia.org/articles/sensitivity-and-specificity-of-multiple-tests
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] MKmisc_0.99 knitr_1.11
loaded via a namespace (and not attached):
[1] DEoptimR_1.0-3 magrittr_1.5 formatR_1.2.1 tools_3.2.2 htmltools_0.2.6 RColorBrewer_1.1-2
[7] yaml_2.1.13 stringi_0.5-5 rmarkdown_0.8 robustbase_0.92-5 stringr_1.0.0 digest_0.6.8
[13] evaluate_0.8
[1] "~/X/DEVELOPMENT\\AGREEMENT SENS SPEC SAMPLE SIZE"
This took 9.12 seconds to execute.