WebBUGS >> Main page Recent changes Show source History

Built-in models:Linear regression

Model

The multiple linear regression model with dependent variable \(y\) and independent variables \(\mathbf{x}=(x_{1},\ldots,x_{p})\),

\[ y_{i}=\beta_{0}+\beta_{1}x_{1}+,\ldots,+\beta_{p}x_{p}+e_{i} \]

where \(e_{i}\) is usually assumed to be iid \(N(0,\phi)\). As an example, we let \(p=2\) in the code.

Code

model{
 for (i in 1:N){
    mu[i]<-beta0+beta1*(x1[i]-mean(x1[]))+beta2*(x2[i]-mean(x2[]))
    y[i] ~ dnorm(mu[i],pre.phi)
 }
  beta0~dnorm(0,1.0E-6)
  beta1~dnorm(0,1.0E-6)
  beta2~dnorm(0,1.0E-6)
 
  pre.phi~dgamma(.001,.001)
 
  phi<-1/pre.phi
}


Powered by LionWiki. Last changed: 2014/11/11 21:44 Erase cookies Show source History