Presentation is loading. Please wait.

Presentation is loading. Please wait.

An Introduction to WinBUGS and BOA. Outline zIntroduction zQuick review of Bayesian statistical analysis zThe WinBUGS language zConvergence diagnostics.

Similar presentations


Presentation on theme: "An Introduction to WinBUGS and BOA. Outline zIntroduction zQuick review of Bayesian statistical analysis zThe WinBUGS language zConvergence diagnostics."— Presentation transcript:

1 An Introduction to WinBUGS and BOA

2 Outline zIntroduction zQuick review of Bayesian statistical analysis zThe WinBUGS language zConvergence diagnostics and BOA (Bayesian Output Analysis). zIllustration with example --- Meta - analysis

3 Introduction zWhat is WinBUGS? yjoint endeavor between the MRC Biostatistics Unit in Cambridge and the Department of Epidemiology and Public Health of Imperial College, at St Mary's Hospital London yBUGS: Bayesian Inference Using Gibbs Sampling yWinBUGS: DoodleBUGS (graphical representation of model) and window interface for controlling the analysis.

4 Introduction zWinBUGS can handle analysis for complex statistical models yMissing data yMeasurement error yNo closed form for posterior distribution zBayesian posterior inference achieved via Markov chain Monte Carlo (MCMC) Integration yUseful when no closed form exists.

5 Bayesian Inference zSuppose we have data x, and unknowns  which might be ymodel parameters ymissing data yevents we did not observe directly or exactly (e. g., latent variables) Bayesian approach concerns making statements about  given data x. zRecall Bayes theorem:

6 Bayesian Inference zComponents of Bayesian inference  The prior distribution p(  ). Use probability as means of quantifying uncertainty about  before taking into account the data.  The likelihood p(x|  ). Relate all variables into a “full probability model”.  The posterior distribution p(  |x). Express uncertainty about  after taking into account the data.  Utilities --- required for decision making and not discussed here. zGiven a posterior distribution p(  |x), we may want ymean, standard deviations, medians etc. yprobability of exceeding certain thresholds, p(  >  0 |x). yInference on arbitrary functions of unknown model parameters. And they are easily to be implemented in WinBUGS.

7 Priors zWhere does the prior come from? yIt is in principle subjective. yIt might be elicited from experts. yIt might be more convincing to be based on existing data. But the assumed relevance is still a subjective judgement. yThere are various “objective” approaches. yConjugacy is useful but no longer necessary. yIt might be assumed unknown (full Bayes) or “estimated” (Empirical Bayes). z“Non-informative” priors

8 Priors z“Non-informative” priors yalso known as vague, ignorance, flat, diffuse and so on yThere could exist a prior that reproduces the classical results. yOften improper. yUsually quite unrealistic. yHowever, always useful to report likelihood-based results as arising from a ‘reference’ prior. zWinBUGS does not allow improper priors. zGeneral idea: by sensitivity analysis to a community of priors, one can assess whether the current results will be convincing to a broad spectrum of opinion.

9 Bayesian Inference zProbabilities of parameters are based on all available information. zSome theoretical advantages (Spiegelhalter D. 1999) yOnly need probability theory as basis for inference. yNo need to worry about statistical ‘principles’ such as: unbiasedness, efficiency, sufficiency, ancillarity, consistency, asymptotics and so on. yNo need to worry about significance tests, stopping rules, p - values. yModels can be as complex as reality demands (But WinBUGS still has its limitations). yIntegrates with planning decisions. yTell us what is desired: how should this piece of evidence change what we currently believe?

10 Bayesian Inference zSome practical difficulties (Spiegelhalter D. 1999) yInferences need to be justified to an outside world (reviewers, regulatory bodies, the public and so on): in particular xWhere did the prior come from? xIs the model for the data appropriate (standard diagnostics)? xIf making decisions, whose utilities? yAlthough huge progress has been made, computational problems can still be considerable. yCannot overcome basic deficiencies in design. yStandards are needed for Bayesian analysis and reporting.

11 MCMC --- To Achieve Bayesian Inference zMCMC --- Markov chain Monte Carlo. zUsually we are interested in studying a vector of unknown , say, with k components and the posterior distribution for  or components of  might not be able to simplify to known distribution forms. zRemedy: ySampling from a Markov chain with p(  |x) as its stationary distribution. yGibbs Sampling: sampling from full conditional distribution p(  j |  1,…,  j-1,  j+1,…  k, x) yMethods have been developed to implement sampling.

12 Sampling methods used in WinBUGS zThe sampling methods are used in the following hierarchies:

13 MCMC --- To Achieve Bayesian Inference zInference may be achieve via Monte Carlo integration. zMonte Carlo integration ySuppose we can draw samples from the joint posterior distribution for , i.e.  (1),  (2), …,  (n) ~ p(  |x) yThen yResult: really easy to make inference on an arbitrary function of parameters!!

14 Bayesian Graphical Modeling zBasis of WinBUGS modeling: conditional independence, i.e., the full joint distribution of all quantities V has a simple factorization in terms of the conditional distribution of each component (node). zCrucial idea: we need only provide the parent-child distribution in order to fully specify the model in WinBUGS. zRepresentation using graphs (DoodleBUGS):

15 Recap: Bayesian inference zBayesian inference is based on the posterior distribution, which is derived from prior distribution and likelihood through Bayes theorem. zBayesian inference is achieved through Monte Carlo integration where samples of posterior distribution can be obtained from MCMC simulation.

