Solved – Truncated normal distribution with WinBUGS

bayesianregressionsoftware

I am trying to do a very simple regression analysis using a truncated normal distribution with WinBUGS.

Let's suppose the following model $Y|\beta_0,\beta_1,\sigma \sim Normal(\beta_0+\beta_1X,\sigma)$ where $Y$ is the grade of 13 students (from 0 to 10) and $X$ is the gender of each student (1 for Males and 0 for Females). We wonder whether the grade depends on the gender, so we could state if males have higher grades than females or the other way around. The following code is fine and does the job. However, as the grade is scaled from 0 to 10, I thought that using a truncated normal distribution could improve the model: $Y|\beta_0,\beta_1,\sigma \sim TrNormal(\beta_0+\beta_1X,\sigma,\alpha=0,\beta=10)$ where $\alpha$ and $\beta$ are the lower and upper bounds respectively.

The truncated normal distribution for WinBUGS is available as a WBDev shared component. However, when I am trying to use it with the following script it hangs unexpectedly. It returns a messages titled "undefined real result". What am I doing wrong?

WinBUGS script:

#MODEL
model
{
    for(i in 1:N)
    {
       mu[i]<-b0+b1*x[i]
       #y[i]~dnorm(mu[i],tau)
       y[i]~djl.dnorm.trunc(mu[i],tau,0,10)
    }
    tau~dgamma(0.01,0.01)
    b0~dnorm(0,1.0E-6)
    b1~dnorm(0,1.0E-6)
    sigma<-sqrt(1/tau)
}
#DATA
list(N=13,y=c(9.6,7.0,5.0,8.0,8.4,6.4,6.1,9.1,8.8,5.7,8.9,6.1,6.5),x=c(1,1,1,1,1,1,0,0,0,0,0,0,0))
#INITS
list(tau=1, b0=0, b1=0)

Best Answer

In openbugs (so I would assume the same in winbugs, but could be wrong) you can do a truncated distribution using the T function, something like:

y[i] ~ dnorm(x[i],tau)T(0,10)
Related Question