To understand sensitivity & specificity in diagostic accuracy analysis.
To calculate the probability a pateient has disease given a certain test results. Usually, a 2 by 2 table is used:
library(epiR)
TD_table <- as.table(matrix(c("TP","FP","FN","TN"), nrow = 2, byrow = TRUE))
rownames(TD_table) <- c("Test positive","Test negative")
colnames(TD_table) <- c("Disease present", "Disease absent")
TD_table
## Disease present Disease absent
## Test positive TP FP
## Test negative FN TN
Sensitivity: the proportion of patients with disease who test positive.
Specificity: the proportion of patients without disease who test negative.
Pretest probability (prevalence): * the estimated likelihood of disease before the test is done within a relevant population.*
Posttest probability (Predictive value of a positive test): * the proportion of patients with positive tests who have disease.*
Take mammogram test for women breast test for example: if we have 10,000 women,
8 women with a positive mammogram who have cancer (true positive)
2 woman with a negative mammogram who have cancer (false negative)
9490 women with a negative mammogram who do not have cancer(ture negative)
500 women with a positive mammogram who do not have cancer (false positive)
So the 2 by 2 table should be replaced as:
TD_table <- as.table(matrix(c(8,500,2,9490), nrow = 2, byrow = TRUE))
rownames(TD_table) <- c("Test positive","Test negative")
colnames(TD_table) <- c("Disease present", "Disease absent")
TD_table
## Disease present Disease absent
## Test positive 8 500
## Test negative 2 9490
epi.tests(TD_table, conf.level = 0.95)
## Disease + Disease - Total
## Test + 8 500 508
## Test - 2 9490 9492
## Total 10 9990 10000
##
## Point estimates and 95 % CIs:
## ---------------------------------------------------------
## Apparent prevalence 0.05 (0.05, 0.06)
## True prevalence 0.00 (0.00, 0.00)
## Sensitivity 0.80 (0.44, 0.97)
## Specificity 0.95 (0.95, 0.95)
## Positive predictive value 0.02 (0.01, 0.03)
## Negative predictive value 1.00 (1.00, 1.00)
## Positive likelihood ratio 15.98 (11.59, 22.04)
## Negative likelihood ratio 0.21 (0.06, 0.73)
## ---------------------------------------------------------
Based on the results, we can conclude that:
1) The sensitivity is 80% (a test can detect 8 out of 10 cancers);
2) The specifity is 95% (5% of patients who have positive test do not have cancer). Although 95% seems high, with population of 10,000, that is 500 women with positve test have wrong diagnosation.
Reference:
http://medicine4community.blogspot.com/2011/09/r-sensitivity-specificity-and.html