'Question about the Division operator in R not returning the correct value
I am trying to caculate the Bayes Theorem for Cancer and tried to plug in the correct values in my formula as such:
cancer <- (1 * (1/100000)) / (1*(1/100000)) + ((10/99999) * (99999/100000))
In this case, cancer = 1.0001
However, the correct answer should be: 0.09090909, as proven by running the code separately, like this:
num = (1 * (1/100000))
den = (1*(1/100000)) + ((10/99999) * (99999/100000))
num / den
> 0.09090909
Can you please let me know why this is the case and how I should run the combined equation in the future to get the proper result?
Solution 1:[1]
Parentheses are needed:
cancer <- (1 * (1/100000)) / ((1*(1/100000)) + ((10/99999) * (99999/100000)))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Johnny |