Professional Documents
Culture Documents
d i to
WinBUGS
Olivier Gimenez
University of St Andrews
Andrews, Scotland
A bri
brieff hi
history
t r
Who?
Nicky Best
Imperial College Faculty of
Medicine, London (UK)
Thomas Andrew
Wally Gilks
University of Helsinki,
Helsinki (Finland)
David Spiegelhalter
MRC Biostatistics Unit
Institute of Public Health
Cambridge (UK)
Key principle
l
Y
You
specify
if the
h prior
i and
d build
b ild up the
h likelihood
lik lih d
(|D)
(
) / L(D|)
(
) ()
( )
A biological
g
example
p throughout
g
White stork (Ciconia ciconia) in Alsace 1948-1970
Demographic components
(fecundity, breeding success,
survival, etc)
Climate
2.55
1.85
2.05
2.88
3.13
2.21
2 43
2.43
2.69
2.55
2.84
2.47
2.69
2.52
2 31
2.31
2.07
2.35
2.98
1.98
2.53
2.21
2 62
2.62
1.78
2.30
15.1
13.3
15.3
13.3
14.6
15.6
13 1
13.1
13.1
15.0
11.7
15.3
14.4
14.4
12 7
12.7
11.7
11.9
15.9
13.4
14.0
13.9
12 9
12.9
15.1
13.0
67
52
88
61
32
36
72
43
92
32
86
28
57
55
66
26
28
96
48
90
86
78
87
Yi ii.i.d.
i d ~ N(
N( i,2),
) i=1,...,23
i 1
23
i = + r Ri + t Ti
3. Estimation of parameters: , r, t,
4. Frequentist inference uses t-tests
2.55
1.85
2.05
2.88
3.13
2.21
...
2.30
Y=
temperature
rainfall
15.1
13.3
15.3
13.3
14.6
15.6
...
13.0
67
52
88
61
32
36
...
87
T Temp
Temp. May (C)
R Rainf. May (mm)
Estimate
0.031069
-0.007316
Std. Error
0.054690
0.002897
t value Pr(>|t|)
0.568 0.57629
-2.525 0.02011 *
2.55
1.85
2.05
2.88
3.13
2.21
...
2.30
Y=
temperature
rainfall
15.1
13.3
15.3
13.3
14.6
15.6
...
13.0
67
52
88
61
32
36
...
87
T Temp
Temp. May (C)
R Rainf. May (mm)
Estimate
0.031069
-0.007316
Std. Error
0.054690
0.002897
t value Pr(>|t|)
0.568 0.57629
-2.525 0.02011 *
Running WinBUGS
Wh do
What
d you need?
d?
Running WinBUGS
T model
The
d
use the WinBUGS
command 'model'
Running WinBUGS
Data andd initial values
...and
'vector'
structures
(R/Splus
syntax)
Use 'list'
structures
(R/Splus
syntax)...
Running WinBUGS
Overall
2 - data
3 - initial values
Running WinBUGS
At last!!
1- check model
1
2- load data
3- compile model
4- load initial values
4
5- generate burn-in values
6- parameters to be monitored
7- p
perform the sampling
p g to g
generate p
posteriors
8- check convergence and display results
Running WinBUGS
1. Check model
d
Running WinBUGS
1. Check model:
d highlight ''model'
d '
Running WinBUGS
1. Check model:
d open the Model
d Specification T
Tool
Running WinBUGS
1. Check model:
d Now click ''check model'
d '
Running WinBUGS
1 Check
1.
Ch k model:
d l Watch
W h out for
f the
h confirmation
fi
i at the
h foot
f off the
h screen
Running WinBUGS
2. Loadd ddata: Now highlight the 'list'
' ' in the data
d window
d
Running WinBUGS
2. Loadd ddata: then click ''loadd ddata''
Running WinBUGS
2 Load
2.
L d ddata: watchh out ffor the
h confirmation
fi
i at the
h foot
f off the
h screen
Running WinBUGS
3. Compile model:
d Next, click ''compile''
Running WinBUGS
3 Compile
3.
C il model:
d l watchh out for
f the
h confirmation
fi
i at the
h foot
f off the
h screen
Running WinBUGS
4. Loadd initial values: highlight the 'list'
' ' in the data
d window
d
Running WinBUGS
4. Loadd initial values: click 'load
' d inits''
Running WinBUGS
4 Load
4.
L d iinitial
i i l values:
l watchh out for
f the
h confirmation
fi
i at the
h foot
f off the
h screen
Running WinBUGS
5. Generate Burn-in values: Open the Model
d Update
d T
Tool
Running WinBUGS
5 Generate
5.
G
B
Burn-in
i values:
l Give
Gi the
h number
b off burn-in
b i iterations
i
i (1000)
Running WinBUGS
5 Generate
5.
G
B
Burn-in
i values:
l click
li k 'update'
' d ' to do
d the
h sampling
li
Running WinBUGS
6 Monitor
6.
M i parameters: open the
h Inference
I f
Samples
S l Tool
T l
Running WinBUGS
6 Monitor
6.
M i parameters: Enter
E
'intercept'
'i
' in
i the
h node
d box
b andd click
li k 'set'
' '
Running WinBUGS
6 Monitor
6.
M i parameters: Enter
E
'slope_temperature'
'l
' in
i the
h node
d box
b andd click
li k 'set'
' '
Running WinBUGS
6 Monitor
6.
M i parameters: Enter
E
'slope_rainfall'
'l
i f ll' in
i the
h node
d box
b andd click
li k 'set'
' '
Running WinBUGS
7 Generate
7.
G
posterior
i values:
l enter the
h number
b off samples
l you want to take
k (10000)
Running WinBUGS
7 Generate
7.
G
posterior
i values:
l click
li k 'update'
' d ' to do
d the
h sampling
li
Running WinBUGS
8. Summarize posteriors: Enter '*' in the node box and click 'stats'
Running WinBUGS
8. Summarize posteriors: mean, median and credible intervals
Running WinBUGS
8. Summarize posteriors: 95% Credible intervals
temperature
rainfall
Estimate
0.031069
-0.007316
Std. Error
0.054690
0.002897
t value Pr(>|t|)
0.568 0.57629
-2.525 0.02011 *
Running WinBUGS
8. Summarize posteriors: 95% Credible intervals
temperature
rainfall
Estimate
0.031069
-0.007316
Std. Error
0.054690
0.002897
t value Pr(>|t|)
0.568 0.57629
-2.525 0.02011 *
Running WinBUGS
8. Summarize posteriors: click 'history'
Running WinBUGS
8. Summarize posteriors: click 'auto cor'
Problem of autocorrelation
Re-running WinBUGS
1,2,...7, and 8. Summarize posteriors: click 'auto cor'
slope temperature
slope.temperature
1.0
0.5
0.0
-0.5
-1.0
0
20
40
lag
slope.rainfall
1.0
0.5
0.0
-0.5
-1.0
0
20
40
lag
g
autocorrelation OK
Re-running WinBUGS
1,2,...7, and 8. Summarize posteriors: click 'density'
slope.rainfall sample: 1000
8.0
6.0
40
4.0
2.0
0.0
-0.6
06
-0.4
04
-0.2
02
slope.temperature
p
p
sample:
p 1000
8.0
6.0
4.0
2.0
0.0
-0.4
-0.2
0.0
0.2
Re-running WinBUGS
1,2,...7, and 8. Summarize posteriors: click 'quantiles'
slope.rainfall
p
-2.77556E-17
-0.1
-0.2
-0.3
-0.4
1041
1250
1500
1750
iteration
slope.temperature
0.3
0.2
0.1
0.0
-0.1
-0.2
02
1041
1250
1500
iteration
1750
Running WinBUGS
8. Checking for convergence using the Brooks-Gelman-Rubin criterion
Running WinBUGS
8. Checking for convergence using the Brooks-Gelman-Rubin criterion
slope.temperature chains 1:2
1.5
1.0
10
1.0
0.5
0.5
0.0
0.0
1
5000
iteration
10000
5000
10000
iteration
Re-running WinBUGS
1,2,...7, and 8. Summarize posteriors: others...
151 / 173
105 / 164
73 / 103
107 / 113
113 / 122
87 / 112
77 / 98
108 / 121
118 / 132
122 / 136
112 / 133
120 / 137
122 / 145
89 / 117
69 / 90
71 / 80
53 / 67
41 / 54
53 / 58
31 / 39
35 / 42
14 / 23
18 / 23
15.1
13.3
15.3
13.3
14.6
15.6
13 1
13.1
13.1
15.0
11.7
15.3
14.4
14.4
12 7
12.7
11.7
11.9
15.9
13.4
14.0
13.9
12 9
12.9
15.1
13.0
67
52
88
61
32
36
72
43
92
32
86
28
57
55
66
26
28
96
48
90
86
78
87
model
# succ. in
i year i ~ Bin(p
Bi ( i, totall # couples
l in
i year i)
where pi the probability of success in year i
logit(pi)= + r Ri + t Ti,
i=1,...,23
noninformative priors
lower
upper
53
58
31
39
35
42
14
23
18
23
nbpairs
173
164
15 3
15.3
113
122
15.6
15
6
14.0
13 9
13.9
12.9
15.1
13 0
13.0
temperature
15.1
13.3
88
13.3
14.6
36
48
90
86
78
87
rainfall
67
52
61
32
Bayesian Model
d l SSelection
l
Discriminating between different models
can often be of particular interest, since
they represent competing biological
hypotheses.
How do we decide which covariates to use?
often there may
y be a large
g number of
possible covariates.
Example
l (cont))
Model
d l SSelection
l
Bayesian Approach
A
h
Prior on parameters
in model m
Prior on model m
Posterior Model
d l Probabilities
b bl
MCMC-based
C C b d estimates
Reversible
bl Jump MCMC
C C
Markov
k chain
h
Each
E
h iteration
it
ti
off the
th Markov
M k
chain
h i essentially
ti ll
involves two steps:
1
1.
2
2.
WinBUGS
GS
Variable selection
Splines
See http://www.winbugs-development.org.uk/rjmcmc.html
So, in particular, WinBUGS can be used for model
selection in the White storks example.
Example:
l White
h SStorks
k
Example:
l White
h SStorks
k
WinBUGS demonstration.
Results
l
Models with largest posterior support
0001000000
0000000000
0001010000
0001100000
0001000001
1001000000
0001000100
0001001000
0001000010
0000000100
0101000000
0011000000
1000000000
0000010000
0.5178058297
0
5178058297
0.07629791141
0.0474087675
0 03814092265
0.03814092265
0.03085379849
0.02549001607
0 02374569658
0.02374569658
0.02336699564
0.0229240303
0 02123479458
0.02123479458
0.01809960982
0.01540739041
0.01186825798
0.01103282075
0.5178058297
0
5178058297
0.5941037411
0.6415125086
0 6796534313
0.6796534313
0.7105072297
0.7359972458
0 7597429424
0.7597429424
0.783109938
0.8060339683
0 8272687629
0.8272687629
0.8453683727
0.8607757631
0.8726440211
0.8836768419
Results
l
Additionally the (marginal) posterior probability that each covariate influence
the survival rates:
node
effect[1]
effect[2]
effect[3]
effect[4]
effect[5]
effect[6]
effect[7]
effect[8]
[ ]
effect[9]
effect[10]
p
sdeps
mean
0.01
0 00
0.00
0.00
0.30
-0.01
0.01
0.01
-0.00
0.01
0.01
-0.01
0.91
0.20
sd
0.04
0 03
0.03
0.02
0.17
0.04
0.05
0.03
0.06
0.04
0.04
0.01
0.14
Results:
l survivall rates
0.8
1.0
S
Survival
i l rate
t for
f white
hit storks
t k
0.6
*
-
*
-
*
-
*
-
*
*
-
*
-
0..4
0.2
*
*
*
*
*
*
0.0
Survival rate
S
1960
1965
Year
1970