|>
Your_group filter(test == "P") |>
summarize(mean(sick=="S"))
mean(sick == "S") |
---|
0.0967742 |
We demonstrated using a data simulation how to compute the probability that you are \(\Sick\) given your \(\Ptest\).
In constructing the simulation, we used the relevant information:
- \({\cal L}_\Sick(\Ptest) = 0.90\)
- \({\cal L}_\Healthy(\Ptest) = 0.20\)
- Prevalence in your group is 0.02.
We don’t actually need the simulation. We can carry out the calculation of the probability that a \(\Ptest\) person is \(\Sick\) with arithmetic.
- The proportion of people in your group who are \(\Sick\) is the prevalence: \(p(\Sick) = 0.02\).
- Of these \(\Sick\) people, the proportion who will test positive is \({\cal L}_\Sick(\Ptest)\).
- So, the proportion of the whole group who are both \(\Sick\) and \(\Ptest\) is \({\cal L}_\Sick(\Ptest) p(\Sick) = 0.9 \times 0.02 = 0.018\). This corresponds to the red dots in the upper right quadrant of Figure 28.2(b).
- The proportion of people in your group who are \(\Healthy\) is 1 minus the prevalence: \(p(\Healthy) = 1 - 0.02 = 0.98\)
- Of these \(\Healthy\) people, the proportion who will test positive is \({\cal L}_\Healthy(\Ptest) = 0.9 \times 0.01 = 0.009\).
- So, the proportion of the whole group who are both \(\Healthy\) and \(\Ptest\) is \({\cal L}_\Healthy(\Ptest) p(\Healthy) = 0.20 \times 0.98 = 0.196\).
- Putting these two proportions together, we get \(0.196 + 0.018 = 0.216\) have a \(\Ptest\).
We want the proportion of sick \(\Ptest\) people out of all the \(\Ptest\) people, or:
\[p(\Sick\given\Ptest) = \frac{0.018}{0.198 + 0.018} = 0.084\ .\]
Even though you tested \(\Ptest\), there is less than a 10% chance that you are \(\Sick\)!
Bayesian thinking
We used the specific, concrete situation of medical testing to illustrate Bayesian thinking, the result of which was the probability that you are \(\Sick\) given your \(\Ptest\) result. In this section we will describe Bayesian thinking in more general terms.
Bayesian thinking is analogous to deductive reasoning in geometry. The purpose of both is to generate new statements (e.g. “the two lines are not parallel”) from existing statements (e.g. “the two lines cross at a point”) that are posited to be true. In geometry, statements are about lengths, angles, areas, and so on. In Bayesian thinking, the statements are about a set of hypotheses, observations, and likelihoods.
Bayesian thinking involves two or more hypotheses that you want to choose between based on observations. In the medical testing example, the two hypotheses were \(\Sick\) and \(\Healthy\).
This claim that \(\Sick\) and \(\Healthy\) are hypotheses may surprise you. Aren’t \(\Sick\) and \(\Healthy\) two different objective states of being, one of which is true and the other one isn’t? In the Bayesian system, however, such states are always uncertain. We quantify the uncertainty by relative probabilities.
For instance, a possible Bayesian statement about \(\Sick\) and \(\Healthy\) goes like this, “In the relevant instance, \(\Sick\) and \(\Healthy\) have relative probabilities of 7 and 5 respectively.” (Many people prefer to use “belief” instead of “statement.”)
The book-keeping for Bayesian statements is easiest when there are only two hypotheses in contention. In this section, we will stick to that situation. Since there are only two hypotheses, any statement about them can be translated from relative probabilities into “odds.” For instance, “relative probabilities of 7 and 5 respectively” is equivalent to “the odds of \(\Sick\) are 7 to 5, that is 1.4. (The odds of the other hypothesis, \(\Healthy\) in the example, are just the reciprocal of the odds of the first hypothesis.)
As mentioned previously, Bayesian thinking is a way of generating new statements out of old ones that are posited to be true. The words “new” and “old” suggest that time is in play, and that’s a good way to think about things. Conventionally the words prior and posterior are used to indicate “old” or “new.” From prior statements we will deduce posterior statements.
Observations are the thing that drive the derivation from prior statements to posterior statements. For instance, in the medical testing example, a good prior statement about \(\Sick\) for you relates to the prevalence of \(\Sick\) in your relevant reference group. We stipulated before that this is 0.02. In terms of odds, this amounts to saying that the odds of \(\Sick\) on the day before the test were 2/98 = 0.02041. Or, better, your prior for \(\Sick\) is 0.02041.
Now new information comes along: your test result: \(\Ptest\). We will use this to transform your prior into a posterior informed by the test result. Like this:
\[posterior\ \text{for } \Sick\ \longleftarrow_\Ptest\ prior\ \text{for }\Sick\] Keep in mind that both the prior and posterior are in the form of “odds of \(\Sick\).
How do we accomplish the transformation? This is where the likelihoods come in. There is one \(\Ptest\) likelihood for each of the two hypotheses. We will write them as a fraction:
\[\text{Likelihood ratio}(\Ptest) \equiv\frac{{\cal L}_{\Sick(\Ptest)}}{{\cal L}_\Healthy({\Ptest})}\] Note that the likelihood for the \(\Sick\) hypothesis is on the top and \(\Healthy\) is on the bottom. This is because we are framing our prior and posterior in terms of the odds of \(\Sick\). Also, both likelihoods involve the same observation, in this case the \(\Ptest\) result from your test.
Here is the formula for the transformation:
\[posterior\ \text{for } \Sick = \text{Likelihood ratio(}\Ptest\text{)} \times \ prior\ \text{for }\Sick\]
We assumed your reference group has a prevalence of 2%. Translating this probability into the form of odds gives:
\[prior\ \text{for}\ \Sick = \frac{2}{98} = 0.02041\]
The relevant likelihoods were established, as described in the previous section, by the test developer’s study of \(\Sick\) patients and \(\Healthy\) individuals.
\[\text{Likelihood ratio}(\Ptest) \equiv\frac{{\cal L}_\Sick(\Ptest)}{{\cal L}_\Healthy(\Ptest)} = \frac{0.90}{0.20} = 4.5\] Consequently, the posterior (driven by the observation \(\Ptest\)) is
\[posterior\ \text{for } \Sick = 4.5 \times 0.02041 = 0.09184\ .\]
This posterior is stated as odds. In terms of probability, it corresponds to \(\frac{0.09184}{1 + 0.0984} = 0.084\), exactly what we got when we counted red circles and red triangles in Figure 28.2!
Bayes with multiple hypotheses
The previous section showed the transformation from prior to posterior when there are only two hypotheses. But Bayesian thinking applies to situations with any number of hypotheses.
Suppose we have \(N\) hypotheses, which we will denote \({\cal H}_1, {\cal H}_2, \ldots, {\cal H}_N\).
Since there are multiple hypotheses, it’s not clear how odds will apply. So instead of stating priors and posteriors as odds, we will write them as relative probabilities. We’ll write the prior for each hypothesis as \(prior({\cal H}_i)\) and the posterior as \(posterior({\cal H}_i)\).
Now an observation is made. Let’s call it \(\mathbb{X}\). This observation will drive the transformation of our priors into our posteriors. As before, the transformation involves the likelihood of \(\mathbb{X}\) under the relative hypotheses. That is, \({\cal L}_{\cal H_i}(\mathbb{X})\). The calculation is simply
\[posterior({\cal H_i}) = {\cal L}_{\cal H_i}(\mathbb{X}) \times\ prior({\cal H_i}) \ \text{in relative probability form}\]
If you want to convert the posterior from a relative probability into an ordinary probability (between 0 and 1), you need to collect up the posteriors for all of the hypotheses. The notation \(p(\cal H_i\given \mathbb X)\) is conventional, where the posterior nature of the probability is indicated by the \(\given \mathbb X)\). Here’s the formula:
\[p(\cal H_i\given \mathbb X) = \frac{posterior(\cal H_i)}{posterior(\cal H_1) + posterior(\cal H_2) + \cdots + posterior(\cal H_N)}\] ::: {.callout-note} ## Example: Car safety
Maybe move the example using the exponential distribution from the Likelihood Lesson to here.
:::
Accumulating evidence
THE CYCLE OF ACCUMULATION
Note: There are specialized methods of Bayesian statistics and whole courses on the topic. An excellent online course is Statistical Rethinking.