Presentation is loading. Please wait.

Presentation is loading. Please wait.

Bursts modelling Using WinBUGS Tim Watson May 2012 :diagnostics/ :transformation/ :investment planning/ :portfolio optimisation/ :investment economics/

Similar presentations


Presentation on theme: "Bursts modelling Using WinBUGS Tim Watson May 2012 :diagnostics/ :transformation/ :investment planning/ :portfolio optimisation/ :investment economics/"— Presentation transcript:

1 Bursts modelling Using WinBUGS Tim Watson May 2012 :diagnostics/ :transformation/ :investment planning/ :portfolio optimisation/ :investment economics/ :regulation and economics/ :training/

2 Page : 2 © ICS Consulting Ltd 2012 Bayesian analysis software Using Gibbs Sampling for Windows. DoodleBugs – a graphical directed acyclic graph (DAG) Many add-ons, utilities, and variations of the package are also available (e.g. GeoBUGS-for spatial modelling, and PKBUGS-for pharmacokinetic) Can be run from other software packages, e.g. R. library(R2WinBUGS) Connecting to data Business as usual What is WinBUGS?

3 Page : 3 © ICS Consulting Ltd 2012 Exploratory Data Analysis Linear Model Log-Linear Model Maybe some non-linearity?

4 Page : 4 © ICS Consulting Ltd 2012 Define the model Load the data Specify the number of MCMC chains Compile the model Load values to initialise the algorithm Update the MCMC Sample parameters of interest Running a statistical model in WinBUGS

5 Page : 5 © ICS Consulting Ltd 2012 Note: WinBUGS uses precision instead of variance to specify a normal distribution! Model 1 Linear Regression in WinBUGS model { #specify likelihood for( i in 1 : N ) { Bursts[i] ~ dnorm(mu[i],tau) } for( i in 1 : N ) { mu[i] <- alpha + beta * frost[i] } #specify priors alpha ~ dnorm( 0.0,1.0E-6) beta ~ dnorm( 0.0,1.0E-6) tau ~ dgamma(0.001,0.001) sigma <- sqrt(1 / tau) }

6 Page : 6 © ICS Consulting Ltd 2012 Results R output Estimate Std. Error t value Pr(>|t|) (Intercept) 460.460 26.686 17.255 < 2e-16 *** Nr.Air.Frost.Days 25.616 3.504 7.312 2.19e-09 ***

7 Page : 7 © ICS Consulting Ltd 2012 Model 2 Poisson Regression in WinBUGS model { for( i in 1 : N ) { Bursts[i] ~ dpois(mu[i]) } for( i in 1 : N ) { log(mu[i]) <- alpha + beta * frost[i] } alpha ~ dnorm( 0.0,1.0E-6) beta ~ dnorm( 0.0,1.0E-6) } R output Estimate Std. Error z value Pr(>|z|) (Intercept) 6.155015 0.007951 774.10 <2e-16 *** Nr.Air.Frost.Days 0.038524 0.000861 44.74 <2e-16 ***

8 Page : 8 © ICS Consulting Ltd 2012 Real word data (missing data) - Model 2b Missing data are easily handled Missing observations are treated as unknown parameters Missing values are denoted by “NA” Missing responses are no problem; they are simply estimated A missing explanatory variable must either be replaced, or else given some prior distribution Elicitation model; { for( i in 1 : N ) { Bursts[i] ~ dpois(mu[i]) } for( i in 1 : N ) { log(mu[i]) <- alpha + beta * frost[i] } alpha ~ dnorm( 0.0,1.0E-6) beta ~ dnorm( 0.0,1.0E-6) frost[1]~dunif(0,20) frost[2]~dunif(0,20) frost[4]~dunif(0,20) } list(Bursts = c(581, 504, NA, 403, 395, 484, 531, 338, 599, 611, 396, 1038, 990, 887, 722, 446, 510, 666, NA, 453, 300, 435, 532, NA, 1433, 626, 792, 499, 339, 247, 646, 367, 494, 372, 752, 924, 781, 599, 482, 438, 570, 533, 494, 715, 555, 370, 614, 524, 501, 851, 472), frost = c(NA, NA, 5.7, NA, 0.1, 0.1, 0, 0, 0, 2, 3.8, 15.3, 14.8, 11, 6.3, 2.5, 0.1, 0, 0, 0, 0, 0.9, 0.5, 13.2, 18.9, 15.4, 12.3, 5.1, 2.3, 0, 0, 0, 0.2, 2.7, 9.4, 23.1, 15.2, 3.8, 9.9, 0.3, 0.2, 0.2, 0, 0, 0, 0.4, 1.1, 4.1, 7.8, 11.1, 2.8 ),N=51)

9 Page : 9 © ICS Consulting Ltd 2012 Poisson Regression with some Missing observations in WinBUGS Frost missingBursts missing frost =c(4.1,10.1,5.8) burst=c(504,664,1433)

10 Page : 10 © ICS Consulting Ltd 2012 Month effect - Model 4

11 Page : 11 © ICS Consulting Ltd 2012 BUGS language quite straightforward to learn. Doodle Bugs even easier. Handles missing data easily. Very fast especially when the initialising values are closer to the stationary distribution. Can fit a wide variety of statistical models. Convenient in running multiple MCMC chains. Automated in R and other tools (including Excel) library(R2WinBUGS) library(Rexcel) Why WinBUGS?

12 Page : 12 © ICS Consulting Ltd 2012 Need to understand what you are doing Saving the data in the appropriate format can be very challenging especially large data set. Algorithm can easily crash especially when priors are not well specified or due to unrealistic initialising values. Algorithm can be very slow especially when dealing with hierarchical model. Needs to know the model to be fitted as every distribution have to be defined. Negatives about WinBUGS

13 Page : 13 © ICS Consulting Ltd 2012 Limitation in plotting capability. Learning BUGS syntax (though very similar to other packages such as R, S-PLUS). Using extreme priors especially non-informative priors can cause the algorithm to crash. Challenges with WinBUGS


Download ppt "Bursts modelling Using WinBUGS Tim Watson May 2012 :diagnostics/ :transformation/ :investment planning/ :portfolio optimisation/ :investment economics/"

Similar presentations


Ads by Google