Bayesian Regression Analysis – R Code

This is an R code on regression analysis: a Bayesian regression model is being implemented. The time series are randomly created so no meaningful results can be expected. Moreover, non-informative priors are utilized. Using proper priors the estimates would differ (the estimated slope is the mean of the OLS estimate and the information derived by the priors).

## Bayesian linear regression

# clear environment and console
rm(list = ls())

#install and load required packages

# create random series for the independent variable (var1) and dependent
# variables (var2 var3)
v1 = data.frame(var1 = runif(100, 20, 120))
v2 = data.frame(var2 = runif(100, 20, 120))
v3 = data.frame(var3 = runif(100, 20, 120))

# concatenate the time series
vv = c(v1, v2, v3)

# run a Bayesian regression
reg1 = bas.lm(var1 ~ ., data = vv,
prior = 'BIC', modelprior = uniform())

# run a linear regression
reg2 = lm(var1 ~ ., data = vv)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s