16 Analysis using WinBUGS zThree basic parts of a WinBUGS file: yModel specification xBUGS language: Similar to S - Plus. xGraphical language: Using DoodleBUGS It is good practice to construct a directed graphical model to communicate the structure of the problem. However, there are some features in BUGS language that could not be represented by DoodleBUGS. Examples of DoodleBUGS are given but no more details. For tutorial purpose, see http://www.mrc-bsu.cam.ac.uk/bugs/winbugs/winbugs-demo.pdf for “WinBUGS Demo” and “Doodle help” in WinBUGS13 help. yData yInitial values for unknowns .

17 Expressing model in the BUGS language zLexical conventions yQuantity (node) names. xCharacters: letters, numbers and period. xStarting with a letter, not ending with a period. xUpper or lower case or mixed, but case is important. xLength restriction: 32 characters. yIndexing xVectors and matrices are indexed within square brackets [..]. xNo limitation on dimensionality of arrays. yNumbers xStandard or exponential notation. xA decimal point must be included in the exponential format. xLegal notion for 0.0001:.0001, 0.0001, 1.0E-4, 1.0e-4, 1.E- 4, 1.0E-04, but NOT 1E-4.

18 Expressing model in the BUGS language zModel statement model { text-based statements to describe model in BUGS language } yArbitrary spaces may be used in statements. yMultiple statements may appear in a single line as well as one statement may extend over several lines. yComment line is followed by a #.

19 Expressing model in the BUGS language zModel description yConstant: fixed by the design of study. yStochastic nodes: variables (data or parameters) that are given a distribution x ~ dbin(p,n) where ~ means “distributed as”. xThe parameters of a distribution must be explicit. Scalar parameters can be numerical constants but function expressions are not allowed. xCurrently, WinBUGS could handle 20 distributions.(See Appendix A, Table I)

20 Expressing model in the BUGS language zModel description (cont.) yDeterministic nodes: logical functions of other nodes. pred <- beta0 + beta1 * x orLog(p) <-  where <- means “to be replaced by”. xCan not be given initial values or data except for data transformation facility (discussed below). xLogical expressions can be built using: +, –, *, / and unitary minus. xFunctions in Table II (Appendix B) could also be used in logical expressions.

21 Expressing model in the BUGS language zfor loops yAllow repetitive structures to be concisely described. ySame syntax as that of S - plus: for (name in expression1:expression2) { statements } xThe two expressions need to be evaluated to be fixed integer quantities. xPossibly as functions using + – * /.

22 Expressing model in the BUGS language zExample --- simple regression : yResponse Y, explanatory variable x and N independent observations. yNormal assumption. xfor ( i in 1:N) { Y[i] ~ dnorm(mu[i],tau*) mu[i] <- alpha + beta*x[i] sigma <- 1/sqrt(tau) } *: tau = precision of normal distribution = 1/variance

23 Example of graphical modeling zEllipses: stochastic or deterministic node zsolid arrow: a stochastic dependence zhollow arrow: a logical function. zPlate: repeated structure

24 More on Stochastic nodes zMultivariate Nodes zUsing distributions unlisted in Table I. zCensoring and truncation

25 More on Stochastic nodes zMultivariate Nodes yDirichlet, multinomial, multivariate normal and Wishart.  Contiguous elements : Multivariate nodes must form contiguous elements in an array. For example, to define a set of 3-dim multivariate normal variables x as a bidimensional array, we could write: xfor (i in 1:K) { X[i,1:3] ~dmnorm (mu[1:3], prec[1:3,1:3]) }  No missing data : missing values are not allowed in data defined as multivariate normal or multinomial. xPossible remedy: re-express the multivariate likelihood as a sequence of conditional univariate normal or binomial distributions.

26 More on Stochastic nodes zMultivariate Nodes (cont.)  Conjugate updating : xDirichlet: only as prior (parent) of multinomial probs. xWishart: only as prior (parent) of multivariate normal precision matrix. xParameters of Dirichlet and Wishart must be specified explicitly and can not be given prior distribution.  Structured precision matrices for multivariate normals : xIf a Wishart prior is not used for the precision matrix of a multivariate node, then the elements of the precision matrix are updated univariately and it is the user’s responsibility to specify a positive-definite matrix.

27 More on Stochastic nodes zUsing distributions unlisted in Table I. ySuppose data y is a vector of length n and for unknown , it is desired to fit the model p (y) = f (y,  ) and f is the formula of the density that is not currently handled by BUGS, the following trick could be used: for (i in 1:n) { ones[i] <- 1 ones[i] <- dbern(p[i]) p[i] <- f (y[i],  ) / K } Where K is a sufficiently large constant to ensure p[i] <- 1.

28 More on Stochastic nodes zCensoring and truncation yCensoring xinterval censored: y ~ ddist(  )I(lower, upper) xright censored: y ~ ddist(  )I(lower,) xleft censored: y ~ ddist(  )I(, upper) yFor unknown , the sampling will only be correct if the bounds are conditionally independent  of given y. yThis construct should NOT be used for modeling truncated distribution. Truncated distribution may be handled by working out a usually complex algebraic form for the likelihood and using the technique for arbitrary distributions just discussed.  Check : If you knew y, would knowing (lower, upper) tell you anything further about  ? --- Yes so, inappropriate construct of I.

