Gibbs sampler for multiple linear regression

Project information

Project members
brice.semmens e2holmes eric.ward mark.scheuerell

Sharing
Public


Description
THE FOLLOWING FUNCTION CONDUCTS MULTIPLE LINEAR REGRESSION PARAMETER ESTIMATION VIA MCMC USING GIBBS SAMPLING.



The point of this code is to show how to do it with a conjugate distribution such that the method can easily be plugged into LAMBDA.



The function assumes that:

1)the B coefficients are normally distributed ~N(prior_mean,prior_s2)and thus have a normal distribution prior. Large prior variances produce suitably "diffuse" priors

2) the model variance is gamma distributed Ga(alpha, beta), with an associated prior. Small values of alpha and beta (<.001) produce a suitably "diffuse" prior. Note that Matlab's parameterization of their gamma function is a bit wonky compared to the standard. Basically, Matlab uses Ga(alpha,1/beta)-- ie. inverse of the standard scale parameter.

The R code contains 2 versions of Bayesian linear regression. The first (univariate.all) uses the multivariate normal distribution to sample regression coefficients; the second (univariate.vat) does variable at a time sampling. Both R versions are nearly identical, allow a flexible range of priors for B, and allow the prior variance to be specified either as the shape-scale (e.g. gamma, scaled inv chi sq) or in terms of the mean-variance. Output includes saved parameter draws, which can be fed into CODA, and the calculation of the log(Bayes Factor) to be used for model selection.


Files

Gibbs sampler for multiple linear regression /
  • Download Gibbs sampler for multiple linear regression as zip archive Download
Name Status Rev Size Updated Downloads Brief Description Actions
Item is folder R code & examples
Stable
- 3 items 07/05/2008 17:57 PDT 1523 141 d
(none)
bloodpressure.odc
Stable
1 2.1 KB 07/02/2008 15:50 PDT 92 92 f
WinBUGS script that does the exact same thing as the 'call_Gibbs.m' script does (uses same data and model). I have included this to demonstrate that the Matlab Gibbs sampler operates identically to Winbugs. Change the priors around a bit to convince yourselves that this is true.
call_Gibbs.m
Stable
2 1.4 KB 07/02/2008 15:49 PDT 236 236 f
This program gives an example of function use: defines data, specifies priors and model parameters, and then calls the function below.
MLR_Gibbs_func.m
Stable
2 646 B 07/02/2008 15:50 PDT 343 343 f
this is the function that carries out MCMC using Gibbs sampler

Keywords



Downloads

149 project downloads
2194 individual file downloads

Sculpin 0.2 | xhtml | problems or comments? | report bugs