This m-file deals with the Bayes' theorem, as well as with the option of the frequency visualization of a given sample.

Rev. Thomas Bayes (1702-1761), developed a very interesting theorem alter known as Bayes' theorem. The work entitled 'An essay towards solving a Problem in the doctrine of Chances' was published in Philosophical Transactions of the Royal Society of London in 1764 (53: 370-418). It was not by Bayes, but it was communicated posthumously by his friend Richard Price in a letter to John Canton in december 23, 1763.

The complete paper in the original notation can be downloading from:

http://canoe.ens.fr/~ebrian/s1h-dhsrb/1764-bayes.pdf

Also an excellent transcription of it from:

http://www.stat.ucla.edu/history/essay.pdf

Bayes' theorem is a solution to a problem of 'inverse probability'. It gives you the actual probability of an event given the measured test probabilities. For example, you can:

-Correct for measurement errors. If you know the real probabilities and the chance of a false positive and false negative, you can correct for measurement errors.

-Relate the actual probability to the measured test probability. Bayes’ theorem lets you relate p(X|Y), the chance that an event X happened given the indicator Y, and p(Y|X), the chance the indicator Y happened given that event X occurred.

The Bayes' equation is:

p(Y|X)p(X)

p(X|Y) = -----------------------------------

p(Y|X)p(X) + p(Y|~X)p(~X)

Here, the sign ~ means complement.

Note.- According to Eliezer S. Yudkowsky's web page [http://yudkowsky.net/rational/bayes], one thing that's confusing is about the '|' notation. Reading from left to right, '|' means 'given'; reading from right to left, '|' means 'implies' or 'leads to'. Thus, moving your eyes from left to right, X|Y reads 'X given Y' or 'the probability that an element is X, given that the element is Y'. Moving your eyes from right to left, X|Y reads 'Y implies X or 'the probability that an element containing Y is X'.

Syntax: function x = Bayes(a,b,c,d)

Inputs:

a - a priori probability (prior, marginal or actual)

b - First conditional probability, p(Y|X) [option=1]; first interaction probability, p(XY) (true positive) [opion=2] or conditional probability, p(Y|X) [option=3]

c - Second conditional probability, p(Y|~X) [option=1]; second interaction probability, p(X~Y) (false positive) [opion=2] or interecation probability, p(~XY) [option=3]

d - Option = 1(default),2,or 3

- It shows a dialog whether or not you are interested with the frequency visualization of a given sample

Output:

x - chance positive test or positive result (posterior probability)

- frequency visualization of a given sample (optional)

### Cite As

Antonio Trujillo-Ortiz (2024). Bayes (https://www.mathworks.com/matlabcentral/fileexchange/25203-bayes), MATLAB Central File Exchange. Retrieved .

##### MATLAB Release Compatibility

##### Platform Compatibility

Windows macOS Linux##### Categories

##### Tags

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!### Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.