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 / R code & examples /
  • Download contents of Gibbs sampler for multiple linear regression/R code & examples as zip archive Download
Name Status Rev Size Updated Downloads Brief Description Actions
Go to parent folder Parent directory - - - - - - -
univariate.R
Stable
2 1.3 KB 07/05/2008 17:34 PDT 318 318 f
This is the master file, to be sourced
univariate_simple_example.r
Stable
1 1.7 KB 07/05/2008 14:24 PDT 239 239 f
This script illustrates (1) how to source the univariate.R file, (2) how to specifiy priors / mcmc parameter, (3) application to the blood pressure data

Keywords



Downloads

84 project downloads
1006 individual file downloads

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