Aim

  1. To calculate Bayes posterior probability using Bayes theorem

Packages used and syntax of R methods

Bayes posterior probability can be directly calculated using mathematical method or using the package LaplacesDemon.

Algorithm

Case: Classical Problem from Hoel, Port, and Stone (1971). Suppose there are three tables with two drawers each. The first table has a gold coin in each of the drawers, the second table has a gold coin in one drawer and a silver coin in the other drawer, while the third table has silver coins in both of the drawers. A table is selected at random and a drawer is opened which shows a gold coin.

Observation:The problem is to compute the probability of the other drawer also showing a gold coin. The Bayes formula can be easily implemented in an R program.

R code

#loading data
prob_GC <- c(1,1/2,0)
priorprob_GC <- c(1/3,1/3,1/3)
#calculating postrior probability
post_GC <- prob_GC*priorprob_GC
post_GC/sum(post_GC)
## [1] 0.6666667 0.3333333 0.0000000
# do the same using LaplacesDemon` package
library(LaplacesDemon)
BayesTheorem(prob_GC, priorprob_GC)
## [1] 0.6666667 0.3333333 0.0000000
## attr(,"class")
## [1] "bayestheorem"

Results & discussions

The Bayes theorem is used to calculate posterior probability of the Mathematical model of the given case. Also the result is verified using the LaplacesDemon package.