0% found this document useful (0 votes)
23 views6 pages

Pump Example

Bayesian Analysis Tutorial

Uploaded by

James Rush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views6 pages

Pump Example

Bayesian Analysis Tutorial

Uploaded by

James Rush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Pump Data Example

The data below show number of failures of pumps at a power plant for 10 pumps. Two
different kinds of pumps were in use. Also shown is the length of operation in thousands
of hours for each pump.

y = number of pump failures t = length of operation (in 1000s of hours)


x = type of pump (1,2)

Pump y t x
1 19 31.440 1
2 5 62.880 1
3 5 94.320 1
4 14 125.760 1
5 1 1.048 2
6 1 1.048 2
7 4 2.096 2
8 3 5.240 2
9 22 10.480 2
10 1 15.720 2

A Bayesian Model

Likelihood:
yi | θi ∼ Poisson(ti θi ) yi | θi independent i = 1, . . . , 10

Prior 1:
θi | µi , γ ∼ Gamma(γµi , γ)
log µi = α + β xi

Prior 2: (Noninformative)
α ∼ N (0, 106 ) β ∼ N (0, 106 ) γ ∼ Gamma(0.01, 0.01)

The WinBugs Code

Having specified the model, we are now ready to use WinBugs. You are not expected to
be an expert programmer. This is why the code is given to you. However, you should be
able to modify this code slightly for a similar problem where only the data have changed.

Note that the program is short and assignment statements (<−) are the same as in R.
Note also that for the normal distribution, the variance is parameterized in the numerator
for precision. This means, for example, that if α ∼ N (0, 106 ), the WinBugs code is

alpha ~ dnorm(0.0,1.0E-6)
model
{
for(i in 1:N) {
y[i] ~ dpois(lambda[i])
lambda[i] <- theta[i] * t[i]
theta[i] ~ dgamma(gammu[i],gamma)
gammu[i] <- gamma * mu[i]
log(mu[i]) <- alpha + beta * x[i]
}
alpha ~ dnorm(0.0,1.0E-6)
beta ~ dnorm(0.0,1.0E-6)
gamma ~ dgamma(0.01,0.01)
}

list(y=c(19,5,5,14,1,1,4,3,22,1),
t=c(31.440,62.880,94.320,125.760,1.048,1.048,2.096,5.240,10.480,15.720),
x=c(0,0,0,0,1,1,1,1,1,1),
N=10)

list(alpha=0,beta=0,gamma=1)

How to Use WinBugs

Step-by-step procedures are now outlined for using WinBugs.

1. Start WinBugs (close the License Agreement) and open a new program window by
clicking on File -> New.

2. Type or copy and paste the program above into the editor.

3. In the menu bar, click on Model -> Specification...

4. Highlight the word “model” in your program either by dragging or double clicking
and then click on check model in the Specification Tool. “model is syntactically
correct” should appear in the lower left corner of the WinBUGS display.

5. Highlight the word “list” that describes your data and click on load data in the
Specification Tool. “data loaded” should appear in the lower left corner of the
WinBUGS display. Click on compile. “model compiled” should appear in the
lower left of the display.

6. Highlight the word “list” that describes your initial values and click on load inits.
If you see “this chain contains unitialized variables” then click on gen inits. If the
message in the lower left corner reads, “model initialized” close the Specification
Tool.
7. Click on Inference -> Samples.... The Sample Monitor Tool will appear. In the
“node” dialogue box, type in the name of each parameter in your model that you
want to make inference about, followed by clicking the “set” button. For this prob-
lem, the parameters of interest are theta, alpha, beta, and gamma. The parameters
should be visible in the “node” drop down list.

8. Click on Model -> Update....In the “updates” dialogue box, type in the number of
iterations you want. For the models we are using, 20,000 should be enough, possibly
50,000 for slowly converging chains. Leave “refresh” and “thin” alone. Click on the
“update” button and the chain will start to run. When iterations are completed,
close the Update Tool.

9. Return to the Sample Monitor Tool and using the “node” drop down list, select the
parameter you want to make inference about. Now click on the “history”, “density”,
or “stats” buttons to see results.

10. These Markov chains are designed to converge in distribution to the posterior distri-
butions of your parameters. Therefore, we usually discard initial iterations. These
initial iterations are usually called burn-in. In the “beg” dialogue box type in 5001
for a burn-in of 5,000 iterations. The “history” button is a good tool for monitoring
mixing and convergence of the chain.

11. Running two chains with different initial values is also commonly done to ensure
convergence to the posterior distribution.

Some screen shots appear below. Results can vary slightly due to the nature of simulation.

You might also like