29 More on Model specification zThe declarative structure of model specification in BUGS language requires each node appears once and only once on the left hand side of a node. zData transformation is the only exception. zIndexing

30 More on Model specification zData transformation ySuppose we have data y and want to model, the following statements could be used: for (i in 1:N) { z[i] <- sqrt(y[i]) z[i] ~ dnorm(mu, tau) } yAdvantage: No need to create a separate variable in data. yNo missing data is allowed. yExample: leuk; endo

31 More on Model specification zIndexing yFunctions as an index x+ – * / and appropriate bracketing. e.g. y[(I+J)*K] xOn the left hand side of a relation, a constant or a function of data that always evaluates to a fixed value is allowed. xOn the right hand side of a relation, a fixed value or a named node (nested indexing) is allowed. xNo function of unobserved nodes allowed. Intermediate deterministic nodes. yImplicit indexing : broadly following conventions of S - plus. xn:m represents n, n+1,..., m. xx[] represents all values of a vector x. xy[,3] indicates all values of the third column of a two-dimensional array y.

32 More on Model specification zIndexing (cont.) yNested indexing xcan be very effective. xe.g., suppose there are N studies and each study have different number of treatments, S[N] is a vector contains information about the treatments across studies. Then “treatment” coefficients beta[I] can be declared and fitted using beta[S[i]] in a regression model.  Example: eyes.  Multidimensional arrays are handled as one-dimensional arrays with a constructed index. Thus functions defined on arrays must be over equally spaced nodes within an array: for example sum(i,1:4,k).

33 Data and Initial Values Files zFormatting of data. yS - plus format or rectangular format. xS - plus format Scalars and arrays are named and given values in a single structure. Headed by Keyword list. There must be no space after list. Example: list(xbar = 22, N = 30, T = 5, x = c(8.0, 15.0, 22.0, 29.0, 36.0), Y = structure(.Data = c(151, 199, 246, 283, 320, 145, 199, 249, 293, 354,.......... 137, 180, 219, 258, 291, 153, 200, 244, 286, 324),.Dim = c(30,5) ) )

34 Data and Initial Values Files zFormatting of data (cont.) yS - plus format or rectangular format. xRectangular format Headed by array name. The array need to be of equal size. The array names must have explicit brackets. The first index position must be empty. Example: age[] sex[] 26 0 52 1.… Example of multi-dimensional arrays: Y[,1] Y[,2] Y[,3] Y[,4] Y[,5] 151 199 246 283 320 145 199 249 293 354....

35 Data and Initial Values Files zFormatting of data (cont.). yS - plus format or rectangular format. yThe whole data must be specified in the file --- it is not possible just to specify selected components. yMissing values are represented as NA. yAll variables in a data file must be defined in a model. yIt is possible to load a mixture of rectangular and S - plus format data for the same model. yInitial values are specified following the same rules.

36 Example --- Meta Analysis zProblem: Lau et al. (1992) y33 trials evaluated the use of intravenous streptokinase as thrombolyic therapy for myocardial infarction from 1959 to 1988. yTreatments: IV - SK vs. Placebo (Control). yData: No. of death out of total subjects for each group. yGoal: Access the efficacy of IV - SK.

37 Example --- Meta Analysis StudyMortality: deaths (r) / total(n) IV-SKPlacebo Fletcher1/124/11 Dewar4/217/21 European_120/8315/84 European_2 69/37394/357 Heikinheimo22/21917/207 Italian19/16418/157 Australian 1 26/26432/253 Frankfurt_213/10229/104 NHLBI_SMIT7/533/54 Frank6/556/53 Valere 11/499/42 Klein 4/141/9 UK_Collab38/30240/293 Austrian37/35265/376 Australian 225/12331/107 Lasierra1/133/11 N_gerCollab63/24951/234 StudyMortality: deaths (r) / total(n) IV-SKPlacebo Witchitz5/325/26 European_318/15630/159 ISAM54/85963/882 GissI-1628/5860758/5852 Olson1/282/24 Baroffio0/296/30 Schreiber1/193/19 Cribier1/211/23 Sainsous3/496/49 Durand3/354/29 White2/10712/112 Bassand4/527/55 Vlay1/132/12 Kennedy12/19117/177 ISIS-2791/85921029/8595 Wisenberg2/415/25

38 Example --- Meta Analysis zA full Bayes Model. yLogistic regression. yMeasure of efficacy: difference of log-odds ratios. yIt is reasonable to assume the treatment effects from each trial are similar but not exactly the same --- exchangeable. yExchangeability allows differences from study to study, but such that the differences are not expected a priori to have predictable effects favoring one study or another, Likelihood: Placebo: r i C ~ binomial (n i C, p i C ) IV - SK : r i T ~ binomial (n i T, p i T ) logit(p i C ) =  i logit(p i T ) =  i +  i xPrimary interest:  i.

39 Example --- Meta Analysis zA full Bayes Model(cont.). Priors --- exchangeability  i ~ normal (d,  )  i ~ normal (0, 1.0E-5) Hyper priors d ~ normal (0, 1.0E-6 )  ~ gamma(0.001, 0.001)  “non-informative” priors are given for the  's, d and . yBUGS requires that a full probability model is defined, and hence forces all priors to be proper. yNot standard non-informative priors which usually are improper.

