WinBUGS Training WinBUGS & linear regression
Transcript of WinBUGS Training WinBUGS & linear regression
WinBUGS TrainingTricks & Tips – Interface with R
Catherine Dettori & Jonathan Jaeger
1
WinBUGS & linear regression
Data:
Plot:
1 2 3 4 5
1 3 3 3 5
2
WinBUGS & linear regression
1 – Regression model:
2 – Estimation of parameters
3 – Frequentist approach uses t-tests
3
Frequentist approach
Result of the regression:
Prediction formula:
Estimate Std. error t-value P(>|t|)
0.6 0.7659 0.783 0.4906
0.8 0.2309 3.464 0.0405
4
WinBUGS
1- check model
2- load data
3- specify the number of MCMC chains
4- compile model
5- load initials values
6- generate burn-in value
7- parameters to be monitored
8- perform the sampling to generate posteriors
9- check convergence and display results
15
WinBUGS
16
WinBUGS – Node Statistics
95% credibility intervals
39
WinBUGS – Node Statistics
Estimate Std. error t-value P(>|t|)
0.6 0.7659 0.783 0.4906
0.8 0.2309 3.464 0.0405
40
WinBUGS
A way to identify non-convergence is to simulate multiple
sequences for over-dispersed starting points.
Intuitively, the behavior of all of the chains should be
basically the same.
In other words, the variance within the chains should be
the same as the variance across the chains.
In WinBUGS, stipulate the number of chains after 'load
data' and before 'compile' (obviously, as many sets of
initial values as chains have to be loaded, or generated).
45
WinBUGS – Gelman Rubin Statistic
The normalized width of the central 80% interval of the
pooled runs is green.
The normalized average width of the 80% intervals within
the individual runs is blue.
46
Script in WinBUGS
Another mean to use WinBUGS : script.
Advantages :
Faster (only a script for all the instructions).
Put all the graph and statistical results in one file.
Easy to modify the script to solve a new problem.
Disadvantages :
Difficult to manipulate the outputs.
47
Script in WinBUGS
check the model
48
Running WinBUGS using R
WinBUGS : uneasy to read complex sets of data and
initial values.
Quite boring to specify the parameters to be monitored
in each run.
Interesting to save the output and read it into R for
further analyses :
R2WinBUGS allows WinBUGS to be run from R
Possibility to have the results of the MCMC and work with
them (plot, convergence diagnostics…)
55
R2WinBUGS
1- Create a .txt file with the model.
2- In R, load coda and R2WinBUGS packages.
3- Load the data in a list.
4- Load the initials values in a list.
5- Specify the parameters in a vector.
6- Create a bugs object using:
data,
initials values,
parameters,
model,
…
56
R2WinBUGS
With the option codaPkg=TRUE:
Use the command read.bugs to work with this object:coda.sim1 <- read.bugs(sim1)
63
R2WinBUGS
Using the command plot:
64
R2WinBUGS
Using the command autocorr.plot:
65
R2WinBUGS
Using the command gelman.diag & gelman.plot:
66