Sample WinBuGS 1.4 Script using Price Data

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:

1) A Model File: ("price.model.odc")
This specifies the model in the BuGS language:
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)
	}
2) A Data File: ("price.data.odc")
This can be in Splus format (e.g. use the dput command). However, note that matrices probably load (via row and column) in the opposite direction to Splus!
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))
3) An Inits File: ("price.inits.odc")
A file containing the initial state of the chain. There is an option for auto generation, although this may not work with very diffuse priors.
list(
a=0, b=0, tau=1)
4) A Script File
This is the file that saves you hours upon hours of hassle loading files, highlighting words, playing with menu options etc! Basically you run the whole operation from here. Just open the script in WinBuGS, and with the file in focus press ALT-M, ALT-C (or select MODEL-SCRIPT from the drop-down menu). A summary of the output is put in the specified Log file.
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')