Sunday, July 26, 2009

Bayes 10: discrete prior

Finally, we need to deal with the case of a discrete prior in the problem about estimation of the mean. Remember Chuck's thinking was:

Chuck decides his prior belief is not normal. His prior has a trapezoidal shape. His prior gives zero weight at 18 cm. It gives weight one at 24 cm, and is level up to 40 cm, and then goes down to zero at 46 cm.

I will use the Bolstad package in R. The hardest part is just constructing the prior distribution.

mu = seq(18.2,46,by=0.2)
length(mu) # 140 values

s = seq(0.2,6,by=0.2)
L = length(mu) - 2*length(s)
v = c(s,rep(6,L),rev(s))
mu.prior = v/sum(v)

x = rep(32,12)


We can also save the result and then do the plot manually. That would allow us to compare the results from different priors on the same plot.

p1 = normdp(x,sigma.x=sigma.x,mu=mu,
p2 = normnp(x,30,4,sigma.x=2,ret=T)


Here the red is the posterior from use of the normal prior, and the blue is from use of the discrete prior. The discrepancy in peak heights is due to the different number of elements in each mu vector.

No comments: