In this chapter, weβll start with conditional probability, derive Bayesβs Theorem, and demonstrate it using a real dataset. In the next chapter, weβll use Bayesβs Theorem to solve problems related to conditional probability. In the chapters that follow, weβll make the transition from Bayesβs Theorem to Bayesian statistics, and Iβll explain the difference.
Linda is 31 years old, single, outspoken, and very bright. She majored in philosophy. As a student, she was deeply concerned with issues of discrimination and social justice, and also participated in anti-nuclear demonstrations. Which is more probable?
Many people choose the second answer, presumably because it seems more consistent with the description. It seems uncharacteristic if Linda is just a bank teller; it seems more consistent if she is also a feminist.
But the second answer cannot be "more probable", as the question asks. Suppose we find 1000 people who fit Lindaβs description and 10 of them work as bank tellers. How many of them are also feminists? At most, all 10 of them are; in that case, the two options are equally probable. If fewer than 10 are, the second option is less probable. But there is no way the second option can be more probable.
I am particularly fond of this example because I know that the [second] statement is least probable, yet a little homunculus in my head continues to jump up and down, shouting at me, "but she canβt just be a bank teller; read the description."
At this point I should provide a definition of "probability", but that turns out to be surprisingly difficult. To avoid getting stuck before we start, we will use a simple definition for now and refine it later: A probability is a fraction of a finite set.
For example, if we survey 1000 people, and 20 of them are bank tellers, the fraction that work as bank tellers is 0.02 or 2%. If we choose a person from this population at random, the probability that they are a bank teller is 2%.
With this definition and an appropriate dataset, we can compute probabilities by counting. To demonstrate, Iβll use data from the General Social Survey (GSS).
The fraction of women in this dataset is higher than in the adult U.S. population because the GSS does not include people living in institutions like prisons and military housing, and those populations are more likely to be male.
The other variables weβll consider are polviews, which describes the political views of the respondents, and partyid, which describes their affiliation with a political party.
0 Strong democrat
1 Not strong democrat
2 Independent, near democrat
3 Independent
4 Independent, near republican
5 Not strong republican
6 Strong republican
7 Other party
Iβll define democrat to include respondents who chose "Strong democrat" or "Not strong democrat":
"Conjunction" is another name for the logical and operation. If you have two propositions, A and B, the conjunction A and B is True if both A and B are True, and False otherwise.
If we have two Boolean series, we can use the & operator to compute their conjunction. For example, we have already computed the probability that a respondent is a banker.
2. The dataset includes respondents as far back as 1974; in the early part of this interval, there was less alignment between political views and party affiliation, compared to the present.
Letβs try the second example, "What is the probability that a respondent is female, given that they are a banker?" We can interpret that to mean, "Of all respondents who are bankers, what fraction are female?"
Letβs wrap this computation in a function. Iβll define conditional to take two Boolean series, proposition and given, and compute the conditional probability of proposition conditioned on given:
The result shows that the majority of bankers are female. That is not the same as the probability that a respondent is a banker, given that they are female:
I hope this example makes it clear that conditional probability is not commutative, and maybe it was already clear to you. Nevertheless, it is a common error to confuse conditional(A, B) and conditional(B, A). Weβll see some examples later.
We can combine conditional probability and conjunction. For example, hereβs the probability a respondent is female, given that they are a liberal Democrat.
The result is the same. This example demonstrates a general rule that relates conditional probability and conjunction. Hereβs what it looks like in math notation:
In addition to these three theorems, thereβs one more thing weβll need to do Bayesian statistics: the law of total probability. Hereβs one form of the law, expressed in mathematical notation:
In words, the total probability of \(A\) is the sum of two possibilities: either \(B_1\) and \(A\) are true or \(B_2\) and \(A\) are true. But this law applies only if \(B_1\) and \(B_2\) are:
Because male and female are mutually exclusive and collectively exhaustive (MECE), we get the same result we got by computing the probability of banker directly.
Again, this holds as long as the conditions, \(B_i\) are mutually exclusive and collectively exhaustive. As an example, letβs consider polviews, which has seven different values.
In this example, using the law of total probability is a lot more work than computing the probability directly, but it will turn out to be useful, I promise.
At this point you might ask, "So what?" If we have all of the data, we can compute any probability we want, any conjunction, or any conditional probability, just by counting. We donβt have to use these formulas.
And you are right, if we have all of the data. But often we donβt, and in that case, these formulas can be pretty useful -- especially Bayesβs Theorem. In the next chapter, weβll see how.
Linda is 31 years old, single, outspoken, and very bright. She majored in philosophy. As a student, she was deeply concerned with issues of discrimination and social justice, and also participated in anti-nuclear demonstrations. Which is more probable?
Whether you agree with this proposition or not, it suggests some probabilities we can compute as an exercise. Rather than use the specific ages 25 and 35, letβs define young and old as under 30 or over 65:
For these thresholds, I chose round numbers near the 20th and 80th percentiles. Depending on your age, you may or may not agree with these definitions of "young" and "old".
For the conditional probabilities, be careful about the order of the arguments. If your answer to the last question is greater than 30%, you have it backwards!