Tip:
Highlight text to annotate it
X
Here's my answer.
My code does exactly what I've shown you before.
It first considers the possibility of cancer,
multiplies it with the test sensitivity p1
and then it observes the opposite possibility
and of the course the specitivity over here refers to a negative test result
so we take 1 minus this to get the positive one.
Adding these two products up gives us the desired result.
So let's try this. It gives me a function f with the parameters we just assumed
and if I hit run, I get 0.27.
Obviously I can change these parameters,
so, suppose I make it much less likely to have cancer in the prior from 0.1 to 0.01
then my 0.27 changes to 0.207.
Now I realise it's not the posterior in Bayes' Rule.
It's just the probability of getting a positive test result.
You can see this if you change the prior probability of cancer to 0
which means we don't have cancer, no matter what the test result says.
But there still is 0.2 chance of getting a positive test result
and the reason is our test has a specitivity of 0.8
that is, even in the absence of cancer,
there is a 0.2 chance of getting a positive test result.