SensSpec.demo.RdThis function demonstrates how to get PPV and NPV from Sensitivity, Specificity, and Prevalence by using a virtual population rather than a direct application of Bayes Rule. This approach is more intuitive to mathphobes.
SensSpec.demo(sens, spec, prev, n = 100000, step = 11)The common way to compute Positive Predictive Value (probability of disease given a positive test (PPV)) and Negative Predictive Value (probability of no disease given negative test (NPV)) is to use Bayes' rule with the Sensitivity, Specificity, and Prevalence.
This approach can be overwhelming to non-math types, so this demonstration goes through the steps of assuming a virtual population, then filling in a 2x2 table based on the population and given values of Sensitivity, Specificity, and Prevalence. PPV and NPV are then computed from this table. This approach is more intuitive to many people.
The function can be run multiple times with different values of
step to show the steps in building the table, then rerun with
different values to show how changes in the inputs affect the results.
An invisible matrix with the 2x2 table
roc.demo, fagan.plot,
the various Epi packages, tkexamp
for(i in seq(1,11,2)) {
SensSpec.demo(sens=0.95, spec=0.99, prev=0.01, step=i)
if( interactive() ) {
readline("Press Enter to continue")
}
}
#> Disease
#> Test Yes No Total
#> Positive
#> Negative
#>
#> Total 1e+05
#>
#> PPV =
#> NPV =
#>
#> Disease
#> Test Yes No Total
#> Positive
#> Negative
#>
#> Total 1000 99000 1e+05
#>
#> PPV =
#> NPV =
#>
#> Disease
#> Test Yes No Total
#> Positive 950
#> Negative 50
#>
#> Total 1000 99000 1e+05
#>
#> PPV =
#> NPV =
#>
#> Disease
#> Test Yes No Total
#> Positive 950 990
#> Negative 50 98010
#>
#> Total 1000 99000 1e+05
#>
#> PPV =
#> NPV =
#>
#> Disease
#> Test Yes No Total
#> Positive 950 990 1940
#> Negative 50 98010 98060
#>
#> Total 1000 99000 100000
#>
#> PPV =
#> NPV =
#>
#> Disease
#> Test Yes No Total
#> Positive 950 990 1940
#> Negative 50 98010 98060
#>
#> Total 1000 99000 100000
#>
#> PPV = 950/1940 = 0.4897
#> NPV = 98010/98060 = 0.9995
#>