We'll construct a simple script in WinBuGS v1.4 (for Windows) to fit a simple
linear regression model to the above data:
price=a+b*age
To achieve this we require four files:
model
{
for( i in 1 : N ) {
mu[i] <- a+b*age[i]
price[i] ~ dnorm(mu[i], tau)
}
tau ~ dgamma(0.001, 0.001)
sigma <- 1 / sqrt(tau)
a ~ dnorm(0, 1.0E-12)
b ~ dnorm(0, 1.0E-12)
}
list(N=39, age = c(13, 14, 14,12, 9, 15, 10, 14, 9, 14, 13, 12, 9, 10, 15, 11, 15, 11, 7, 13, 13, 10, 9, 6, 11, 15, 13, 10, 9, 9, 15, 14, 14, 10, 14, 11, 13, 14, 10), price = c(2950, 2300, 3900, 2800, 5000, 2999, 3950, 2995, 4500, 2800, 1990, 3500, 5100, 3900, 2900, 4950, 2000, 3400, 8999, 4000, 2950, 3250, 3950, 4600, 4500, 1600, 3900, 4200, 6500, 3500, 2999, 2600, 3250, 2500, 2400, 3990, 4600, 450, 4700))
list( a=0, b=0, tau=1)
display('log')
check('scotts_data/price.model.odc')
data('scotts_data/price.data.odc')
compile(1)
inits(1,'scotts_data/price.inits.odc')
thin.samples(5)
update(10000)
set(a)
set(b)
set(sigma)
update(10000)
stats(*)
history(*)
density(*)
autoC(*)
coda(*,'scotts_data/')
save('scotts_data/priceLog')