Bayesian updating

## Set prior probabilities to 1/3
prior = c(red1white2 = 1, red2white1 = 1,red3white0 = 1)
barplot(prop.table(prior), ylim = c(0,1), main = "prior")

plot of chunk unnamed-chunk-2


## Give likelihood of getting red ball given each jar
likelihood.of.red = c(red1white2 = 1/3, red2white1 = 2/3,red3white0 = 3/3)
likelihood.of.red
red1white2 red2white1 red3white0 
    0.3333     0.6667     1.0000 

## Get posterior probabilities after 1 red ball
posterior.after.1red = prior * likelihood.of.red
barplot(prop.table(posterior.after.1red), ylim = c(0,1), main = "after 1 red ball")

plot of chunk unnamed-chunk-2


## Get posterior probabilities after 1 red ball
posterior.after.2red = posterior.after.1red * likelihood.of.red
barplot(prop.table(posterior.after.2red), ylim = c(0,1), main = "after 2 red balls")

plot of chunk unnamed-chunk-2