40 Example --- Meta Analysis zLikelihood: r i C ~ binomial (n i C, p i C ) r i T ~ binomial (n i T, p i T ) logit(p i C ) =  i logit(p i T ) =  i +  i zPriors  i ~ normal (d,  )  i ~ normal (0, 1.0E-5) zHyper priors d ~ normal (0, 1.0E-6 )  ~ gamma(0.001, 0.001) model { for( i in 1 : NoTrial) { rc[i] ~ dbin(pc[i], nc[i]) rt[i] ~ dbin(pt[i], nt[i]) logit(pc[i]) <- mu[i] logit(pt[i]) <- mu[i] + delta[i] mu[i] ~ dnorm(0.0,1.0E-5) delta[i] ~ dnorm(d, tau) } d ~ dnorm(0.0,1.0E-6) tau ~ dgamma(0.001,0.001) sigma <- 1 / sqrt(tau) } z Specifying model in the BUGS language.

41 WinBUGS Demo zFile: SK1.odc (Appendix C) zCompound document --- nice interface yA file contains various types of information(formatted text, tables, plots, graphs etc) with special rectangular embedded regions or elements. yEach region could be manipulated by standard word- processing tools. xThe Attributes menu: changes the style, size, font and color of the selected text. xThe Text menu: changes the vertical offset of the selection. xWinBUGS does not provided detailed information about how to use these editing tools.

42 Running the Model in WinBUGS. zUnder the Model Menu yClick specification z check model: Highlight the word model in model statement and click the button “check model” to check the syntax of model.On the status line (lower left corner of screen) yModel is syntactically correct. Or yError information. z load data: Highlight list (S - plus format) or the first array name (rectangular format) and click button to load data. yData Loaded. yError information.

43 Running the Model in WinBUGS. zUnder the Model Menu yClick specification zNum of chains: Specify the number of chains to be simulated. yThe default number is one chain. yEnter the number of chains desired to be simulated. yMultiple chains are needed for convergence diagnostic. z compile: Click to Build the data structures needed to carry out Gibbs sampling. The model is checked for completeness and consistency with data. yModel Compiled. yError information.

44 Running the Model in WinBUGS. zUnder the Model Menu yClick specification zload inits: Click to load initial values of the nodes in the exactly same way as data. zgen inits: Generate initial values by sampling from the prior. zWhen specifying initial values, yIf some elements in an array are known, e.g. constraints in a parameterization, those elements are specified as missing (NA) in the initial value files. yInitial values for each chain should be well dispersed. yGenerally it is recommended to load initial values for all fixed effects model for all chains, initial values for random effects can be generated using the gen inits button. zStatus line information: yInitial values loaded: model contains uninitialized nodes --- try gen inits. yInitial values loaded: model initialized --- now model ready to update. yError information.

45 Running the Model in WinBUGS. zOnce the model has been compiled and initialized, it is ready to run MCMC to get samples from the posterior distribution. Under the Model Menu, yClick update yEnter the number of MCMC updates to be carried out in the updates field. yClick update button to start updating the model. y“burn in”: the first one thousand or more samples are discarded to get over the influence of initial values and get the transitional distribution converged to stationary distribution.

46 Running the Model in WinBUGS. zOther specifications about update. yrefresh: the number of updates between redrawing the screen. ythin: enter k in the field to store every k th iteration. No real advantage except reducing storage requirement for very long run. yover relax: In each iteration, generates multiple samples and selects one that is negatively correlated with the current one. xReduce within chain autocorrelation xnot always effective. yadapting: indicates the initial tuning of Metropolis or slice- sampling algorithm. The first 4000 and 500 are discarded respectively.

47 Bayesian Inference using WinBUGS zUnder the Inference Menu and click Samplings: yNodes: The variable of interest must be typed in this text field before updating to be monitored. x“ * “ serves as shorthand for all the stored samples. x“deviance”, minus twice of log-likelihood is automatically calculated for each iteration and can be monitored by typing in deviance. yset: click to finish the specification of interested variable.

48 Bayesian Inference using WinBUGS zUnder the Inference Menu and click Samplings: ybeg and end: select a subset of the stored samples for analysis. ychains and to: select chains for analysis. ythin: select every k th iteration of each chain for analysis. xThe sample for each chain are not independent. xThis dependence gets smaller when samples are getting further apart. xApproximately independent samples could be obtained by checking the autoC plot and looking for the appropriate lag. yClear: removes the stored values of the variable.

49 Bayesian Inference using WinBUGS --- the meta-analysis example zTrace: dynamic plot of the variable value against iteration number. Redrawn each time when the the screen is redrawn.

50 Bayesian Inference using WinBUGS --- the meta-analysis example zquantiles: plots the running mean with running 95% confidence interval (credible set) against iteration number.

51 Bayesian Inference using WinBUGS --- the meta-analysis example zHistory: complete trace of the variable

52 Bayesian Inference using WinBUGS --- the meta-analysis example zautoC: plots the autocorrelation function of the variable out to lag 50. yAutocorrelation plot for every 10th sample.

53 Bayesian Inference using WinBUGS --- the meta-analysis example zMore on autoC yThe autocorrelation coefficient could be listed to a window by double-clicking on the plot followed by ctrl- left-mouse-click. yHelps to determine the thinning number of a chain to get independent samples. Autocorrelation coefficient for d to lag 15 for 3 chains. 10.2887 0.30270.3102 20.1154 0.11810.1512 30.0398 0.071440.07887 40.0108 0.027850.06515 50.008905 0.02874 0.04598 60.009483 0.01345 0.04224 7-0.007061 0.02338 0.03699 89.585E-4 0.007169 0.03051 9-0.002919 -0.009028 0.02958 100.00248 0.006675 0.01267 110.004878 0.0084730.02488 12-0.003961 0.0068360.007014 13-0.001721 0.0048220.008959 140.002111 -0.004585 0.007996 15-0.002157 -0.008235 -0.01987

