BayesTheorem {LaplacesDemon}R Documentation

Bayes' Theorem

Description

Bayes' theorem shows the relation between two conditional probabilities that are the reverse of each other. This theorem is named after Reverend Thomas Bayes (1702-1761), and is also referred to as Bayes' law or Bayes' rule (Bayes and Price, 1763). Bayes' theorem expresses the conditional probability, or ‘posterior probability’, of an event AA after BB is observed in terms of the 'prior probability' of AA, prior probability of BB, and the conditional probability of BB given AA. Bayes' theorem is valid in all common interpretations of probability. This function provides one of several forms of calculations that are possible with Bayes' theorem.

Usage

BayesTheorem(PrA, PrBA)

Arguments

PrA

This required argument is the prior probability of AA, or Pr(A)\Pr(A).

PrBA

This required argument is the conditional probability of BB given AA or Pr(BA)\Pr(B | A), and is known as the data, evidence, or likelihood.

Details

Bayes' theorem provides an expression for the conditional probability of AA given BB, which is equal to

Pr(AB)=Pr(BA)Pr(A)Pr(B)\Pr(A | B) = \frac{\Pr(B | A)\Pr(A)}{\Pr(B)}

For example, suppose one asks the question: what is the probability of going to Hell, conditional on consorting (or given that a person consorts) with Laplace's Demon. By replacing AA with HellHell and BB with ConsortConsort, the question becomes

Pr(HellConsort)=Pr(ConsortHell)Pr(Hell)Pr(Consort)\Pr(\mathrm{Hell} | \mathrm{Consort}) = \frac{\Pr(\mathrm{Consort} | \mathrm{Hell})\Pr(\mathrm{Hell})}{\Pr(\mathrm{Consort})}

Note that a common fallacy is to assume that Pr(AB)=Pr(BA)\Pr(A | B) = \Pr(B | A), which is called the conditional probability fallacy.

Another way to state Bayes' theorem (and this is the form in the provided function) is

Pr(AiB)=Pr(BAi)Pr(Ai)Pr(BAi)Pr(Ai)++Pr(BAn)Pr(An)\Pr(A_i | B) = \frac{\Pr(B | A_i)\Pr(A_i)}{\Pr(B | A_i)\Pr(A_i) +\dots+ \Pr(B | A_n)\Pr(A_n)}

Let's examine our burning question, by replacing AiA_i with Hell or Heaven, and replacing BB with Consort

Laplace's Demon was conjured and asked for some data. He was glad to oblige.

Now, Bayes' theorem is applied to the data. Four pieces are worked out as follows

Finally, the desired conditional probability Pr(HellConsort)\Pr(\mathrm{Hell} | \mathrm{Consort}) is calculated using Bayes' theorem

The probability of someone consorting with Laplace's Demon and going to Hell is 73.7%, which is less than the prevalence of 75% in the population. According to these findings, consorting with Laplace's Demon does not increase the probability of going to Hell.

For an introduction to model-based Bayesian inference, see the accompanying vignette entitled “Bayesian Inference” or https://web.archive.org/web/20150206004608/http://www.bayesian-inference.com/bayesian.

Value

The BayesTheorem function returns the conditional probability of AA given BB, known in Bayesian inference as the posterior. The returned object is of class bayestheorem.

Author(s)

Statisticat, LLC.

References

Bayes, T. and Price, R. (1763). "An Essay Towards Solving a Problem in the Doctrine of Chances". By the late Rev. Mr. Bayes, communicated by Mr. Price, in a letter to John Canton, M.A. and F.R.S. Philosophical Transactions of the Royal Statistical Society of London, 53, p. 370–418.

See Also

IterativeQuadrature, LaplaceApproximation, LaplacesDemon, PMC, and VariationalBayes.

Examples

# Pr(Hell|Consort) =
PrA <- c(0.75,0.25)
PrBA <- c(6/9, 5/7)
BayesTheorem(PrA, PrBA)

[Package LaplacesDemon version 16.1.6 Index]