Home

User Manual for the Windows Matlab Version of BACC (Bayesian

image

Contents

1. mi txt 4 10 2 To From Binary Files To save a model instance called mi to a binary file called mi bin use the command miSave mi mi bin To load a model instance stored in a binary file called mi bin and to give it the name mi use the command mi miLoad mi bin 4 11 Drawing from Various Distributions The following code demonstrates how to draw from various distributions See Appendix A for the parameterization of these distributions 4 11 1 Dirichlet a 1 2 3 4 5 6 setSeedConstant sample dirichletSim a 1000 disp dirichlet mean disp sum sample 1000 4 11 2 Gamma setSeedConstant sample gammaSim 3 5 1000 disp gamma mean disp sum sample 1000 84 CHAPTER 4 A BACC TUTORIAL 4 11 3 Gaussian Multivariate Normal mean 1 2 precision 1 0 0 1 setSeedConstant sample gaussianSim mean precision 1000 disp gaussian mean disp sum sample 1000 4 11 4 Pareto setSeedConstant sample paretoSim 3 5 1000 disp pareto mean disp sum sample 1000 4 11 5 Wishart Multivariate Chi squared scale precision setSeedConstant sample wishartSim scale 10 1000 disp wishart mean disp sum sample 1000 Appendix A Distributions This appendix gives the density and mass functions for the distributions used in this docu ment A 1 The Dirichlet Distribution A random vector 7 of length n has the Dirichlet distribution with parameter vecto
2. TO 77 9 Wii P G PS TP Ta PO a 18 CHAPTER 2 MODELS 2 5 The Non Stationary First Order Markov Finite State Model 2 5 1 Dimension parameters There are m states N individuals and T observation times 2 5 2 Unknown Quantities Unknown Parameters There is a 1 x m initial state probability vector 7 and an m x m Markov transition probability matrix P 2 5 3 Known Quantities Prior Parameters The prior parameters are a 1 x m vector o indexing the prior distribution of 7 and an m x m matrix a indexing the prior distribution of P Data There are state observations si 1 m for each individual i and each observation time f 11 SIN S ST STN 2 5 4 Data Generating Process The N observation sequences s _ are i i d with each sequence being first order Markov The initial distribution is 7 and the Markov transition matrix is P Pr si s 275 8 231 m Prisa 4551 2 8 Pia 2 5 5 Priors The m rows P of P and are mutually independent and have the following marginal distributions 7 Di ao P Pa Poem Dilg s 1 m ao av e Qom 2 5 THE NON STATIONARY FIRST ORDER MARKOV FINITE STATE MODEL 19 a oy wan Q s 1 m sm LEDS 2 5 6 Creating a Model Instance The mnemonic label identifying the model is nsfomfs Supply the names you wish to give the unknown quantities in the following order first the name of v pi for example and then the name of
3. The prior for is obtained by truncating the following density to the region for which y is stationary N H5 Sampling Algorithm The sampling algorithm for prior simulation features three blocks each making independent draws from the prior distribution of one of the unknown quantities The sampling algorithm for posterior simulation features three blocks each making draws from the conditional pos terior distribution of one of the unknown quantities 2 17 AN AUTOREGRESSION MODEL WITH STATE DEPENDANT MEANS 41 2 17 An Autoregression Model with State Dependant Means The mnemonic label identifying the model is Hamilton Dimension Parameters T number of observations number of covariates autoregressive order 3 Ww m number of states Unknown Quantities y m K x1 vertical stack of alpha and beta h 1x 1 residual precision o p x 1 vector of autoregression coefficients P m x m state transition probability matrix S T x 1 latent states f T x m filter probabilities Known Quantities 7 m K x 1 prior mean of y H m K x m K prior precision of y D 1x1 prior degrees of freedom of h g 1 x 1 prior inverse scale of h p x 1 prior mean of before truncation Hg p x p prior precision of before truncation A m x m parameters of prior for P X T x K covariates y T x 1 dependant variable Data Generating Process The data generating process is given by yt Os Bar
4. hu u 2 Prior Distribution The vectors 8 h are mutually independant The covariate coefficient vector has distribu tion N 8 Hg p B 21 K H 5 exp 8 8 H4 8 B 2 28 CHAPTER 2 MODELS The precision parameter h has a scaled chi squared distribution with s h v p h 2 P T v 2 8 Ph exp s h 2 Sampling Algorithm See Example 3 4 1 in Contemporary Bayesian Econometrics and Statistics by John Geweke at http www cirano qc ca bacc bacc2003 resources html 2 11 A UNIVARIATE LINEAR MODEL WITH STUDENT T DISTURBANCES 29 2 11 A Univariate Linear Model with Student t Distur bances The mnemonic label identifying the model is t_ulm Dimension Parameters T number of observations K number of covariates Unknown Quantities K x1 vector of covariate coefficients B h 1x1 precision of Student t distribution h Tx1 time varying latent precision variable A 1x1 degrees of freedom of Student t distribution Known Quantities B Kx1 prior mean of 8 H KxK prior precision of 8 s 1x1 prior inverse scale of h V 1x1 prior degrees of freedom of h A 1x1 prior mean of A X TxK covariates y Tx1 dependant variable Data Generating Process The observables y are given by y XP u where uisa Tx 1 vector of independant Student t disturbances with u h X t 0 HERA Conditioning on the latent h gives u h h N 0 hh 1 g p ulX B h h 22 7
5. B Kx1 prior mean of 8 H KxK prior precision of 8 A 1x1 prior mean of A X TxkK covariates y Tx1 dependant variable Data Generating Process y isa T x 1 vector with fo s e 0o 0 i 5 0 00 uis aT x 1 vector of i d normal disturbances with u h N 0 h7 p u X 8 h 21 1 hT exp hu u 2 Prior Distribution The covariate coefficient vector has distribution N B H a p B 2 EP H 1 exp 8 BY H4 8 B 2 32 CHAPTER 2 MODELS Sampling Algorithm See Example 3 4 1 in Contemporary Bayesian Econometrics and Statistics by John Geweke at http www cirano qc ca bacc bacc2003 resources html 2 13 A UNIVARIATE CENSORED REGRESSION MODEL WITH STUDENT T DISTURBANCES33 2 13 A Univariate Censored Regression Model with Stu dent t Disturbances The mnemonic label identifying the model is t censor Dimension Parameters T number of observations K number of covariates Unknown Quantities B K x1 vector of covariate coefficients h 1x1 precision of student t distribution h Tx1 time varying latent precision variable A 1x1 degrees of freedom of Student t distribution y Tx1 normal latent variables Known Quantities B Kx1 prior mean of 8 Hg KxK prior precision of 8 s 1x1 prior inverse scale of h v 1x1 prior degrees of freedom of h A 1x1 prior mean of A yo 1x1 censoring threshold X TxkK covariates y Tx1 dependant variable
6. d T x1 upper bound of observed interval Data Generating Process y isa T x 1 vector with fo s 00 0 971i ge 0 00 uisa T x 1 vector of ii d normal disturbances with u h N 0 h 1 p u X B h 21 T 2 amp 7 exp hu u 2 36 CHAPTER 2 MODELS Prior Distribution The vectors h are mutually independant The covariate coefficient vector P has distribu tion N 8 Hg p B 20 H4 exp 8 B H 4 8 8 2 The precision parameter h has a scaled chi squared distribution with s h v p h 22PT 1 2 8 Ph exp s h 2 Sampling Algorithm See Example 3 4 1 in Contemporary Bayesian Econometrics and Statistics by John Geweke at http www cirano qc ca bacc bacc2003 resources html 2 15 A UNIVARIATE LINEAR MODEL WITH FINITE MIXTURES OF NORMALS DISTURBANCES37 2 15 A Univariate Linear Model with Finite Mixtures of Normals Disturbances The mnemonic label identifying the model is fmn ulm Dimension Parameters T number of observations K number of covariates m number of mixture components or states Unknown Quantities y m Kx1 vector of state means and covariate coefficients h 1x 1 constant multiplicative precision component h m x 1 state dependant multiplicative precision component 5 T x 1 time varying latent discrete state T 1x m state probabilities Known Quantities ha 1x1 prior precision parameter for state means B Kx1 prior mean of cova
7. n Integer number of draws to generate Outputs sample n by m matrix sample generated from Wishart distribution See Also paretoSim gaussianSim gammaSim dirichletSim Example A 1 0 0 0 0 0 1 0 nu 100 sample wishartSim A nu 1000 Details Each of the n draws of the sample is an m by m matrix with a Wishart distri bution The result is given as a m by m matrix See Appendix A for the parametrization of the Wishart distribution Chapter 4 A BACC Tutorial In order to answer commonly asked questions this chapter contains a step by step tutorial with explanations of what each step is doing and what each term means 77 78 CHAPTER 4 A BACC TUTORIAL 4 1 Loading Known Quantities To begin using BACC you first need to specify the known quantities These quantities can be entered directly into Matlab loaded from a Matlab file or loaded from a text file The next lines load the prior matrices and data matrices for the normal linear model The files for this example are in the test directory contained in the BACC zipfile for Matlab users load betahd mtx load Hhd mtx load nuhd mtx load shd mtx load Xhd mtx load yhd mtx 4 2 Creating a Model Instance Next a model instance is created A model instance can be though of as a box containing everying that BACC needs to know about a particular model This includes the type of the model i e normal linear model a list of names for the knowns and
8. 0 0 0 d T TO 4 IND 3 8 DETAILED DESCRIPTION OF COMMANDS 51 3 3 4 The extract Command Description Returns simulation matrices for a model instance Usage sim extract modelInst Inputs modelInst Integer model instance identifier Outputs sim Structure simulation matrices Example sim extract mi Details The return value is a structure named list in S PLUS and R with the following fields components in S PLUS and R id Model instance identifier logWeightPost Log weights for posterior draws logPrior Value of log prior for posterior draws logXPrior Value of transformed log prior values for posterior draws logLike Value of log likelihood for posterior draws logPriorHM Value of log prior for posterior HM draws logLikeHM Value of log likelihood for posterior HM draws logWeightPrior Log weights for prior draws logPriorPrior Value of log prior for prior draws logLikePrior Value of log likelihood for prior draws Posterior simulation matrix of unknown quantity named Prior Prior simulation matrix of unknown quantity named HM Posterior HM simulation matrix of unknown quantity named All simulation matrices have three dimensions The first two dimensions give the row and column of the unknown quantity The third dimension is the simulation dimension Each value of the third index gives a different draw of the unknown quantity 52 CHAPTER 3 BACC COMMANDS 3 3 5 The gammaSim Command
9. 1 TT h exp h ru 2 t 1 See Section 4 8 in Contemporary Bayesian Econometrics and Statistics by John Geweke at http www cirano qc ca bacc bacc2003 resources html for details 30 CHAPTER 2 MODELS Prior Distribution The vectors 3 h and h A together with X are mutually independant The covariate coefficient vector 3 has distribution N 8 H 5 p B 21 H4 exp 8 B H 4 8 8 2 The precision parameter h has a scaled chi squared distribution with s h v p h 274 T yJ2 8 PRE exp s7h 2 The time varying latent precision parameters h are iid scaled chi squared variates with Ali x2 A F p r 2 FAP TT AP exp Ah 2 t 1 The degrees of freedom parameter A is distributed exp A p A A exp A A Sampling Algorithm See Section 4 8 in Contemporary Bayesian Econometrics and Statistics by John Geweke at http www cirano qc ca bacc bacc2003 resources html 2 12 A UNIVARIATE DICHOTOMOUS CHOICE MODEL WITH STUDENT T DISTURBANCES31 2 12 A Univariate Dichotomous Choice Model with Stu dent t Disturbances The mnemonic label identifying the model is t dichot Dimension Parameters T number of observations K number of covariates Unknown Quantities B K x1 vector of covariate coefficients h Tx1 time varying latent precision variable A 1x1 degrees of freedom of Student t distribution y Tx1 normal latent variables Known Quantities
10. 6 4 Data Generating Process The N observation sequences s4 7 are i i d with each sequence being first order Markov with transition matrix P The initial distribution vector is assumed to be the invariant distribution 7 for P Pr si S Ts s 1 m Prisa s st 1 8 Pss where 7 is the left eigenvector of P corresponding to the eigenvalue 1 2 6 5 Priors The m rows P of P are mutually independent and have the following marginal distributions P Pais Pega DIA Sm 2 6 THE STATIONARY FIRST ORDER MARKOV FINITE STATE MODEL 21 2 6 6 Creating a Model Instance The mnemonic label identifying the model is sfomfs Supply the name you wish to give the unknown quantity P Supply the known quantities in the following order a S 2 6 7 Sampling Algorithms Generating Prior Draws Samples from the prior distribution of P are generated independently Generating Posterior Draws In this model an independance Metropolis Hastings chain is used to draw from the posterior distribution for P The distribution P S of candidate draws is PS Di Gs s 1 m where Q at n Qs Qs1 Asm M11 Nim n a Nml ps Nmm where nss is the number of transitions from state s to state s in the data The Hastings ratio for this block is given by N Ir ici Su 22 2 7 A Univariate Linear Model with bances The mnemonic label identifying the model is n ulm Dimension Parameters T number of observat
11. COMMANDS 61 3 3 14 The minst Command Description Creates an instance of a particular model specification Usage modellnst minst modelSpecName unknownNames knowns Inputs modelSpecName String name of model specification unknownNames List of strings separated by commas user provided names for unknown quantities knowns List of matrices separated by commas user provided matrices of known quantities Outputs modelInst Integer model instance identifier Example a 1 1 2 s 1 1 2 3 3 3 myMI minst iidfs pi a s Details The available model specifications are described in Chapter 2 For each model specification there is a section Creating a Model Instance with the relevant information namely e The name of the model specification e The order in which the user specifies the names for the unknown quantities of the model e The order in which the user provides the matrices giving the values of the known quantities of the model 62 CHAPTER 3 BACC COMMANDS 3 3 15 The mlike Command Description Computes various estimates of the marginal likelihood for a model instance with numerical standard errors Usage m1 mlnse mlike modelInst m1 mlnse mlike modelInst p taper Inputs modelInst Integer model instance identifier p Vector of length L truncation parameters optional taper Vector of length K taper half widths optional Outputs ml Vector of
12. DISTRIBUTION 87 The mean and variance are given by E a A A Var x A A A 6 The Wishart Distribution An m x m random matrix H has the Wishart distribution with positive definite m x m scale parameter matrix A and degrees of freedom parameter v gt m denoted H Wi A v if its probability density function is goto e ens v m 1 2 1 zi p H A v EAS a 0 otherwise The mean and mean of the matrix H are given by E H A v vA 1 Ao v m 1 E H A v 88 APPENDIX A DISTRIBUTIONS Bibliography DeRobertis L and J A Hartigan 1981 Bayesian Inference Using Intervals of Mea sures The Annals of Statistics 9 235 244 Gelfand A E and D K Dey 1994 Bayesian Model Choice Asymptotics and Exact Calculations Journal of the Royal Statistical Society Series B 56 501 514 Geweke J 1989 Bayesian Inference in Econometric Models Using Monte Carlo In tegration Econometrica 57 1317 1340 Geweke J 1992 Evaluating the Accuracy of Sampling Based Approaches to the Cal culation of Posterior Moments in J O Berger J M Bernardo A P Dawid and A F M Smith eds Proceedings of the Fourth Valencia International Meeting on Bayesian Statistics 169 194 Oxford Oxford University Press Geweke J 1999 Simulation Based Bayesian Inference for Economic Time Series in R S Mariano T Schuermann and M Weeks eds Simulation Based Inference in Econometrics Methods and Appli
13. Data Generating Process y isa T x 1 vector with fo s 00 0 971i ge 0 00 uisa T x 1 vector of ii d normal disturbances with u h N 0 h p u X B h 21 T 2 amp 7 exp hu u 2 34 CHAPTER 2 MODELS Prior Distribution The vectors h are mutually independant The covariate coefficient vector P has distribu tion N 8 Hg p B 20 H4 exp 8 B H 4 8 8 2 The precision parameter h has a scaled chi squared distribution with s h v p h 22PT 1 2 8 Ph exp s h 2 Sampling Algorithm See Example 3 4 1 in Contemporary Bayesian Econometrics and Statistics by John Geweke at http www cirano qc ca bacc bacc2003 resources html 2 14 A UNIVARIATE OBSERVED SET MODEL WITH STUDENT T DISTURBANCES35 2 14 A Univariate Observed Set Model with Student t Disturbances The mnemonic label identifying the model is t set Dimension Parameters T number of observations K number of covariates Unknown Quantities B KK x1 vector of covariate coefficients h 1x1 precision of Student t distribution h Tx1 time varying latent precision variable A 1x1 degrees of freedom of Student t distribution y Tx1 normal latent variables Known Quantities B Kx1 prior mean of 8 H KxK prior precision of 8 s 1x1 prior inverse scale of h v 1x1 prior degrees of freedom of h A 1x1 prior mean of A X TxK covariates T x1 lower bound of observed interval
14. Description Generates a sample from a gamma distribution Usage sample gammaSim alpha beta n Inputs alpha Real scalar shape parameter of gamma distribution beta Real scalar inverse scale parameter of gamma distribution n Integer number of draws to generate Outputs sample n by 1 matrix sample generated from gamma distribution See Also paretoSim gaussianSim dirichletSim wishartSin Example alpha 3 0 beta 5 0 sample gammaSim alpha beta 1000 Details Each of the n draws of the sample is a scalar with a gamma distribution The result is given as a n by 1 matrix See Appendix A for the parametrization of the gamma distribution 3 8 DETAILED DESCRIPTION OF COMMANDS 53 3 3 6 The gaussianSim Command Description Generates a sample from a Gaussian distribution Usage sample gaussianSim mean precision n Inputs mean Vector of length K mean of Gaussian distribution precision K by K matrix precision of Gaussian distribution n Integer number of draws to generate Outputs sample n by K matrix sample generated from Gaussian distribution See Also paretoSim dirichletSim gammaSim wishartSim Example mean 1 0 2 0 precision 1 0 0 0 0 0 1 0 sample gaussianSim mean precision 1000 Details Each of the n draws of the sample is a vector of length K with a Gaussian distribution The result is given as a n by K matrix See Appendix A for the parametrization of the G
15. P Supply the known quantities in the following order ap a S 2 5 7 Sampling Algorithms Generating Prior Samples Samples from the prior distributions of 7 and P are generated independently Generating Posterior Samples In the posterior distribution 7 P S the parameters 7 and P are conditionally independent and their marginal posterior distributions are the following familiar distributions n S Di ao Ps S Di s s l am where Qo Q9 no a a n as Qs1 Asm no Nor NOm ni Nim n Nml Tomum where no is the number of individuals starting in state s and nss is the number of transi tions from state s to state s in the data Posterior samples are drawn independently from this distribution 2 5 8 Marginal Likelihood The marginal likelihood is available in closed form P4094 MES 1 I aos di Ja 1 Ass d TS 1 Iss PS TI T as TS oe ees II a POT m s 1 20 CHAPTER 2 MODELS 2 6 The Stationary First Order Markov Finite State Model 2 6 1 Dimension parameters There are m states N individuals and T observation times 2 6 2 Unknown Quantities Unknown Parameters There is an m x m Markov transition probability matrix P 2 6 3 Known Quantities Prior Parameters The prior parameter is an m x m matrix q indexing the prior distribution of P Data There are state observations sy 1 m for each individual and each observation time t 11 SIN S STi STN 2
16. length L marginal likelihood estimates mlnse L by K 1 matrix numerical standared error estimates See Also postsim postsimHM Example Use default truncation and taper values nl m1NSE m1HM mlNSEHM mlike mi 4 Use alternate truncation values p 0 1 0 3 0 5 0 7 0 9 m1 m1NSE mlHM mlNSEHM mlike mi p 4 Use alternate truncation and taper values taper 4 0 8 0 m1 m1NSE mlHM mlNSEHM mlike mi p taper Details The method used is a modification described in Geweke 5 of the method pro posed in Gelfand and Dey Pl 3 8 DETAILED DESCRIPTION OF COMMANDS 63 The truncation parameters p 0 1 index the truncated multivariate normal distribution f discussed in Geweke 5 For each p mlike generates inter nally an unweighted vector 21 21 where M is the number of posterior samples in the given model instance For each l mlike calculates the sample mean z and numerical standard errors 91 71 from 21 z4r and A1 Ax in the same way that expect calculates To TK from 21 2u a vector of equal log weights and A1 Ax Then for all Z the estimate of the log marginal likelihood is given by pa log and for all l and k the estimate of the numerical standard error for the log marginal likelihood is given by When numerical standard error is small results are not sensitive to the choice of p In these cases L 1 and p 0 5 will suffice
17. length n exact upper bounds Vector of length n exact lower bounds Ut Vector of length n asymptotic upper bounds Lt Vector of length n asymptotic lower bounds Example K 5 0 10 0 20 0 mean std U L Ut Lt priorRobust lw beta K Details For each bound factor calculates exact lower and upper bounds and asymptotic lower and upper bounds for the posterior mean For each bound parameter ki priorRobust calculates exact lower and upper bounds L and U for the posterior mean of the function of interest g for the following set of prior density kernels to p 0 p 8 lt kip 0 VO o where p is the actual prior density Tt uses the algorithm described in Geweke and Petrella 6 Also for each k priorRobust calculates asymptotically valid 3 83 DETAILED DESCRIPTION OF COMMANDS lower and upper bounds L and using the results of DeRobertis and Hartigan 0 69 70 CHAPTER 3 BACC COMMANDS 3 3 21 The priorfilter Command Description Filters out previously generated draws from the prior simulation matrix of a given model instance Usage priorfilter modelInst filter Inputs modelInst Integer model instance identifier filter Vector of integers of length n indices of existing draws to keep Outputs None Example filter 101 1000 priorfilter mi filter Details The ith draw of the prior simulation matrix is kept if and only if i f for some j from 1 to n 3
18. of Ktype Ktype K uniform K t I n Xt 1 1 LS txen triangle K t I B om I For any set S the function xs is a set membership indicator function The value h is given by h Xqa q3 where qa denotes the a th sample quantile of z The weightedSmooth command generates N ordered pairs xi yi The values x are evenly spaced between min and max determined by Krange according to Table B2 The values y satisfy y f x Table 3 2 Values of Krange Krange Erin Tmar quantile Qai Qa absolute Q1 a2 For most plotting routines N should be in the range of 200 to 400 The choice of A depends on how smooth the resulting plot is desired to be As with all kernel smoothing methods some experimentation will probably be necessary The greater the number of simulations available the smaller A can be and still retain visual smoothness It is generally easier to use the Krange quantile option and specify a in the range 001 to 01 and az in the range 99 to 999 this will include the important part of the estimated density while not wasting space on the plot for points where the density is small 76 CHAPTER 3 BACC COMMANDS 3 3 26 The wishartSim Command Description Generates a sample from a Wishart distribution Usage sample wishartSim A nu n Inputs A m by m matrix inverse scale parameter of Wishart distribution nu Real scalar degrees of freedom parameter of Wishart distribu tion
19. 8 DETAILED DESCRIPTION OF COMMANDS 71 3 3 22 The priorsim Command Description Generates or appends to the prior simulation matrix of a given model instance Usage priorsim modelInst m n Inputs modelInst Integer model instance identifier m Integer number of prior draws to record n Integer number of prior draws to generate for each one recorded Outputs None See Also minst priorfilter postsim extract Example priorsim mi 1000 1 Details Generates draws of unknown quantities from their prior distribution Generates mn new prior draws and appends every nth draw to the prior simulation matrix If there are any draws from a previous invocation of priorsim the first new draw comes from the transition kernel of the Markov chain used for prior simulation Otherwise it comes from the initial distribution of the Markov chain Use the extract command to obtain the prior draws 72 CHAPTER 3 BACC COMMANDS 3 3 23 The setseedconstant Command Description Sets the seeds of the random number generators to a constant value Usage setseedconstant Inputs None Outputs None See Also setseedtime Example setseedconstant Details This is useful for ensuring that repeated invocations of a command generating random values lead to the same results 3 8 DETAILED DESCRIPTION OF COMMANDS 3 3 24 The setseedtime Command Description Sets the seeds of the random number generators t
20. CC Matlab directory to the Matlab path Choose Set Path from the File menu in Matlab and add the directory to the path Change the Matlab working directory to C NBACC Matlab Install BACC using the command installBACC The Windows Matlab version of BACC is now installed Follow these steps to run the sample program testBACC m 1 2 3 Start Matlab In Matlab change directory to the Test directory gt gt cd C BACC_Matlab Test Run the test program gt gt testBACC Chapter 2 Models 2 1 Introduction This document specifies the models currently supported by the BACC system Each sec tion following this one describes one of the supported models Each model description is organized into subsections following the pattern of this section Appendix A gives the probability density and mass functions of the distributions used throughout the document 2 1 1 Dimension parameters All the quantities relevant to a model are treated as matrix valued All matrix sizes are specified in terms of these dimension parameters Examples of dimension parameters include the number of times a variable is observed the number of individuals in a cross section and the number of equations in a linear model This subsection lists and describes the dimension parameters for a particular model 2 1 2 Unknown Quantities Unknown quantities are all the unobserved elements in a model They include unknown parameters of t
21. However the additional compu tational burden of increasing L is negligible If you are concerned about standard errors it is best to use several values of p for example p 0 1 0 2 0 9 64 CHAPTER 3 BACC COMMANDS 3 3 16 The paretoSim Command Description Generates a sample from a Pareto distribution Usage sample paretoSim alpha beta n Inputs alpha Real scalar tail parameter of Pareto distribution beta Real scalar location parameter of Pareto distribution n Integer number of draws to generate Outputs sample n by 1 matrix sample generated from Pareto distribution See Also dirichletSim gaussianSim gammaSim wishartSim Example alpha 1 0 beta 4 0 sample gammaSim alpha beta 1000 Details Each of the n draws of the sample is a scalar with a pareto distribution The result is given as a n by 1 matrix See Appendix A for the parametrization of the Pareto distribution 3 8 DETAILED DESCRIPTION OF COMMANDS 65 3 3 17 The postfilter Command Description Filters out previously generated draws from the posterior simulation matrix of a given model instance Usage postfilter modelInst filter Inputs modelInst Integer model instance identifier filter Vector of integers of length n indices of existing draws to keep Outputs None Example filter 101 1000 postfilter mi filter Details The ith draw of the posterior simulation matrix is kept if and only
22. Matlab Isue o a a BOS ee ete aa th OS ee ECEDEDSNE A 44 a od a aes 44 3 3 1 The dirichletSim Command lll sn 45 Riu daba dd e a aos UN eU 46 ia a Ea ad 49 A ene ee ae eee 51 3 3 5 The gammaSim Command ee ee 52 3 3 6 The gaussianSimCommand 53 3 3 7 The listModelSpecs Command 54 3 3 8 The listModels Command 55 3 3 9 ThemiDelete Command 0 00002 ee ee eee 56 3 3 10 The mi Load Command s ou x Xe Sok e eee A x m e 57 3 3 11 The miLoadAscii Command 58 3 3 12 ThemiSave Command 59 CONTENTS 7 3 3 13 The miSaveAscii Command 60 3 3 14 The minst Command 61 e eee BE Oe A ped Eu ee 62 oe ge ates ok eee ees 64 T 65 VT 66 lc xoc ucc eus d tase eos EUR 67 3 320 The priorRobust Command 222 RR 68 3 3 21 The priorfilter Command 70 3 3 22 The priorsimCommand eee 11 3 3 23 The setseedconstant Commandl rsen 72 3 3 24 The setseedtime Command 73 3 3 25 The weightedSmooth Command 74 3 3 26 The wishartSim Command 000002 eee 76 4 A BACC Tutoria 41 Loading Known Quantities 4 10 TE To From Text Files 4 10 2 To From Binar Eile Bibl
23. User Manual for the Windows Matlab Version of BACC Bayesian Analysis Computation and Communication William McCausland John J Stevens June 28 2007 Important Information About this Manual This manual describes the software developed in connection with the project Bayesian Com munication in the Social Sciences Siddhartha Chib and John Geweke principle investigators Acknowledgement in any resulting published work would be appreciated This project was supported in part by Grants SBR 9600040 and SBR 9731037 from the National Science Foundation Help Keep This Software Free The National Science Foundation supports this software and its continued development It is important that we document the use of BACC We respectfully request that all publications and working papers reporting the results of research using BACC software include the following acknowledgement and reference Computations reported in this paper were undertaken in part using the Bayesian Analysis Computation and Communication software http www cirano qc ca bacc described in Geweke J 1999 Using Simulation Methods for Bayesian Econo metric Models Inference Development and Communication with discussion and rejoinder Econometric Reviews 18 1 126 BACC Software and Documentation BACC software and documentation is available on the web at http www cirano qc ca bacc Please send any comments or questions to bacc econ umn edu Content
24. aussian distribution 54 CHAPTER 3 BACC COMMANDS 3 3 7 The listModelSpecs Command Description Lists all available model specifications e g nlm poisson Usage listModelSpecs Inputs None Outputs None See Also minst listModels Example listModelSpecs Details A printed message gives a list of model specifications 3 8 DETAILED DESCRIPTION OF COMMANDS 3 3 8 The listModels Command Description Lists all open model instances Usage listModels Inputs None Outputs None See Also minst miDelete listModelSpecs Example listModels Details A printed message gives the model instance identification number the name of the model specification e g nlm poisson and the number of prior posterior and posterior HM draws 56 CHAPTER 3 BACC COMMANDS 3 3 9 The miDelete Command Description Closes without saving a or all model instances Usage miDelete modelInst Inputs modelInst Integer model instance identifier Outputs None See Also minst listModels Example miDelete mi 3 8 DETAILED DESCRIPTION OF COMMANDS 3 3 10 The miLoad Command Description Loads a model instance stored in a binary file Usage modelInst miLoad filename Inputs filename String name of binary file storing the model instance Outputs modelInst Integer model instance identifier See Also miSave minst miLoadAscii Example mi m
25. cations Cambridge Cambridge University Press forthcoming Geweke J and L Petrella 1999 Prior Density Ratio Class Robustness in Economet rics Journal of Business and Economic Statistics forthcoming Raftery A E 1995 Hypothesis testing and model selection via posterior simulation University of Washington working paper 89
26. e 42 CHAPTER 2 MODELS where z is the t th row of X as a column vector and a m x 1 and 8 K x 1 are obtained by partitioning y p t gt QiEt i Ut i l and uz ii d N 0 h7 Prior Distribution The unknowns are a priori independent and have the following distributions al y NH 8h x v The prior for is obtained by truncating the following density to the region for which y is stationary mu N H5 Pa Pim iid Di Aa Aim Pr s jlr i Pj The unknown quantity f gives for each observation time t the state probabilities at t given previous states previous values of the observed variables and the other unknown quantities It is not a primitive unknown quantity and it is included to give the user access to filtered probabilities Sampling Algorithm The sampling algorithm for prior simulation features five blocks Four blocks make indepen dent draws from the prior distributions of y h and P The fifth makes draws from the distribution s P The sampling algorithm for posterior simulation features five blocks each making draws from the conditional posterior distribution of one of the unknown quantities Chapter 3 BACC Commands 3 1 Overview of BACC Commands The following is a list of BACC commands with brief descriptions dirichletSim expecti expectN extract gammaSim gaussianSim listModelSpecs listModels miDelete miLoad miLoadAscii miSave
27. ent variables Known Quantities B Kx1 prior mean of 8 H Kx K prior precision of 3 X TxK covariates y Tx1 dependant variable Data Generating Process y isa T x 1 vector with fo je 00 0 971i ge 0 00 uis a T x 1 vector of i d normal disturbances with u h N 0 h7 p u X B h 27m T2 kTP exp hu u 2 Prior Distribution The covariate coefficient vector P has distribution N 8 H 5 p B 27 EH gl exp 8 B EplB 8 2 Sampling Algorithm See Example 3 4 1 in Contemporary Bayesian Econometrics and Statistics by John Geweke at http ww cirano qc ca bacc bacc2003 resources html 2 9 A UNIVARIATE CENSORED REGRESSION MODEL WITH NORMAL DISTURBANCES25 2 9 A Univariate Censored Regression Model with Nor mal Disturbances The mnemonic label identifying the model is n censor Dimension Parameters T number of observations K number of covariates Unknown Quantities B KK x1 vector of covariate coefficients h 1x1 precision of student t distribution y Tx1 normal latent variables Known Quantities B Kx1 prior mean of 8 Hg KxK prior precision of 8 1x1 prior inverse scale of h Ia Ix 1x1 prior degrees of freedom of h Yo 1x1 censoring threshold X Ix K covariates y Tx1 dependant variable Data Generating Process y isa T x 1 vector with fO je 00 0 211 Ge 0 00 uisa T x 1 vector of i i d normal disturbances w
28. es you wish to keep to the postfilter routine postfilter mi filt Now you are left with 900 posterior samples Add another 4100 samples setSeedConstant postsim mi 4100 1 We can also simulate 10000 samples from the posterior using a random walk Hastings Metropolis algorithm setSeedConstant postsimhm mi 10000 1 1 4 4 Extracting and Deleting Model Instances To manipulate a model instance in the Matlab workspace it needs to be extracted from memory Type mysim extract mi to extract the model instance associated with the identification number mi to a Matlab structure called mysim Alternatively this can be done automatically following simulation by typing mysim postsim mi 4100 1 in place of postsim mi 4100 1 Similarly with priorsim and postsimhm To see a list of your current model instances in memory not necessarily in the Matlab workspace type 80 CHAPTER 4 A BACC TUTORIAL listModels To delete the model instance associated with mi from memory type deleteModel mi To delete all model instances in memory type deleteModel 4 5 Computing Marginal likelihoods The mlike command can report several log marginal likelihood values for a model instance First if the model has an analytic marginal likelihood then the exact marginal likehood is printed Then for either a default truncation parameter or for a user specified vector of truncation paramters mlike computes an estimate of the log marginal l
29. et dis tribution See Also paretoSim gaussianSim gammaSim wishartSim Example A 1 0 2 0 3 0 4 0 5 0 6 0 sample dirichletSim A 1000 Details The sample consists of n draws Each of the n draws of the sample is an m by K matrix with independent rows Each row has a Dirichlet distribution with parameters given by the corresponding row of A The result is given as a n by mK matrix and each column gives a draw in column major order See Appendix A for the parameterization of the Dirichlet distribution 46 CHAPTER 3 BACC COMMANDS 3 3 2 The expect1 Command Description Calculates for a weighted random sample the sample mean and standard devi ation estimates of the numerical standard error for the mean and estimates of the relative numerical efficiency Usage mean std nse rne expecti logWeight sample mean std nse rne expecti logWeight sample taper Inputs logWeight Vector of length M log sample weights sample Vector of length M sample of scalar draws taper Vector of length K taper half widths optional Outputs mean Real scalar weighted sample mean std Real scalar weighted sample standard deviation nse Vector of length K 1 estimated numerical standard errors rne Vector of length K 4 1 estimated relative numerical efficiency See Also expectN priorRobust Example 4 Use default taper values mean std nse rne expect1 lw z 4 Use alternate taper value
30. gWeight2 sample2 expectN logWeight1 sample1 logWeight2 sample2 log sample weights for first sample first sample of scalar draws log sample weights for second sample second sample of scalar draws taper half widths optional 1 estimated combined weighted sample Vector of length K 1 estimated numerical standard errors Vector of length K 1 marginal significance levels for a chi squared test of the equality of the population means Use default taper values mean nse p expectN lw1 zi 1w2 z2 4 Use alternate taper values taper 4 0 8 0 mean nse p expectN lw1 zi lw2 z2 taper 50 CHAPTER 3 BACC COMMANDS Details In general there are N pairs of weighted samples not just two For each sample z expectN calculates individual sample moments z and estimates of numerical standard errors ro T TQ from the samples 2 D 29 the log weights log 26 log z6 and the half taper values A1 Ax in the same way that expect1 calculates Z and 7 7 from z1 ZM log z1 logzy and A1 Ax The estimated sample means Zz are given by z 1 2 Z k 2 2 1 20 k 1 K i 1 i 1 Tk For each k the marginal significance level is the value of pz such that 7 7 7 ze B gt E x x x XU 71 en im where X is the following matrix 720 7120 72 0 ee 0 0 SAONE T D 0 0 0 qr 0 0 0 0 0 eid HO ae 2U 0 2 N 1
31. he model latent variables and missing data Separate sub sub sections discuss unknown quantities in each of these categories Posterior simulation involves drawing these quantities from their posterior distribution that is their conditional distribution given known quantities 2 1 3 Known Quantities Known quantities are all the observed or user specified values in a model They include prior parameters which index distributions within a family of prior distributions and observed data Separate sub sub sections discuss known quantities in both of these categories The user of the BACC software must specify all the known quantities of a model in order to create an instance of the model 11 12 CHAPTER 2 MODELS 2 1 4 Data Generating Process This section specifies the conditional distribution of the endogenous observed data given the unknown quantities and any observed data ancillary with respect to the unknown quantities 2 1 5 Prior Distribution This section specifies the marginal distribution of the unknown quantities reflecting the user s prior beliefs about these quantities These unknown quantities may or may not be independent An example where they are not is a hierarchical prior in which the prior density is expressed as the product of marginal densities of the lowest level unknowns and conditional densities of higher level unknowns given lower level unknowns 2 1 6 Creating a Model Instance This sectio
32. iLoad miFile 57 58 CHAPTER 3 BACC COMMANDS 3 3 11 The miLoadAscii Command Description Loads a model instance stored in a text file Usage modelInst miLoadAscii filename Inputs filename String name of text file storing the model instance Outputs modelInst Integer model instance identifier See Also miSaveAscii minst miLoad Example mi miLoadAscii miFile txt 3 8 DETAILED DESCRIPTION OF COMMANDS 3 3 12 The miSave Command Description Saves a model instance in a binary file Usage miSave modelInst filename Inputs modelInst Integer model instance identifier filename String name of binary file in which to store the model instance Outputs None See Also miLoad minst miSaveAscii Example miSave mi miFile Details If the file already exists it is written over 59 60 CHAPTER 3 BACC COMMANDS 3 3 13 The miSaveAscii Command Description Saves a model instance in a text file Usage miSaveAscii modelInst filename Inputs modelInst Integer model instance identifier filename String name of text file in which to store the model instance Outputs None See Also miLoadAscii minst miSave Example miSaveAscii mi miFile txt Details If the file already exists it is written over The ascii version of a model instance is platform independent and human readable but long and inefficient 3 8 DETAILED DESCRIPTION OF
33. if i f for some j from 1 to n 66 CHAPTER 3 BACC COMMANDS 3 3 18 The postsim Command Description Generates or appends to the posterior simulation matrix of a given model in stance Usage postsim modelInst m n Inputs modelInst Integer model instance identifier m Integer number of posterior draws to record n Integer number of posterior draws to generate for each one recorded Outputs None See Also minst postfilter nlike priorsim postsimHM extract Example postsim mi 1000 1 Details Generates draws of unknown quantities from their posterior distribution Gen erates mn new posterior draws and appends every nth draw to the posterior simulation matrix If there are any draws from a previous invocation of postsim the first new draw comes from the transition kernel of the Markov chain used for posterior simulation Otherwise it comes from the initial distribution of the Markov chain Use the extract command to obtain the posterior draws 3 8 DETAILED DESCRIPTION OF COMMANDS 67 3 3 19 The postsimHM Command Description Generates or appends to the posterior HM simulation matrix of a given model instance Usage postsimHM modellnst m n scalePrecision Inputs modelInst Integer model instance identifier m Integer number of posterior draws to record n Integer number of posterior draws to generate for each one recorded scalePrecision Real scalar factor used to rescale the precisi
34. ikelihood for each truncation parameter Finally if there are postsimhm samples as well then mlike also reports estimates of the log marginal likelihood based on those samples To use the default truncation parameter and compute the log marginal likelihoods type mlike mi or to specify a vector of truncation parameters type for example p 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 mlike mi p 4 6 Computing Moments of Functions of Interest To compute the posterior mean of the first element of beta type expect1 mysim logweight mysim beta 1 1 To specify taper parameters rather than the use the default values type taper 4 0 8 0 expect1 mysim logweight mysim beta 1 1 taper More generally expect1 can compute the mean and standard deviation of any function of interest The first argument is a vector of log weight values and the second argument is a vector of function of interest values In some cases it may be sufficient to simply change the weight vector For example to find the mean of h conditional on h being greater than 0 8 the log weight vector could be defined as 4 7 SENSITIVITY TO THE PRIOR 81 lw log mysim h gt 8 If h is greater than 0 8 then lw equals log 1 O for that sample If h is less than or equal to 0 8 then 1w equals log 0 Infinity for that sample Hence the mean of the prior samples of h conditional on h being greater than 0 8 is found by expecti lw mysim h In other cases the second argument
35. iography 88 CONTENTS Chapter 1 Getting Started with BACC 1 1 Introduction The BACC software provides the user several commands for doing Bayesian analysis and communications This document describes the function of these commands and their in puts and outputs It also outlines some of the theory behind the commands and provides references to the relevant literature The following versions of the BACC software and documentation are available e Windows Matlab e Linux Unix Matlab e Windows R e Linux Unix R This particular manual is for the Windows Matlab version of BACC 1 2 Requirements The Windows Matlab Version of the BACC software requires Matlab 5 0 or higher for Microsoft Windows 95 or higher 1 3 Installation and Configuration Follow these steps to install the Windows Matlab version of BACC 1 Download the zip file baccWinMatlab zip from the software page of the BACC website http www cirano qc ca bacc 10 5 6 CHAPTER 1 GETTING STARTED WITH BACC Unzip the zip file to the directory C using a standard unzipping utility such as PKZIP available at http www pkware com Other freeware and shareware unzip ping utilities are available on the web This creates the directory C NBACC Matlab and fills it with all the necessary files You may also install the software into an alternative directory in which case the following steps need to be modified accordingly Start Matlab Add the C NBA
36. ions K number of covariates Unknown Quantities B K x1 vector of covariate coefficients h 1x1 precision of disturbance Known Quantities B Kx1 prior mean of B H KxK prior precision of 8 IVa 1x1 prior inverse scale of h Ix 1x1 prior degrees of freedom of h X TxkK covariates y Tx1 dependant variable Data Generating Process The observables y are given by y XP u CHAPTER 2 MODELS Normal Distur where uis a T x 1 vector of i i d normal disturbances with u h N 0 h7 p u X B h 21 T hTP exp hu u 2 Prior Distribution The vectors 9 and h together with X are mutually independant The covariate coefficient vector 3 has distribution N P H 5 p B 2 P H 11 exp 8 B H4 8 8 2 The precision parameter h has a scaled chi squared distribution with s h v p h 22PT 1 2 1 s2 22n 97 exp s h 2 2 7 A UNIVARIATE LINEAR MODEL WITH NORMAL DISTURBANCES 23 Sampling Algorithm See Example 3 4 1 in Contemporary Bayesian Econometrics and Statistics by John Geweke at http www cirano qc ca bacc bacc2003 resources html 24 CHAPTER 2 MODELS 2 8 A Univariate Dichotomous Choice Model with Nor mal Disturbances The mnemonic label identifying the model is n dichot Dimension Parameters T number of observations K number of covariates Unknown Quantities B K x1 vector of covariate coefficients g Tx1 normal lat
37. ision inverse scale parameter S Data There are m vectors of observations of dependent variables y1 Ym Each vector is T x 1 There are m matrices of observations of ancillary with respect to unknown quantities variables Z1 Zm Each matrix is T x k 2 2 4 Data Generating Process Ui Zi Ym Zm m SES m T3 2 2 5 Priors The unknown parameters 6 and H are a priori independent and have the following marginal distributions B N B Hz H Wi S v When m 1 the distribution of SH is chi squared with y degrees of freedom 14 CHAPTER 2 MODELS 2 2 6 Creating a Model Instance The mnemonic label identifying the model is nlm Supply the names you wish to give the unknown quantities in the following order first the name of 8 beta for example and then the name of H Supply the known quantities in the following order B Hg v S Z y 2 2 7 Sampling Algorithms Generating Prior Samples Samples from the prior distribution of 8 and H are generated independently Generating Posterior Samples The algorithm to generate samples from the posterior distribution 8 H Z y is a Gibbs sam pling algorithm with two blocks based on the following conditional posterior distributions H 6 y Z W S v where Hg H Z H 9 Ir Z B H H5B Z H 8 Ir y 2 8 THE SEEMINGLY UNRELATED REGRESSIONS MODEL 2 3 The Seemingly Unrelated Regressions Model This is a special case of the Norma
38. ith u h N 0 h 1 p u X B h 27m T 2 amp 7 exp hu u 2 Prior Distribution The vectors 8 h are mutually independant The covariate coefficient vector has distribu tion N 8 Hg p B 21 K H 5 exp 8 8 H4 8 B 2 26 CHAPTER 2 MODELS The precision parameter h has a scaled chi squared distribution with s h v p h 2 P T v 2 8 Ph exp s h 2 Sampling Algorithm See Example 3 4 1 in Contemporary Bayesian Econometrics and Statistics by John Geweke at http www cirano qc ca bacc bacc2003 resources html 2 10 A UNIVARIATE OBSERVED SET MODEL WITH NORMAL DISTURBANCES27 2 10 A Univariate Observed Set Model with Normal Disturbances The mnemonic label identifying the model is n set Dimension Parameters T number of observations K number of covariates Unknown Quantities B K x1 vector of covariate coefficients h 1x1 precision of student t distribution y Tx1 normal latent variables Known Quantities B Kx1 prior mean of 8 Hg KxK prior precision of 8 IVa 1x1 prior inverse scale of h Ix 1x1 prior degrees of freedom of h X TxkK covariates a T x1 lower bound of observed interval a T x1 upper bound of observed interval Data Generating Process y isa T x 1 vector with t ik 00 0 Ye 1 Ut 0 00 uisa T x 1 vector of i i d normal disturbances with u h N 0 h7 p u X B h 27m T 2 amp 7 exp
39. l Linear Model with m gt 1 Please see section 2 2 15 16 CHAPTER 2 MODELS 2 4 The LI D Finite State Model 2 4 1 Dimension parameters There are m states N individuals and T observation times 2 4 2 Unknown Quantities Unknown Parameters There is a 1 x m state probability vector 7 2 4 3 Known Quantities Prior Parameters There is a 1 x m parameter o indexing the prior distribution of 7 Data There are state observations sy 1 m for each individual of N individuals and each observation period t of T periods S 2 4 4 Data Generating Process Each observation s is independently and identically distributed as follows Pr si s Ts 1 2 4 5 Priors 7 Di a 2 4 6 Creating a Model Instance The mnemonic label identifying the model is iidfs Supply the name you wish to give the unknown quantity 7 pi for example Supply the known quantities in the following order a S 2 4 7 Sampling Algorithms Generating Prior Samples Samples from the prior distribution of 7 are generated independently 2 4 THE LI D FINITE STATE MODEL 17 Generating Posterior Samples In this model the posterior distribution for 7 is the following familiar distribution S Di a where Q Q at n n m Nm and n is the number of observations for which s s Posterior samples are drawn independently from this distribution 2 4 8 Marginal Likelihood The marginal likelihood is given by
40. miSaveAscii minst Generates a sample from a multiple Dirichlet distribution Calculates for a weighted random sample the sample mean and stan dard deviation estimates of the numerical standard error for the mean and estimates of the relative numerical efficiency Calculates combined sample means with numerical standard errors for a set of different weighted random samples and tests for the equality of their individual population means Returns simulation matrices for a model instance Generates a sample from a gamma distribution Generates a sample from a Gaussian distribution Lists all available model specifications e g nlm poisson Lists all open model instances Closes without saving a or all model instances Loads a model instance stored in a binary file Loads a model instance stored in a text file Saves a model instance in a binary file Saves a model instance in a text file Creates an instance of a particular model specification 43 44 mlike paretoSim postfilter postsim postsimHM priorRobust priorfilter priorsim setseedconstant setseedtime weightedSmooth wishartSim CHAPTER 3 BACC COMMANDS Computes various estimates of the marginal likelihood for a model in stance with numerical standard errors Generates a sample from a Pareto distribution Filters out previously generated draws from the posterior simulation ma trix of a given model instance Generates or ap
41. might be changed For example foi 1 mysim h expecti mysim logweight foi To compute combined sample means and test for the equality of the individual popula tion means use the expectN command For example to compare the posterior and prior means for the first element of the beta vector type expectN mysim logweight mysim beta 1 1 mysim logweight mysim betaPrior 1 1 taper 4 7 Sensitivity to the Prior To calculate upper and lower bounds on the mean of a posterior function of interest as the prior distribution is varied from its original specification type priorRobust mysim logweight mysim beta 1 1 To specify values of the bounds parameter other than the default values bounds 2 10 priorRobust mysim logweight mysim beta 1 1 bounds 4 8 Kernel Smoothing of Simulations To estimate a univariate density function for a weighted random sample using kernel smoothing type x y weightedSmooth mysim logweight mysim beta 1 1 Then plot the kernel using the Matlab plot command plot x y The weightedSmooth command has various settings that can be changed For example 82 CHAPTER 4 A BACC TUTORIAL to generate more samples and use a different kernel you might type nplot 2000 ktype triangular x y weightedSmooth mysim logweight mysim beta 1 1 4 9 Plotting The user can use all of the standard Matlab plotting tools Before plotting unknown quan tities however they must be con
42. n gives all the model specific information a user requires to create a model instance It specifies a short mnemonic label that identifies the model the order in which the user gives the names to assign the unknown quantities and the order in which to supply all the known quantities To create a model instance the user issues the minst command with appropriate arguments see section 3 3 14 2 1 7 Sampling Algorithms This section has brief descriptions of the algorithm used to generate samples of unknown quantities from their prior and posterior distributions One subsection each concerns the prior distribution and the posterior distribution For further details on the algorithms the user should consult the internal source code documentation for the BACC system 2 1 8 Marginal Likelihood Where there is an analytical expression for the marginal likelihood in a model this subsection provides that expression 2 2 THE NORMAL LINEAR MODEL 13 2 2 The Normal Linear Model 2 2 1 Dimension parameters There are m equations k covariate coefficients and T observations of each variable 2 2 2 Unknown Quantities Unknown Parameters There is a k x 1 coefficient parameter 8 and a m x m precision parameter H 2 2 3 Known Quantities Prior Parameters There is a k x 1 coefficient mean vector 8 a k x k positive definite coefficient precision matrix H a precision degrees of freedom parameter y gt and a positive definite 2 prec
43. n s t n t 0 T 1 48 CHAPTER 3 BACC COMMANDS y dik 2 and nd k of Then it calculates for each k 1 K estimates Orn T d t based on the taper c2 Var n t c2 Var d t and ona Cov n t half width A Ak 1 u Ak 1 ls m Ocak Yad 0 2 5 Em Yda s s 1 2 Ond k Wmal0 YA bass s US Yan s These calculations are based on conventional time series methods for a wide sense stationary process described in Geweke 1992 4 By the conventional asymptotic expansion the square of the numerical standard error is approximated by 2 1 On Ond d T Var i 4 i Ond Od P For each k 1 K it calculates the approximation 7 using Or nk 0 ak and o a x defined above Relative numerical efficiencies vo vg are calculated using 3 8 DETAILED DESCRIPTION OF COMMANDS 49 3 3 3 The expectN Command Description Calculates combined sample means with numerical standard errors for a set of different weighted random samples and tests for the equality of their individual population means Usage mean nse equal mean nse equal taper Inputs logWeighti samplei logWeight2 sample2 taper Outputs mean nse equal See Also expecti Example Vector Vector Vector Vector Vector Vector means of length Mi of length Mi of length M2 of length Mo of length K of length K expectN logWeight1 samplei lo
44. o the number of seconds since the beginning of 1970 Usage setseedtime Inputs None Outputs None See Also setseedconstant Example setseedtime Details This is useful for ensuring that repeated invocations of a command generating random values lead to different results 73 T4 CHAPTER 3 BACC COMMANDS 3 3 25 The weightedSmooth Command Description Estimates a univariate density function for a weighted random sample using a kernel smoothing algorithm adapted to weighted samples Usage x y weightedSmooth logWeight sample Inputs logWeight Vector of length M log weights sample Vector of length M a posterior sample of some function of in terest ktype String kernel type optional krange String kernel range type optional wwf Real scalar window width fraction optional nplot Integer number of ordered pairs to generate optional range_al Real scalar left bound range parameter optional range_a2 Real scalar right bound range parameter optional Outputs x Vector of length N ordinate values y Vector of length N abscissa values Example x y weightedSmooth lw z 2000 nplot ktype triangular x y weightedSmooth lw z Details The estimated density at a point z is Rm ws K 2 Xs Wm f z The functional form of the kernel function K depends on the value of ktype according to Table BI 3 83 DETAILED DESCRIPTION OF COMMANDS 75 Table 3 1 Values
45. on matrix of the random walk innovation Outputs None See Also minst mlike postsim extract Example postsimHM mi 1000 1 10 0 Details Generates draws of unknown quantities from their posterior distribution using a Gaussian random walk Metropolis chain with proposal covariance proportional to the sample covariance of draws from the posterior simulation matrix Generates mn new posterior draws and appends every nth draw to the posterior simulation matrix If there are any draws from a previous invocation of postsimHM the first new draw comes from the transition kernel of the Markov chain used for posterior simulation Otherwise it comes from the initial distribution of the Markov chain Use the extract command to obtain the posterior HM draws 68 CHAPTER 3 BACC COMMANDS 3 3 20 The priorRobust Command Description Calculates upper and lower bounds on the mean of a posterior function of inter est as the prior distribution is varied from its original specification Usage mean std U L Ut Lt priorRobust logWeight sample factors Inputs logWeight Vector of length m log weights sample Vector of length m posterior sample of some scalar function of interest factors Vector of length n bound factors for robustness analysis Outputs mean Real scalar posterior sample mean for original prior specification std Real scalar posterior sample standard deviation for original prior specification Vector of
46. pends to the posterior simulation matrix of a given model instance Generates or appends to the posterior HM simulation matrix of a given model instance Calculates upper and lower bounds on the mean of a posterior function of interest as the prior distribution is varied from its original specification Filters out previously generated draws from the prior simulation matrix of a given model instance Generates or appends to the prior simulation matrix of a given model instance Sets the seeds of the random number generators to a constant value Sets the seeds of the random number generators to the number of seconds since the beginning of 1970 Estimates a univariate density function for a weighted random sample using a kernel smoothing algorithm adapted to weighted samples Generates a sample from a Wishart distribution 3 2 Matlab Issues Help is available within Matlab for BACC commands Type help commandName at the Matlab prompt or help BACC for a list of BACC commands 3 3 Detailed Description of Commands Each BACC command is described in detail in one of the following sections 3 8 DETAILED DESCRIPTION OF COMMANDS 45 3 3 1 The dirichletSim Command Description Generates a sample from a multiple Dirichlet distribution Usage sample dirichletSim A n Inputs A m by K matrix Dirichlet parameters n Integer number of draws to generate Outputs sample n by nK matrix sample generated from multiple Dirichl
47. r a RY denoted m Di a if its probability density function is TO Qi Q amp i n n p rja ii res IT im TEA PERE Dep 0 otherwise The mean and variance are given by El la Es _ E vi o E n o Saec uu A 2 The Gamma Distribution A random scalar A has the Gamma distribution with shape parameter a gt 0 and scale parameter 8 gt 0 denoted A Ga a B if its probability density function is AA le P A0 pAla 6 4 T9 otherwise 85 86 APPENDIX A DISTRIBUTIONS The mean and variance are given by Ella 8 5 Var Alo 8 A 3 The Normal Distribution A random vector x has the Normal Distribution with mean parameter vector u R and positive definite k x k variance parameter matrix X denoted x N p X if its probability density function is 1 p z p Ep m Sexp 5 m 4yE a a eR The mean and variane are given by Elz u E y Var z u X X A A The Pareto Distribution A random scalar x has the Pareto Distribution with parameters a gt 0 and 8 gt 0 denoted 0 Pala B if its probability density function is Ago 82g p 6 a 8 otherwise The mean and variance are given by a El6 o 8 a aff Var 6 a 8 a 13 a 3 A 5 The Poisson Distribution A discrete random variable x has the Poisson distribution with mean parameter A gt 0 denoted x Po A if its probability mass function is e xe 0 1 p x 0 otherwise A 6 THE WISHART
48. riate coefficients He KxK prior precision of covariate coefficients s 1x1 prior inverse scale of h V 1x1 prior degrees of freedom of h m 1x1 number of states v 1x1 degrees of freedom parameter for state precisions r 1x1 Dirichlet parameter for state probabilities X TxkK covariates T x1 dependant variable e Data Generating Process The observables y are given by y XP u 38 CHAPTER 2 MODELS where u is a T x 1 vector of independant discrete normal mixture disturbances with uilh 7 o h X given by p ur h 7 0 h X 22 1281 2 5 nj hj exp h hj us o 2 j l Conditioning on the latent states gives p u h a h X 20 18V exp h ha ue as 2 See Section 4 8 in Contemporary Bayesian Econometrics and Statistics by John Geweke at http www cirano qc ca bacc bacc2003 resources html for details Prior Distribution The vectors y h h and 8 7 together with X are mutually independant The y pa rameter vertically stacks the parameters a and 0 where a is the m x 1 vector of state dependant means and 8 is the K x 1 vector of covariate coefficients They are independent with a h N 0 h h 7 and 8 N B Ho p y h p alh p 8 21 hh exp h ho 0 2 21 EP E exp 8 B H5 8 8 2 The precision parameter h has a scaled chi squared distribution with s h v p h 27 T v 2 S 67297 exp s h 2 The state dependant precision
49. s Important Informatio 3 1 Getting Started with BAC 1 1 Initroductionhs oros ss uem rs ES a aaa 44 9 1 2 Requirements iio ii Ge a ee oh a a are HE e Ma Ge ok Go 9 TP 9 11 2 1 Introduction ic ee eem sivo p dom m RU RRR RO mE Be XC APER ERE S 11 211 Dimension parameterd le 11 11 11 12 12 NE i 12 2 1 7 Sam m Al gorithm s aos oe dhe ed XC menom 3 309 X Sa Bend 12 2 1 8 Marginal Likelihood RR RRR 12 2 2 The Normal Linear Model cracca 13 2 2 1 Dimension parameterd 13 2 22 Unknown Quantitied es a ee 13 2 2 3 Known Quantitied cr RR 13 Rees ee oe Ae ee ee ey 13 2 2 5 o iu gee dee ek Ra A RS 13 hucht wed 6442 o on hee eeanes 14 2 gt 7 San RE Algorithm oo ee Rom vom mo Eae oe mo gods 14 15 16 16 16 16 16 TF Creating a Model Instanecd RR RR 16 24 7 Sampling Algorithm Ct 6 CONTENTS 2 4 8 Marginal Likelihoo ETENIM TUM 17 he PEE s y 18 18 18 18 18 19 19 19 S 20 2 Dimension parameterd a a 20 UU qe ar eeu id amp ea Se He oe Sa 20 20 3 Known Quantities 5 2 3 oo n mox RGR RE 609 9 ee 20 T 20 210 5 IPTIOTSg s e ae desk ale re ee ks de AS hoe x OR Recap ep Se RUD t Ist 20 2 6 6 Creating a Model Instancd oon 21 2 6 7 Sam pling Algoritiun AA ees ate at a A ae de 21 3 1 Overview of BACC Commandd o 43 32
50. s taper 4 0 8 0 mean std nse rne expectN lw z taper Details Let z z1 zy be the sample and log w logwaz be the vector of log weights Let A A1 Ax be the vector of half widths The sample is broken into T groups of size J M div T and the last M mod T elements are ignored Thus Muse JT elements are used 3 8 DETAILED DESCRIPTION OF COMMANDS 47 The sample mean and standard deviation are calculated as follows Muse Muse z Wm2m 1 Wm m 1 m i For the calculation of the first numerical standard error 79 we assume no serial correlation in 21 2mM This is appropriate for independence or importance sampling Following Geweke 1989 3 this leads to Muse Muse 3 TR TO y we 2m a OS un m 1 m 1 For the calculation of 7 through Tg the remaining K estimates of the nu merical standard error the following method is used First expect1 calculates group and sample means of the numerator quantity w 7 and the denominator quantity Wm 1 tJ 1 tJ n t J 5 Wmm d t J 5 Wm 21 537 m t 1 J 4 1 m t 1 J 1 M M 1 use 1 use n mem d m Muse 2 iid Muse mal i Then it calculates the following sample autocorellation and autcovariance func tions 1 T Walt F Y n nm n s t 5 t 0 T 1 s t 1 E ox alt Y d s d ds t d t 0 T 1 s t 1 L B malt gt Y n s n d s t d t 0 T 1 s t 1 Lo Yan t 5 d s d
51. s h are i i d with v hj x v mu mv 4 v 2 2 p h 27 T x 2 gne TT ay exp h 2 j l The latent states are i i d with the probability Pr s j given by r for j 1 m T p alr 7 t 1 The vector 7 of probabilities is distributed Dirichlet r r Sampling Algorithm See section 4 8 in Contemporary Bayesian Econometrics and Statistics by John Geweke at http www cirano qc ca bacc bacc2003 resources html 2 16 AN AUTOREGRESSION MODEL 39 2 16 An Autoregression Model The mnemonic label identifying the model is AR Dimension Parameters T number of observations K number of covariates p autoregressive order Unknown Quantities B K x1 covariate coefficient vector h 1x1 residual precision px1 vector of autoregression coefficients Known Quantities B K x1 prior mean of 3 Hg Kx K prior precision of 3 D 1x1 prior degrees of freedom of h 32 1x1 prior inverse scale of h Q px 1 prior mean of before truncation Hs pxp prior precision of before truncation gt T x K covariates y Tx1 dependant variable Data Generating Process The data generating process is given by yi Bai t where z is the tth row of X as a column vector p X hiai ut i 1 and uz iid N 0 A1 40 CHAPTER 2 MODELS Prior Distribution The unknowns are a priori independent and have the following distributions B N 6 H5 8h x y
52. the names of the known quantities The next line creates an instance of the normal linear model assigns a model identification number to it and places this number in mi References to mi now refer to this model instance mi minst nlm beta h betahd Hhd nuhd shd Xhd yhd To see a list of available model specifications e g nlm that can be used with minst type listModelSpecs 4 3 Simulating the Model Simulation can be performed from the prior or the posterior of a model using the commands priorsim and postsim After posterior simulation has been done it is also possible to sim ulate the posterior using a random walk Hastings Metropolis algorithm This is done using the command postsimhm If you wish to compare output across runs it is a good idea to set the seeds of the random number generators This is done using the setSeedConstant command Strictly speaking this sets the seeds of another routine that then sets the seeds of the random number generators First generate 5000 samples from the prior setSeedConstant priorsim mi 5000 1 Now generate 1000 samples from the posterior 44 EXTRACTING AND DELETING MODEL INSTANCES 79 setSeedConstant postsim mi 1000 1 To filter out posterior samples you can specify the numbers of the samples you wish to keep For example to drop the first 100 samples you would create a vector containing the numbers 101 to 1000 filt 101 1000 Then pass this list of sampl
53. verted from 3 dimensional arrays to 2 dimensional arrays The first two dimensions for an unknown quantity refer to the actual parameter dimensions The third dimension is the sample index Conversions can be done using the Matlab com mand squeeze The command removes any singleton dimensions To convert the first beta parameter into a two dimensional array type betal squeeze mysim beta 1 1 To convert all of the beta s into an M x k array where M indexes the number of sam ples and k is the number of elements of beta type beta squeeze mysim beta 1 With an understanding of squeeze it is now possible to discuss various plotting tools For example to get a histogram of the posterior simulation of the unknown parameter h type hist mysim h Or hist mysim h 40 where the second command increases the number of bins used in the histogram To plot a time series of the loglikelihood values type plot mysim loglike To plot a scatterplot of the third and fourth elements of beta type scatter beta 3 beta 4 where beta refers to the squeeze d matrix from above 4 10 SAVING AND LOADING MODEL INSTANCES 83 4 10 Saving and Loading Model Instances 4 10 1 To From Text Files To save a model instance called mi to an ascii file called mi txt use the command miSaveAscii mi mi txt To load a model instance stored in an ascii file called mi txt and to give it the name mi use the command mi miLoadAscii

Download Pdf Manuals

image

Related Search

Related Contents

1 miniDSP + 2 miniDIGIs App note  PC Suite for Nokia 8890 - Guía de instalación (PDF file)  Notice  Honda HS55 User's Manual  manuel d`instructions et d`utilisation modèle 2200 poêle  HP Officejet J3500/J3600 All-in  Kicker 2008 KS Tweeters Owner's Manual  GMA 340 AUDIO PANEL installation Manual  www.philips.com/welcome  T'nB HDC10GR  

Copyright © All rights reserved.
Failed to retrieve file