54 Bayesian Inference using WinBUGS --- the meta-analysis example zAutocorrelation coefficient for delta[1] to lag 15 for 3 chains. 10.07055 0.080140.1404 20.05591 0.056910.107 30.006094 0.025610.0576 40.01724 0.023990.04993 50.001357 0.021520.02343 6-0.008961 0.030440.03061 79.379E-4 -0.001046 -0.02419 8-3.373E-5 -0.01555-0.01727 9-0.00459 -0.005384 0.01298 100.005225 0.01231-0.01834 11-0.005177 0.01187-0.01388 12-5.76E-4 0.01402-0.01597 130.004723 -0.033540.03546 14-0.004878 -0.011390.0194 15-0.004111 -0.0138-0.02436 z Autocorrelation coefficient for sigma to lag 15 for 3 chains. 10.6678 0.6736 0.6885 20.4721 0.48260.488 30.3311 0.34350.3481 40.2239 0.24730.2696 50.1372 0.17850.2153 60.08719 0.13120.1657 70.0492 0.10410.1248 80.03393 0.084060.09259 90.02685 0.046740.06971 100.009531 0.023810.04974 11-0.002295 0.011760.03777 12-0.001109 0.014470.03434 130.02182 -0.025470.03265 140.02012 0.02873-0.04168 150.02329 0.02946-0.03077

55 Bayesian Inference using WinBUGS --- the meta-analysis example zautoC: Autocorrelation plot for every 50th sample for get more independent sample.

56 Bayesian Inference using WinBUGS --- the meta-analysis example zGR diag: Gelman-Rubin convergence statistic, as modified by Brooks and Gelman (1998). yGreen line: the width of the central 80% interval of the pooled runs. yBlue line: The average width of the 80% interval within the individual runs. yThe pooled and within interval widths are normalized to be less than 1 for plotting purpose. yRed line: the ratio of pooled/within (= R) calculated in bins of length 50. yConvergence diagnostic xR converges to 1. xBoth the pooled and within interval widths converge to stability.

57 Bayesian Inference using WinBUGS --- the meta-analysis example zGR diag: Gelman-Rubin convergence statistic.

58 Bayesian Inference using WinBUGS zcoda: dumps out an ASCII representation of the monitored values suitable for use in BOA (or CODA) S - plus diagnostic package. yOutput file for each chain:.out file yDescription of the.out file:.ind file zOr the data could be extracted and transformed into right format for any further desired analysis. zAfter checking autocorrlation and convergence, now it is ready to make inference:

59 Bayesian Inference using WinBUGS --- the meta-analysis example zStats: summary statistics for the variable, pooling over the chains selected. zSelected results of the IV-SK studies yEstimates are produced by a 15000 iterations burn in followed by further 40000 iterations with selecting every 50th sample pooling over 3 chains. node mean sd MC error 2.5%median97.5%startsample d -0.28510.058870.00141-0.4148-0.2807-0.1785150002100 sigma0.11380.080880.0018750.023740.08910.3281150002100 delta[1]-0.31250.15330.003321-0.6663-0.2942-0.05425150002100 delta[2]-0.30270.150.003294-0.6508-0.2878-0.03099150002100 delta[3]-0.21990.14330.003155-0.4538-0.24250.1471150002100 delta[4]-0.32830.11190.002649-0.5945-0.3132-0.1312150002100 delta[5]-0.21840.13450.00256-0.4335-0.23880.1209150002100 …………

60 Bayesian Inference using WinBUGS --- the meta-analysis example zdensity: plots a smoothed kernel density estimate for the variable if continuous and a histogram if discrete.

61 Bayesian Inference using WinBUGS zUse of log file yBy default WinBUGS opens a new window for each specie of output (stats, traces etc.). yAll output could be put into a single log file. To do this, xUnder the Options menu, choose use log. All output will be written into log file. xUnder the Info menu, choose open log to access the output.

62 Further Inference of the IV-SK Trials? zPredictive distribution of  in a new trial? zMean relative risk across all trials? zAny other function of parameters? Like log mean relative risk? z ------ Easy to implement in WinBUGS. model { for( i in 1 : NoTrial ) { rc[i] ~ dbin(pc[i], nc[i]) …… delta[i] ~ dnorm(d, tau) rrnum[i] <- exp(mu[i] + delta[i])/ (1+exp(mu[i] + delta[i])) rrdenom[i] <- exp(mu[i]) /(1+exp(mu[i])) rr[i] <- rrnum[i] / rrdenom[i] } …… sigma <- 1 / sqrt(tau) delta.new ~ dnorm(d, tau) Meanrr <- mean(rr[]) }

63 Graphical Modeling of Meta Analysis example zRectangular box: constant

64 Further Inference of the IV-SK Trials zHistory: time series of the samples.

65 Further Inference of the IV-SK Trials zCredible sets, autocorrelation (every 50 th sample) and convergence diagnostics

