Here's the implementation of the function true_negative(sens, spec, prior)
:
main.m205 chars9 lines
This function takes three input arguments: sens
, spec
, and prior
. sens
is the sensitivity of the test, spec
is the specificity of the test, and prior
is the prior probability of the event being tested (e.g. the prevalence of a disease in the population).
The function then calculates the probability of a true negative test result, given the input sensitivity, specificity, and prior probability.
The calculation involves using Bayes' theorem, where the probability of a negative test result being true negative is the specificity of the test multiplied by the prior probability of a negative test result, divided by the total probability of a negative test result (which is the sum of the probability of a true negative and a false positive).
The output of the function is the probability of a negative test to be correct (tn
).
gistlibby LogSnag