I am looking for a teaching example of a multivariate (not bivariate) implementation of Metropolis-Hastings for MCMC in R. I know several packages implement the algorithm more generally, but the code is difficult to follow and typically includes all sorts of other things besides this particular example. How do I implement Metropolis-Hastings for Bayesian multivariate regression like in this bivariate example?
If you want to extend the example you link to to a multivariate regression, take the code as it is and:
- Add one more predictor in the code chunk generating the data
- Add one more parameter in likelihood, as in pred = a1*x1 + a2*x2 + b
- Add the additional parameter in the prior specification
- Adjust the MCMC and plots to deal with 4 instead of 3 parameters