66 Further Inference of the IV-SK Trials z Summary Statistics: node mean sd MC error 2.5% median 97.5% start sample Meanrr 0.78830.035147.334E-4 0.7207 0.7883 0.8598 10000 2400 delta.new -0.28570.14820.00275 -0.6109-0.2812-0.007317 10000 2400

67 Compare with Frequentist results? zThree possibilities of classical approach: ythe studies are identical replications of each other xEstimate an overall treatment mean from the study yThe studies are completely unrelated xEstimate one treatment effect for each study. yThe studies are related to each other xRandom effects model --- meta analysis xAssume exchangeability but interest often focuses on the estimate of overall mean. zThe Bayesian approach: yUncertainty about the probable effect in a particular population where a study has not been performed might be more represented by inference for a new study effect, exchangeable from those for which studies have been performed, rather than for the over mean. yThe effect is predicted by delta.new.

68 Sensitivity Analysis zSensitivity analysis are often carried out to investigate how much impact on posterior inference within reasonable modification of priors.

69 Other features of WinBUGS zUnder Model menu yMonitor Metropolis: shows minimum, maximum and average acceptance rate of metropolis algorithm. ySave state: shows the current state of all the stochastic variables. ySeed: shows and changes the seed of random number generator. zUnder Inference menu yFit: looks at model fit, predicted value and residuals of longitudinal data. yCorrelation: scatter plots and correlation between monitored variables. ySummary: mean and standard deviation of variables. Simplified version of Samples. yRanks: shows the ranks of the simulated values in an array. zUnder Info menu yNode info: current value, sampling method, type of the node, etc. yComponents: displays all the components in use. zDoodle menu : graphical representation of the model.

70 BOA --- Bayesian Output Analysis zAvailable at: http://www.public-health.uiowa.edu/BOA. zModified version of CODA --- Convergence Diagnostic and Output Analysis. zA set of S-Plus functions which serves as an output processor for the WinBUGS(BUGS) software. zS - plus windows users could open BOA as an script file and run the file from the script window. zAnalysis could be done by using yMenu-Driven User Interface Or yCommand line (shown here).

71 BOA --- Bayesian Output Analysis zInput: MCMC output  BUGS output file:.out and.ind files. yFlat ASCII file yS Data matrix object zOutput: Statistics calculated from MCMC output and plots yStatistics: Descriptive and convergence diagnostics xDescriptive: autocorrelation, correlation matrix, summary statistics xConvergence diagnostics: Brooks, Gleman & Rubin (“bandg”) Geweke (“geweke”) Heidelberger & Welch (‘handw”) Raftery & Lewis (“randl”)

72 BOA --- Bayesian Output Analysis zOutput: Statistics calculated from MCMC output and plots yStatistics yPlots: Descriptive and convergence diagnostics xDescriptive: autocorrelation, density, running mean and trace xConvergence diagnostics: Brooks, Gleman & Rubin ; Geweke ; Heidelberger & Welch; Raftery & Lewis(“randl”) yThe descriptive information could be obtained from WinBUGS. zThere are options to manage data and change parameter specifications.

73 BOA: the IV - SK trials ------ More convergence diagnostics zTo show the diagnostic work of BOA, convergence was check for parameters d and sigma over three chains from the meta - analysis example of the IV - SK trials. z zWinBUGS output files: ysk1out1: sk1out1.out and sk1out1.ind ysk1out2: sk1out2.out and sk1out2.ind ysk1out3: sk1out3.out and sk1out3.ind ysk1out1.ind, sk1out2.ind, sk1out3.ind are the same index file produced by CODA in Samples of WinBUGS. Saved three times under three names to facilitate its use in BOA. zUsing of BOA through command line yCopy boa.s into the script file window and run the file. yStart BOA sessions with a call to boa.start().

74 BOA: the IV - SK trials ------ More convergence diagnostics zSk1_boa.ssc (Appendix D) zStart the BOA session. > boa.start() Bayesian Output Analysis Program (BOA) Version 0.99.1 for Windows S-PLUS Copyright (c) 2001 Brian J. Smith ………… yAt this point the global parameters have been assigned default values. zSpecify the path where the MCMC output is located. > boa.par(path = "C:\\Program Files\\WinBUGS13 \\rongwei's files\\",title = "IV-SK Trials")

75 BOA: the IV - SK trials ------ More convergence diagnostics zImport the three parallel chains generated by the IV - SK trials study. > boa.chain.import("sk1out1", type = "BUGS") [1] T > boa.chain.import("sk1out2", type = "BUGS") [1] T > boa.chain.import("sk1out3", type = "BUGS") [1] T zChange the support of sigma to (0, inf) from default values (-inf, inf). > boa.chain.support(pnames = "sigma", limits = c(0, Inf)) master work T T

76 BOA: the IV - SK trials ------ More convergence diagnostics zDisplay summary information about the input data --- data check. > boa.print.info() CHAIN SUMMARY INFORMATION: ========================== Iterations: +++++++++++ Min Max Sample sk1out1 1 10000 10000 sk1out2 1 10000 10000 sk1out3 1 10000 10000 Support: sk1out1 ---------------- d sigma Min -Inf 0 Max Inf Inf (Cont. from left) Support: sk1out2 ---------------- d sigma Min -Inf 0 Max Inf Inf Support: sk1out3 ---------------- d sigma Min -Inf 0 Max Inf Inf

