Skip to contents

Sensitivity and Specificity calculation

Usage

prob_input(sensitivity, specificity, prevalence)

confusion_input(TP, TN, FP, FN)

Arguments

sensitivity

Numeric. P(+|P), the probability of a positive test result given that the result is truly positive.

specificity

Numeric. P(-|N), the probability of a negative test result given that the result is truly negative.

prevalence

Numeric. P(P), the probability of truly positive results in the population.

TP

Integer. True positive count.

TN

Integer. True negative count.

FP

Integer. False positive count.

FN

Integer. False negative count.

Examples

post = prob_input(sensitivity=.9, specificity=.97, prevalence=.008)
post
#>       P(P|+)       P(N|+)       P(N|-)       P(P|-) 
#> 0.1948051948 0.8051948052 0.9991692972 0.0008307028 

# Assume there are 2957 positive cases and 77043 negative cases.
# The code below computes TP, FP, TN, FN
counts = post * c(2957, 2957, 77043, 77043)
counts
#>      P(P|+)      P(N|+)      P(N|-)      P(P|-) 
#>   576.03896  2380.96104 76979.00017    63.99983 

confusion_input(TP=576, FP=2381, TN=76979, FN=64)
#>            N   prevalence  sensitivity  specificity 
#> 8.000000e+04 8.000000e-03 9.000000e-01 9.699975e-01