| tabdiagi | R Documentation |
tabdiagi() calculates diagnostic test accuracy directly from the four
cell counts of a 2 x 2 table. It is intended especially for teaching,
checking hand calculations, and analyses where only aggregated counts are
available.
tabdiagi(
tp = NULL,
fp = NULL,
fn = NULL,
tn = NULL,
a = NULL,
b = NULL,
c = NULL,
d = NULL,
prevalence = NULL,
ci = FALSE,
ci_level = 0.95,
ci_method = c("auto", "wilson", "exact"),
zero_correction = 0.5,
digit = 2,
show = TRUE,
console = FALSE
)
tp |
True positives. With positional input this is the first number. |
fp |
False positives. With positional input this is the second number. |
fn |
False negatives. With positional input this is the third number. |
tn |
True negatives. With positional input this is the fourth number. |
a, b, c, d |
Optional aliases for |
prevalence |
Optional population disease prevalence, strictly between 0 and 1. When supplied, PPV and NPV are recalculated from sensitivity, specificity, and this prevalence. The observed predictive values remain available in the returned object. |
ci |
|
ci_level |
Confidence level, default 0.95. |
ci_method |
Method for binomial proportion confidence intervals:
|
zero_correction |
Continuity correction used only when a zero cell prevents a finite log-scale DOR confidence interval. Default 0.5. |
digit |
Number of digits displayed for estimates. |
show |
Logical; open the formatted result in the Viewer. Default |
console |
Logical; also print the teaching-oriented result in the Console. Default |
The cell layout is:
Reference standard
Positive Negative
Test positive TP FP
Test negative FN TN
The function calculates the full set of commonly used 2 x 2 diagnostic measures: sensitivity, specificity, PPV, NPV, accuracy, balanced accuracy, LR+, LR-, diagnostic odds ratio (DOR), Youden index, F1 score, Matthews correlation coefficient (MCC), Cohen's kappa, false-positive rate (FPR), false-negative rate (FNR), false-discovery rate (FDR), false-omission rate (FOR), disease prevalence, detection rate, and detection prevalence.
Confidence intervals are optional because they can make console output much
wider. ci = TRUE requests all currently supported intervals.
Sensitivity, specificity, PPV, NPV, and accuracy use binomial intervals.
LR+ and LR- use conventional log-scale intervals. DOR uses a log-scale
interval; if any cell is zero, the requested zero_correction is applied
for the DOR interval calculation and this is recorded in the returned
object.
When prevalence is supplied, PPV and NPV in the main results are
prevalence-adjusted. Because simple binomial confidence intervals no longer
apply to these adjusted predictive values, their CI entries are returned as
missing. The observed PPV and NPV remain in result$estimates as
ppv_observed and npv_observed.
Invisibly returns an object of class r4vn_diagi and r4vn_stat containing
table, estimates, ci, settings, and notes.
Use four counts directly:
tabdiagi(80, 20, 10, 90)
or use explicit names:
tabdiagi(tp = 80, fp = 20, fn = 10, tn = 90)
Request only sensitivity and specificity confidence intervals:
tabdiagi(80, 20, 10, 90, ci = c("sens", "spec"))
Request all supported confidence intervals:
tabdiagi(80, 20, 10, 90, ci = TRUE)
To show how PPV and NPV change when disease prevalence is 10 percent:
tabdiagi(80, 20, 10, 90, prevalence = 0.10)
tabdiagi(80, 20, 10, 90)
tabdiagi(tp = 80, fp = 20, fn = 10, tn = 90)
tabdiagi(80, 20, 10, 90, ci = c("sens", "spec"))
tabdiagi(80, 20, 10, 90, ci = TRUE, show = FALSE)
tabdiagi(80, 20, 10, 90, prevalence = 0.10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.