77 BOA: the IV - SK trials ------ More convergence diagnostics zBrooks, Gelman & Rubin Convergence Diagnostic yThe diagnostic was originally proposed by Gelman and Rubin (1992). yAppropriate for the analysis of two or more parallel chains, each with different starting values which are overdispersed with respect to the target distribution. yBased on a comparison of the within and between chain variance for each variable to estimate the potential scale reduction factor (PSRF) which might be reduced if the chains were run to infinity. yBrooks and Gelman (1998) proposed the corrected scale reduction factor (CSRF) to adjust for the sampling variability in the variance estimates. yOnly the second half of the samples is used to compute the reduction factors.  If the estimates are approximately equal to one (or, as a rule of thumb, the 0.975 quantile is < 1.2), the samples may be considered to have arisen from the stationary distribution.

78 BOA: the IV - SK trials ------ More convergence diagnostics zBrooks, Gelman & Rubin Convergence Diagnostic yEstimate of PSRF --- very close to 1 and 97.5% quantile < 1.2. > boa.print.gandr() BROOKS, GELMAN AND RUBIN CONVERGENCE DIAGNOSTICS: =============================================== Iterations used = 5001:10000 Potential Scale Reduction Factors --------------------------------- d sigma 1.005053 1.001255 Multivariate Potential Scale Reduction Factor = 1.0048224 Corrected Scale Reduction Factors --------------------------------- Estimate 0.975 d 1.006186 1.019995 sigma 1.002439 1.006100

79 BOA: the IV - SK trials ------ More convergence diagnostics zBrooks, Gelman & Rubin Convergence Diagnostic yplots of CSRF > boa.plot("gandr") [1] T

80 BOA: the IV - SK trials ------ More convergence diagnostics zGeweke convergence diagnostic yThe diagnostic was proposed by Geweke (1992). yAppropriate for the analysis of individual chains when convergence of the mean of some function of the sampled parameters is of interest. yThe chain is divided into two "windows" containing a set fraction of the first and the last iterations. yA Z statistic was calculated to compare the means of the two “windows”. y As the number of iterations approaches infinity, the Z statistic approaches the N(0,1) if the chain has converged. yThere is evidence against convergence when the p-value is less than 0.05. Otherwise, the test does not provide any evidence against convergence. This does not, however, prove that the chain has converged.

81 BOA: the IV - SK trials ------ More convergence diagnostics zGeweke Convergence Diagnostic yEstimate of Z - statistic --- against convergence of mean > boa.print.geweke() GEWEKE CONVERGENCE DIAGNOSTIC: ============================= Fraction in first window = 0.1 Fraction in last window = 0.5 Chain: sk1out1 -------------- d sigma Z-Score -3.5375257704 4.26733872093 p-value 0.0004038948 0.00001978187

82 BOA: the IV - SK trials ------ More convergence diagnostics zGeweke Convergence Diagnostic yEstimate of Z - statistic --- against convergence, more runs ? > boa.print.geweke() (cont.) GEWEKE CONVERGENCE DIAGNOSTIC: ============================= Chain: sk1out2 -------------- d sigma Z-Score -1.73801549 3.9334628119 p-value 0.08220808 0.0000837308 Chain: sk1out3 -------------- d sigma Z-Score 0.7641664 -3.5127337258 p-value 0.4447681 0.0004435217

83 BOA: the IV - SK trials ------ More convergence diagnostics zGeweke Convergence Diagnostic yplots of Geweke Z statistics > boa.plot("gekewe") [1] T

84 BOA: the IV - SK trials ------ More convergence diagnostics zHeidelberger and Welch convergence diagnostic  The diagnostic was proposed by Heidelberger and Welch (1983). yAppropriate for the analysis of individual chains. yBased on Brownian bridge theory and uses the Cramer-von-Mises statistic. y If there is evidence of non-stationarity, the test is repeated after discarding the first 10% of the iterations and continues until the resulting chain passes the test or more than 50% of the iterations have been discarded. y BOA reports the number of iterations that were kept, the number of iterations that were discarded, and the Cramer-von-Mises statistic. Failure of the chain to pass this test indicates that a longer run of the MCMC sampler is needed in order to achieve convergence.

85 BOA: the IV - SK trials ------ More convergence diagnostics zHeidelberger and Welch convergence diagnostic (cont.) yA halfwidth test is performed on the portion of the chain that passes the stationarity test for each variable. ySpectral density estimation is used to compute the asymptotic standard error of the mean. yIf the half-width of the confidence interval for the mean is less than a specified fraction (accuracy) of this mean, the halfwidth test indicates that the mean is estimated with acceptable accuracy. y Failure of the halfwidth test implies that a longer run of the MCMC sampler is needed to increase the accuracy of the estimated posterior mean.

86 BOA: the IV - SK trials ------ More convergence diagnostics zHeidelberger and Welch Convergence Diagnostic yEstimate of diagnostic statistics > boa.print.handw() HEIDLEBERGER AND WELCH STATIONARITY AND INTERVAL HALFWIDTH TESTS: =================================================== Halfwidth test accuracy = 0.1 Chain: sk1out1 -------------- Stationarity Test Keep Discard C-von-M d passed 9000 1000 0.2703470 sigma passed 7000 3000 0.3615584 Halfwidth Test Mean Halfwidth d passed -0.2853485 0.004450549 sigma passed 0.1171427 0.007776577

