Today I did an illustration of discrete Bayes for a proportion.  I’m interested in the proportion p of graduate students who answer “McDonalds” when asked the question “McDonalds, Wendys, or Burger King?”

I believe p can be one of the five values 0.1, 0.2, 0.3, 0.4, 0.5 and I assign the respective prior weights 1, 2, 5, 10, 5.  I define this prior in R:

> p=c(.1,.2,.3,.4,.5)
> prior=c(1,2,5,10,5)
> prior=prior/sum(prior)
> names(prior)=p

> p=c(.1,.2,.3,.4,.5)
> prior=c(1,2,5,10,5)
> prior=prior/sum(prior)
> names(prior)=p

I collected data from my class.  Of the 25 students, 11 responded with “McDonalds”.
I update my probabilities using the function discrete.bayes.  You can read in the function and associated plot and print methods by typing in
The updating is done by discrete.bayes.  The arguments are the sampling density dbinom, the prior probabilities defined in prior, the number of yes’s (11) and the sample size (25).
> s=discrete.bayes(dbinom,prior,11,size=25)
I compare the prior and posterior probabilities using two bar graphs.
> par(mfrow=c(2,1))
> barplot(prior,ylim=c(0,.6),xlab=”p”,main=”PRIOR”)
> plot(s,xlab=”p”,main=”POSTERIOR”)
Note that the posterior probs are more precise than the prior probabilities.  I am more confident that the proportion of McDonalds fans is equal to 0.4.