Example: Using a nonconjugate prior distribution in estimating a binomial probability (see page 41 of Gelman et al) prior is triangular form p(t) = .5, t < .4 or t > .6 = .5+55(t-.4), .4 < t < .5 = .5+55(.6-t), .5 < t < .6 observe 437 successes and 543 failures want to find posterior median and central 95% credible interval first we name the Minitab columns MTB > name c1 't' c2 'prior' c3 'loglike' c4 'logpost' c5 'post' c6 'post_s' put a grid of values .001,.002, ..., .999 into 't' MTB > set 't' DATA> .001:.999/.001 DATA> end compute the prior on this grid MTB > let 'prior'=.5+55*('t'-.4)*('t'>.4)*('t'<.5)+55*(.6-'t')*('t'>.5)*('t'<.6) compute the logarithm of the likelihood function MTB > let 'loglike'=437*log('t')+543*log(1-'t') compute the posterior -- important to scale the log values before you exp! then you normalize the values so that they sum to 1 MTB > let 'logpost'=log('prior')+'loglike' MTB > let 'post'=exp('logpost'-max('logpost')) MTB > let 'post'='post'/sum('post') simulate 1000 values from this discrete posterior distribution MTB > Random 1000 'post_s'; SUBC> Discrete 't' 'post'. MTB > dotplot 'post_s' Each dot represents 4 points . . .: : : .:::: : .:.:::.:::::::..:: . ::::::::::::::::::::. ..::::::::::::::::::::: . .::::::::::::::::::::::::: .. . ..::.::::::::::::::::::::::::::::::::.... .. . -+---------+---------+---------+---------+---------+-----post_s 0.400 0.420 0.440 0.460 0.480 0.500 the posterior median is approximately the median of this simulated value MTB > median 'post_s' Column Median Median of post_s = 0.45000 the 95% interval is the 25th and 975th order statistics of this simulated sample MTB > sort 'post_s' 'post_s' MTB > let k1='post_s'(25) MTB > let k2='post_s'(975) MTB > prin k1 k2 K1 0.420000 K2 0.480000