87 BOA: the IV - SK trials ------ More convergence diagnostics zH eidelberger and Welch Convergence Diagnostic yEstimate of diagnostic statistics > boa.print.handw()(cont.) Chain: sk1out2 -------------- Stationarity Test Keep Discard C-von-M d passed 10000 0 0.07425641 sigma passed 10000 0 0.34860040 Halfwidth Test Mean Halfwidth d passed -0.2876464 0.004084248 sigma passed 0.1211367 0.007508664

88 BOA: the IV - SK trials ------ More convergence diagnostics zHeidelberger and Welch Convergence Diagnostic yEstimate of diagnostic statistics > boa.print.handw()(cont.) Chain: sk1out3 -------------- Stationarity Test Keep Discard C-von-M d passed 10000 0 0.4266263 sigma passed 5000 5000 0.1765119 Halfwidth Test Mean Halfwidth d passed -0.2878423 0.004138602 sigma passed 0.1247507 0.010573640

89 BOA: the IV - SK trials ------ More convergence diagnostics zRaftery and Lewis convergence diagnostic  was proposed by Raftery and Lewis (1992b). yAppropriate for the analysis of individual chains. yThe diagnostic tests for convergence to the stationary distribution and estimates the run-lengths needed to accurately estimate quantiles of functions of the parameters. yBOA computes the "lower bound" - the number of iterations needed to estimate the specified quantile to the desired accuracy using independent samples. yIf sufficient MCMC iterations are available, BOA lists the lower bound, the total number of iterations needed for each parameter, the number of initial iterations to discard as the burn-in set, and the thinning interval to be used. yThe dependence factor measures the multiplicative increase in the number of iterations needed to reach convergence due to within-chain correlation. yDependence factors greater than 5.0 often indicate convergence failure and a need to reparameterize the model (Raftery and Lewis, 1992a).

90 BOA: the IV - SK trials ------ More convergence diagnostics zRaftery and Lewis Convergence Diagnostic yEstimate of dependence factor --- against convergence > boa.print.randl() RAFTERY AND LEWIS CONVERGENCE DIAGNOSTIC: ========================================= Quantile = 0.025 Accuracy = +/- 0.005 Probability = 0.95 Chain: sk1out1 -------------- Thin Burn-in Total Lower Bound Dependence Factor d 7 21 32781 3746 8.750934 sigma 7 28 27083 3746 7.229845

91 BOA: the IV - SK trials ------ More convergence diagnostics zRaftery and Lewis Convergence Diagnostic yEstimate of dependence factor --- against convergence > boa.print.randl()(cont.) Chain: sk1out2 -------------- Thin Burn-in Total Lower Bound Dependence Factor d 6 18 24816 3746 6.624666 sigma 9 36 42363 3746 11.308863 Chain: sk1out3 -------------- Thin Burn-in Total Lower Bound Dependence Factor d 8 40 50600 3746 13.507742 sigma 10 30 28020 3746 7.479979

92 More BUGS Sources zWebsite of BUGS: for all information http://www.mrc-bsu.cam.ac.uk/bugs/winbugs/contents.shtml zTwo add add-ons: yPKBUGS xComplex population pharmacokinetic/pharmacodynamic (PK/PD) modeling xhttp://www.med.ic.ac.uk/divisions/60/pkbugs_web/home.html yGeoBUGS xa demonstrator version for epidemiological mapping studies xfits spatial models and produces a range of maps as output. xhttp://www.mrc-bsu.cam.ac.uk/bugs/winbugs/geobugs.shtml zBUGS on the web yFeatures examples of BUGS or WinBUGS in different disciplines. yhttp://www.mrc-bsu.cam.ac.uk/bugs/weblinks/webresource.shtml

93 Last reminder z I am the BUGS! z Hoped I had entertained you! z Last reminder: Beware - MCMC sampling can be dangerous in WinBUGS!

94 Selected Reference zBrooks, S.P. and Gelman A. 1998. General methods for monitoring convergence of iterative simulations. J. Comp. Graph. Statist. 7., 434-455. zGelman, A. and Rubin, D. B. (1992). Inference from iterative simulation using multiple sequences. Statistical Science, 7, 457-72. zGilks, W. R. (1992). Derivative-free adaptive rejection sampling for gibbs sampling. In Bayesian Statistics 4, (ed. J. M. Bernardo, J. O. Berger, A. P. Dawid, and A. F. M. Smith), pp. 169-94. Clarendon Press, Oxford, UK. zGeweke, J. (1992). Evaluating the accuracy of sampling-based approaches to calcualting posterior moments. In Bayesian Statistics 4, (ed. J. M. Bernardo, J. O. Berger, A. P. Dawid, and A. F. M. Smith). Clarendon Press, Oxford, UK. zHeidelberger, P. and Welch, P.D. 1983. Simulation run length control in the presence of an initial transient. Operations Research, 31, 1109-1144. zNeal, R.M. (1997). Markov chain Monte Carlo methods based on ‘slicing’ the density function. Technical Report No. 9722, Dept of Statistics, University of Toronto. zRaftery, A.E. and Lewis, S. 1992a? How many iterations is the Gibbs sampler? In Bayesian Statistics 4, J.M. Bernardo, J. O. Berger, A. P. Dawid, and A.F. M. Smith, eds., Oxford: Oxford University Press, pp.763-773.


Download ppt "An Introduction to WinBUGS and BOA. Outline zIntroduction zQuick review of Bayesian statistical analysis zThe WinBUGS language zConvergence diagnostics."

Similar presentations


Ads by Google