# Solved – Calculating posterior of difference given posterior of two means

I am using R and `MCMCpack` to do a Bayesian analysis of some data that I have. I have generated posterior distributions (`postDist`) on the means of some parameters (`y1,y2,y3`) using `MCMCregress` (`postDist <- MCMCRegress( x ~ y + z ,...)`).

Now, I would like to take those posterior distributions on the means and generate a posterior distribution on the difference between the means. Is that a reasonable thing to do in a Bayesian analysis, and if so, how do you do it (either in theory or in R)?

Contents

If those requirements are met, one can view the MCMC sample as an approximation to the posterior. Each individual sample value is one sampled vector of values for \$theta\$; likewise, differencing two sampled parameters over the entire sample produces an approximated distribution of the difference between the two parameters. (I'm not familiar with MCMCPack, but I gather from your code and comment that `postDist[,"y2"]` and `postDist[,"y2"]` are vectors of samples from the posterior, so this should work.) This is one benefit of MCMC methods: If the parameters covary, then solving for their sum or difference analytically depends on knowing their joint distribution.