Review Stanford OLI course section on probability trees: Probability: Conditional Probability and Independence > Multiplication Rule > Probability Trees Defined
Write an R function getProbDisease that calculates the probability of someone having a condition following a positive test result for the condition.
The function should accept the following 3 named arguments (with no defaults) and return P(disease | positive test result).
- prevalence - fraction of people with a condition; probability that a person selected at random from the population has the condition
- sensitivity - sensitivity of the test; probability of a person testing positive for the condition when they have it
- specificity - specificity of the test; probability of a person testing negative for the condition when they do not have it
Write the function in a single .R file and upload the file here. We will download your file and test it with sample input. So be sure to test your code with lots of test input to make sure it works correctly and conforms to the specification.
Let's say you have named your file myFunction.R. I should then be able to download your file, import it into my R session using the source command, and run your function like this:
Note that because your function is written using named arguments, I can list the arguments in any order, so long as I refer to them by name. For example, I can run it like this, also: