scieee AI-readable full text Open interactive document viewer

The R Package Mitisem: Efficient and Robust Simulation Procedures for Bayesian Inference

Basturk, Nalan,Grassi, Stefano,Hoogerheide, Lennart,Opschoor, Anne,van Dijk, Herman K.

Abstract

EconStor is a publication server for scholarly economic literature, provided as a non-commercial public service by the ZBW.

Full text

Basturk, Nalan; Grassi, Stefano; Hoogerheide, Lennart; Opschoor, Anne; van Dijk, Herman K. Working Paper The R Package Mitisem: Efficient and Robust Simulation Procedures for Bayesian Inference Working Paper, No. 10/2017 Provided in Cooperation with: Norges Bank, Oslo Suggested Citation: Basturk, Nalan; Grassi, Stefano; Hoogerheide, Lennart; Opschoor, Anne; van Dijk, Herman K. (2017) : The R Package Mitisem: Efficient and Robust Simulation Procedures for Bayesian Inference, Working Paper, No. 10/2017, ISBN 978-82-7553-987-6, Norges Bank, Oslo, https://hdl.handle.net/11250/2495576 This Version is available at: https://hdl.handle.net/10419/210120 Standard-Nutzungsbedingungen: Die Dokumente auf EconStor dürfen zu eigenen wissenschaftlichen Zwecken und zum Privatgebrauch gespeichert und kopiert werden. Sie dürfen die Dokumente nicht für öffentliche oder kommerzielle Zwecke vervielfältigen, öffentlich ausstellen, öffentlich zugänglich machen, vertreiben oder anderweitig nutzen. Sofern die Verfasser die Dokumente unter Open-Content-Lizenzen (insbesondere CC-Lizenzen) zur Verfügung gestellt haben sollten, gelten abweichend von diesen Nutzungsbedingungen die in der dort genannten Lizenz gewährten Nutzungsrechte. Terms of use: Documents in EconStor may be saved and copied for your personal and scholarly purposes. You are not to copy documents for public or commercial purposes, to exhibit the documents publicly, to make them publicly available on the internet, or to distribute or otherwise use the documents in public. If the documents have been made available under an Open Content Licence (especially Creative Commons Licences), you may exercise further usage rights as specified in the indicated licence. https://creativecommons.org/licenses/by-nc-nd/4.0/deed.no The R package MitISEM: Efficient and robust simulation procedures for Bayesian inference NORGES BANK RESEARCH 10 | 2017 NALAN BASTURK, STEFANO GRASSI, LENNART HOOGERHEIDE, ANNE OPSCHOOR AND HERMAN K. VAN DIJK WORKING PAPER NORGES BANK WORKING PAPER XX | 2014 RAPPORTNAVN 2 Working papers fra Norges Bank, fra 1992/1 til 2009/2 kan bestilles over e-post: [email protected] Fra 1999 og senere er publikasjonene tilgjengelige på www.norges-bank.no Working papers inneholder forskningsarbeider og utredninger som vanligvis ikke har fått sin endelige form. Hensikten er blant annet at forfatteren kan motta kommentarer fra kolleger og andre interesserte. Synspunkter og konklusjoner i arbeidene står for forfatternes regning. Working papers from Norges Bank, from 1992/1 to 2009/2 can be ordered by e-mail: [email protected] Working papers from 1999 onwards are available on www.norges-bank.no Norges Bank’s working papers present research projects and reports (not usually in their final form) and are intended inter alia to enable the author to benefit from the comments of colleagues and other interested parties. Views and conclusions expressed in working papers are the responsibility of the authors alone. ISSN 1502-819-0 (online) ISBN 978-82-7553-987-6 (online) The RPackage MitISEM: Efficient and Robust Simulation Procedures for Bayesian Inference∗ Nalan Ba¸st¨ urk Maastricht University & RCEA Stefano Grassi University of Rome “Tor Vergata” Lennart Hoogerheide Vrije Universiteit Amsterdam & Tinbergen Institute Anne Opschoor Vrije Universiteit Amsterdam &Tinbergen Institute Herman K. van Dijk Erasmus University Rotterdam & The Norges Bank &Tinbergen Institute & RCEA Abstract This paper presents the Rpackage MitISEM (mixture of t by importance sampling weighted expectation maximization) which provides an automatic and flexible two-stage method to approximate a non-elliptical target density kernel – typically a posterior density kernel – using an adaptive mixture of Student-tdensities as approximating density. In the first stage a mixture of Student-tdensities is fitted to the target using an expectation maximization algorithm where each step of the optimization procedure is weighted using importance sampling. In the second stage this mixture density is a candidate density for efficient and robust application of importance sampling or the Metropolis-Hastings (MH) method to estimate properties of the target distribution. The package enables Bayesian inference and prediction on model parameters and probabilities, in particular, for models where densities have multi-modal or other non-elliptical shapes like curved ridges. These shapes occur in research topics in several scientific fields. For instance, analysis of DNA data in bio-informatics, obtaining loans in the banking sector by heterogeneous groups in financial economics and analysis of education’s effect on earned income in labor economics. The package MitISEM provides also an extended algorithm, ‘sequential MitISEM’, which substantially decreases computation time when the target density has to be approximated for increasing data samples. This occurs when the posterior or predictive density is updated with new observations and/or when one computes model probabilities using predictive likelihoods. We illustrate the MitISEM algorithm using three canonical statistical and econometric models that are characterized by several types of non-elliptical posterior shapes and that describe well-known data patterns in econometrics and finance. We show that MH using the candidate density obtained by MitISEM outperforms, in terms of numerical efficiency, MH using a simpler candidate, as well as the Gibbs sampler. The MitISEM approach is also used for Bayesian model comparison using predictive likelihoods. Keywords: finite mixtures, Student-tdensities, importance sampling, MCMC, Metropolis- Hastings algorithm, expectation maximization, Bayesian inference, Rsoftware. ∗This paper should not be reported as representing the views of Norges Bank. The views expressed are those of the authors and do not necessarily reflect those of Norges Bank. 2The R package MitISEM 1. Introduction There exist several classes of important statistical and econometric models where posterior and/or predictive distributions have unknown analytical properties and non-elliptical Bayesian Highest Posterior Density (HPD) credible sets. For a theoretical background see e.g., Berger (1985) and as examples we name the class of so-called instrumental variable regression models with weak instruments where, for instance, the effect of years of education on income is modeled and measured. This is very relevant for government agencies responsible for compulsory schooling laws. A second example is the class of mixture processes where one component is nearly non-identified since it corresponds to very few observations, which may occur in financial models with data that exhibit time varying volatility patterns and heavy tails and it may also occur in epidemiological models with regional data patterns where very few observations of a disease occur. A detailed analysis of this literature is beyond the scope of the present paper. We refer to, e.g., Imbens and Angrist (1994) and Bos, Mahieu, and Van Dijk (2000), the references cited there and to several textbooks: Lancaster (2004); Geweke (2005); Rossi, Allemby, and McCulloch (2005) and Koop, Poirier, and Tobias (2007) for more background. In such studies an important technical issue is the development of efficient and robust procedures to generate (pseudo-) random draws from non-elliptical distributions in a numerically efficient way. Even if simulation from the conditional distributions is relatively easy, for example, using the well-known Gibbs sampler, multi-modality and/or high correlations between model parameters may cause this sampler to converge extremely slowly and yield erroneous results even with a relatively large sample of draws. We illustrate this in the present paper. Two stage method and the approximation property This paper presents the R(RCore Team 2017) package MitISEM (Ba¸st¨ urk, Hoogerheide, Opschoor, and Van Dijk 2017) which provides an automatic and flexible method to approximate a target posterior or predictive density by an adaptive mixture of Student-tdensities, also referred to in the following as approximate,candidate or proposal density1. The multivariate target density can be non-elliptical like being multi-modal, strongly correlated and/or having curved ridges in the surface. Only a kernel of the target density is required for the MitISEM method, which is typically a posterior density kernel. Our method consists of two stages. In the first stage a mixture of Student-tcandidate densities is fitted to the target using an expectation maximization (EM) algorithm where each step of the optimization procedure is weighted using importance sampling. Details are given in Section 2. In the second stage the obtained candidate density can be used in importance sampling or the independence chain Metropolis-Hastings method for Bayesian inference on model parameters and model probabilities. The MitISEM method has been introduced by Hoogerheide, Opschoor, and Van Dijk (2012) and it has been shown that the method provides substantial gains in computational efficiency in Bayesian estimation. The MitISEM method makes use of convex combinations of densities, and the approximation properties of such density combinations have been analyzed extensively in the literature. For instance Zeevi and Meir (1997) show that under certain conditions any density function may be approximated to arbitrary accuracy by a convex combination of ‘basis’ densities. The class of mixtures of Student-tdensities falls within this framework. Algorithmic steps In the first stage the algorithm MitISEM iterates over importance weighted expectation max- 1These three terms are interchangeably used in the literature and we also do that in the present paper. Nalan Ba¸st¨ urk, Lennart Hoogerheide, Anne Opschoor, Herman K. van Dijk 3 imization steps in order to efficiently construct a mixture of Student-tdensities that is an accurate approximation of the target density. Starting with a single Student-tdensity, new mixture components are added in an iterative way until the required approximation is reached. At each iteration, parameters of the mixture components – consisting of mode, scale, degrees of freedom and mixing probability – are optimized such that the Kullback-Leibler divergence between target density and candidate density of Student-tmixtures is minimized. The constructed mixture is used in the second stage for efficient and robust application of either importance sampling (IS) or the independence chain Metropolis-Hastings (MH) method. Illustrations We illustrate the MitISEM algorithm using a well-known statistical example distribution from Gelman and Meng (1991) that is characterized by a very non-elliptical, possibly bi-modal, joint distribution while the conditional distributions are normal. We also use the posterior distributions in two classes of canonical econometric models: the generalized autoregressive conditional heteroskedasticity (GARCH) model that is extensively used in financial econometrics and the Instrumental Variable (IV) regression model that is often used to study the effect of number of years of education on earned income. Both classes of models yield nonelliptical posterior and/or predictive distributions. Furthermore, we show that the MitISEM approach can be used for the evaluation of model probabilities from predictive likelihoods, which are useful for Bayesian model comparison and model averaging. We also introduce an Rprogram for an adapted MitISEM algorithm as in Hoogerheide, Opschoor, and Van Dijk (2012), named ‘sequential MitISEM’, which substantially decreases the computational time required for the candidate density optimization, when the posterior distribution is updated using new observations or when one computes model probabilities with predictive likelihoods. The remainder of this paper is organized as follows: Section 2discusses the basic idea of the MitISEM method and the ‘sequential MitISEM’ extension, and summarizes the steps of the expectation maximization algorithm that we make use of. Section 3presents applications of the algorithm to several model structures and datasets. Section 4concludes. 2. Searching for a mixture of Student-tcandidate densities using IS weighted EM The mixture of Student-tdensities that is obtained by making use of importance sampling weighted expectation maximization is based on iteratively adding Student-tdensities to the mixture (Hoogerheide, Opschoor, and Van Dijk 2012). The algorithm provides an automatic and flexible method to construct a candidate density minimizing the Kullback-Leibler divergence (or cross-entropy distance) (Kullback and Leibler 1951) between two densities: the so-called target density, typically a posterior density, and the approximate or candidate density. Each new Student-tcomponent in the candidate density covers the areas of the target density that are not well covered by the previous candidate density. The modes, scales, degrees of freedom and mixing probabilities are quickly optimized using the importance sampling weighted expectation maximization method. Henceforth we use the notation f(θ) for the target density kernel of θ, the k-dimensional vector of interest. f(θ) can be a posterior density kernel of model parameters defined as f(θ|y) for data yand model parameters θ. Alternatively, f(θ) can be a density kernel f(θ|α) for data θand given fixed model parameters α. We concentrate on the former case, where f(θ) is a 4The R package MitISEM posterior density kernel, and simplify the notation by having removed the conditioning on data. Let g(θ) be a candidate density, a mixture of HStudent-tdensities such that: g(θ) = g(θ|ζ) = H X h=1 ηhtk(θ|µh,Σh, νh),(1) where ζis the set of location parameters µh, scale matrices Σh, degrees of freedom νh, and mixing probabilities ηh(h= 1, . . . , H) of the k-dimensional Student-tcomponents with density: tk(θ|µh,Σh, νh) = Γνh+k 2 Γνh 2(πνh)k/2|Σh|−1/2 1 + (θ−µh)>Σ−1 h(θ−µh) νh!−(k+νh)/2 (2) with h= 1, . . . , H and Σhis positive definite, ηh≥0 and PH h=1 ηh= 1. We further restrict νhsuch that νh≥0.01. Lower and upper bounds for the degrees of freedom parameter νh can be defined using an optional input to the function MitISEM (e.g., demanding νh>2). MitISEM is a new approach that may be compared with the AdMit method (Hoogerheide, Kaashoek, and Van Dijk 2007b), implemented in Ardia, Hoogerheide, and Van Dijk (2009, 2017). Both methods rely on the iterative construction of a mixture of Student-tdensities as the candidate density, but there are three substantial differences between these methods. First, MitISEM minimizes the Kullback-Leibler divergence between target and candidate densities, while AdMit aims at minimizing the variance of the IS estimator, or the variance of the IS weights. Second, in MitISEM all mixture parameters are optimized jointly by means of the relatively quick EM algorithm, while in the AdMit method means and scale matrices of the candidate components are chosen heuristically and are never updated when additional components are added to the mixture. That is, AdMit optimizes only mixture component weights. MitISEM implies a large reduction of the computing time in the approximation procedure, and is expected to lead to a better candidate in most applications. Therefore the MitISEM method may be considered to be a substitute for the AdMit method, rather than an accompanying method. Third, as shown in Hoogerheide, Opschoor, and Van Dijk (2012), AdMit requires the joint target density kernel, whereas MitISEM requires only candidate draws and importance weights. This implies that AdMit can not be applied partially to the marginal and conditional posterior densities of subsets of parameters, whereas MitISEM can be used to approximate a marginal density of which no kernel is explicitly available. 2.1. Background on importance sampling Importance sampling (Hammersley and Handscomb 1975;Kloek and Van Dijk 1978) is a general method for estimating expectations of a function h(θ) of parameter θwhere the probability density function of θis possibly non-standard. Given a density kernel f(θ) for θ, where one cannot directly generate random draws from in an easy manner, importance sampling is based on draws from a different density, the so-called candidate or importance density g(θ), which is easy to simulate from and which is a reasonable approximation to f(θ). Given this indirect sampling, instead of direct sampling from f(θ), one needs a correction step. That Nalan Ba¸st¨ urk, Lennart Hoogerheide, Anne Opschoor, Herman K. van Dijk 5 is, the draws from the candidate density are weighted according to the importance sampling (IS) weights that are ratios of target over candidate density. For a consistent estimator of the expectation of the function of θ,E(h(θ)), the candidate should cover the whole domain of θvalues with f(θ)>0 and the variance of the weights should be bounded (Geweke 1989). The finite sample accuracy of the estimator improves if g(θ) is a good approximation to the target kernel (Van Dijk 1984;Van Dijk, Hop, and Louter 1987;Geweke 1989;Hop and Van Dijk 1992). IS weights for parameter draws ˜ θfrom g(θ) are calculated as: ˜ W(˜ θ) = f(˜ θ)/g(˜ θ),(3) i.e., draws with highest IS weights correspond to the region of the target where the candidate is much smaller than the target and this is a region that is covered too little by the candidate density. Parallel Processing of Computations Capp´e, Douc, Guillin, Marin, and Robert (2008) note that there is a renewed interest in importance sampling, due to the possibility of parallel processing implementation. Numerical efficiency in sampling methods is not only related to the efficient sample size or relative numerical efficiency, but also to the possibility to perform the simulation process in a parallel fashion. Unlike alternative methods such as the random walk Metropolis method or the Gibbs sampler, importance sampling makes use of independent draws from the candidate density, which in turn can be obtained from multiple core machines or computer clusters. See Geweke and Durham (2011) for a very novel approach. We are currently exploring the idea to make use of paralleled computing in MitISEM. We comment on this possibility in Section 4. 2.2. Background on expectation maximization and our use of this algorithm The EM algorithm is a method (Dempster, Laird, and Rubin 1977) to achieve the maximum likelihood estimates of parameters θin models with incomplete data or latent variables. An example of the latter case is the finite mixture model. For the use of the EM algorithm on finite mixture models, we refer to e.g., McLachlan and Peel (2000); McLachlan and Krishnan (2008). If the latent variables would be observable, the computation of the maximum likelihood estimate of θwould be relatively straightforward, depending on the degree of nonlinearity of the first order conditions. The idea behind EM is to take the expectation of the objective function, in most cases the log-likelihood function, with respect to the latent variables. The expectation of the log-likelihood function is then maximized with respect to the model parameters. In most models, expectations of the latent variables depend on the model parameters θ, hence the two steps are repeated until convergence. We emphasize that during the first stage of the method (in which the candidate density is optimized) we do not have draws from the posterior but instead have draws from a previously chosen candidate and corresponding importance weights. As a consequence, we make use of an importance weighted EM algorithm. As shown in Hoogerheide, Opschoor, and Van Dijk (2012), in the MitISEM approach, we minimize the estimated Kullback-Leibler divergence, which implies that we maximize the weighted average of the logarithm of the candidate density g(.|ζ) evaluated at a set of draws θifrom a previous candidate g0(θ), where each candidate value log g(θi|ζ) is weighted by the importance sampling weights Wi≡f(θi)/g0(θi) of each 6The R package MitISEM draw θifrom the previous candidate g0(θ): 1 N N X i=1 Wilog g(θi|ζ) where g(.|ζ) is the mixture of Student-tdensities to be optimally chosen. The mixture of Student-tdensities (1) for θiis equivalent with the specification θi∼N(µh, wi hΣh) if zi h= 1, where ziis a latent H-dimensional vector indicating from which Student-tcomponent the ‘observation’ θistems: if θistems from component h, then zi h= 1, zi j= 0 for j6=h; Pr[zi= eh] = ηhwith ehthe h-th column of the identity matrix; wi hhas the Inverse-Gamma density IG(νh/2, νh/2). For a more extensive explanation of this mixture of Student-tdensities, see e.g., Peel and McLachlan (2000). 2.3. The IS weighted EM algorithm We reemphasize that in the literature the EM algorithm is typically used to find the optimal values of model parameters that maximize the log-likelihood for a given set of data. Here we make use of EM to find the optimal mixture of Student-tdensities for a given set of draws from a previous candidate (and their corresponding weights). We apply an IS-weighted EM algorithm to these candidate draws instead of a regular EM algorithm to posterior draws (obtained by applying the Metropolis-Hastings method to these candidate draws), since the former has three advantages. First, we do not require a burn-in sample. Second, the use of all candidate draws (without the rejections of the MH method) helps to prevent numerical problems with estimating scale matrices of Student-tcomponents; also draws with relatively small, but positive importance weights are helpful for this purpose. Third, the use of all candidate draws may lead to a better approximation. In Hoogerheide, Opschoor, and Van Dijk (2012) the different steps of the IS-weighted EM algorithm in our case are derived. Here we summarize the steps for the mixture of Student-t densities. Note that when one substitutes for the weight Withe value Wi= 1 in Equations 8– 10, then one is back in the case of a regular EM algorithm (without IS weighting). In our case the L-th expectation step for the mixture of Student-tdensities is specified as follows: ˜zi h≡Ehzi hθi, ζ =ζ(L−1) i=tk(θi|µh,Σh, νh)ηh PH j=1 tk(θi|µj,Σj, νj)ηj ,(4) g z/wi h≡E"zi h wi hθi, ζ =ζ(L−1)#= ˜zi h k+νh ρi h+νh ,(5) ξi h≡Ehlog wi hθi, ζ =ζ(L−1) i= ="log ρi h+νh 2!−ψk+νh 2#˜zi h+log νh 2−ψνh 2(1 −˜zi h),(6) δi h≡E"1 wi hθi, ζ =ζ(L−1)#=k+νh ρi h+νh ˜zi h+ (1 −˜zi h),(7) Nalan Ba¸st¨ urk, Lennart Hoogerheide, Anne Opschoor, Herman K. van Dijk 13 data. Even if the ‘old’ candidate is not a good approximation to the posterior for the updated data, it may suffice to perform an update using the IS-weighted EM algorithm, keeping the number Hof Student-tcomponents the same. If the resulting quality is still below a desired level, then one can start the MitISEM algorithm for the updated data, adding components until convergence. Note that the IS-weighted EM algorithm of MitISEM is much more suited to perform (either small or large) adaptations than the AdMit method, since in the MitISEM method all Student-tcomponents are updated. Suppose that the MitISEM candidate is optimized for the data until time Tand the data set now includes observations upto time T+τ(τ= 1,2, . . .). Define y1:T+τ={y1, . . . , yT+τ}. For the updated data until T+τthe sequential MitISEM steps are as follows: Algorithm 2. The sequential MitISEM approach for obtaining a candidate density for the posterior density for data y1:T+τ: (1) Compute CoVr T+τ, the CoV value (Coefficient of Variation of the IS weights) that is based on the posterior density kernel for data y1:T+τand the current, reused candidate density. (2) Compare CoVr T+τwith CoVT, the CoV value for the same candidate and the posterior for data y1:T(the data set at the last time when the candidate was updated). If the change is below a certain threshold (10%), stop. Otherwise go to step (3). (3) Run the IS-weighted EM algorithm with the current mixture of HStudent-tdensities as starting values. Sample from the new distribution (with the same number of components H) and compute IS weights and the corresponding CoVu T+τ, the CoV value with only an EM update. Since the IS-weighted EM algorithm updates all mixture components, it can easily perform a useful shift of the candidate density. (4) Compare CoVu T+τand CoVr T+τ. If the change of quality is below a certain threshold (10%), stop. Otherwise go to step (5). (5) Iterate on the number of components until the CoV value has converged. Note that the change in CoV value can be substantial if the new observation yT+1 is an outlier. Steps (3) and (5) in that case will typically be required. A Student-tcomponent is deleted from the mixture if the weight of this component is too small, i.e., if the probability of one component is close to zero. The default tolerance for the required mixing probability is 0, and a mixture component is removed from the MitISEM approximation if it has a 0 probability. Hence the number of Student-tcomponents is not necessarily monotonically increasing over time. This criterion for the removal of a mixture component can be altered by the user through an optional input to the function MitISEM. Further, in step (2) CoVr T+τis compared with CoVTrather than the CoV for the posterior at time yT+τ−1, since in the latter case a series of small increases of the CoV may eventually lead to a much worse candidate density. 3. Applications in three domains 14 The R package MitISEM In the following subsections, we make use of the MitISEM and the sequential MitISEM methods in order to deal with distributions that have non-elliptical density contours in three domains of applications: (i) Approximating a specific class of well-known, non-elliptical densities in Section 3.1. Here, we continue to analyze the conditionally normal density of Gelman and Meng (1991), which can have non-elliptical, and even distinctly bi-modal, shapes in the joint density depending on specific values of the density function parameters. Note that this is not a posterior density. (ii) Approximating posterior densities of a class of models popular in financial econometrics in Section 3.2. We consider a standard GARCH model and a mixture GARCH model (for S&P 500 data), which are classes of models extensively used in financial practice. We further consider an instrumental variables (IV) model and compare the approximation performance using MitISEM candidate with the griddy Gibbs sampler in Ritter and Tanner (1992). (iii) Approximating model probabilities using the concept of predictive likelihoods in Section 3.3. We consider a mixture GARCH model and an IV model. The latter one using income-education data. Both GARCH and IV models yield non-elliptical distributions for posterior and predictive densities. For cases (ii) and (iii) obtaining a good candidate density, for example for importance sampling or the independence chain Metropolis-Hastings method, is crucial for Bayesian estimation of the model parameters as well as model probabilities. For all cases, we summarize the application of the Rpackage MitISEM, and compare the performance of the MitISEM method with a single, relatively ‘naive’ Student-tcandidate density. The ‘naive’ density is still an adapted density, obtained by the IS weighted EM algorithm, with degrees of freedom set as 1. The fat tails of the ‘naive’ candidate density (due to the low degrees of freedom parameter 1) reduce the probability that relevant parts of the target density are not covered by the ‘naive’ candidate. Still, despite the optimized mode and scale, this density is expected to lead to a relatively poor approximation in particular for multi-modal target densities. In Section 3.2.2, we also compare the MitISEM method with the AdMit method implemented in Ardia et al. (2017), which also aims to construct a candidate density as a mixture of Student-t densities, in terms of approximation accuracy and computing time. 3.1. Approximating densities: The Gelman-Meng function We continue the use of the MitISEM algorithm to approximate the Gelman-Meng density presented in Section 2.4.1. Here we compare the MitISEM approximation’s speed and accuracy with a ‘naive’ approximation of the Gelman-Meng density. Next, we show for the case of a ‘distinctly’ bi-modal Gelman-Meng density, the failure of a simple Gibbs sampler to yield accurate results even when the sample is relatively large. Gelman-Meng density with a banana shape For the Gelman-Meng target density, we set A= 1, B = 0, C1=C2= 3 in Equation 12, where this parameter setting leads to a non-elliptical banana shape in the target kernel, as shown in Nalan Ba¸st¨ urk, Lennart Hoogerheide, Anne Opschoor, Herman K. van Dijk 15 the top-left panel in Figure 3. We compare the performance of the MitISEM approach with a ‘naive’ density. We note that the MitISEM approximation to the target density is obtained as before, using the target density function in Section 2.4.1 and function MitISEM: R> set.seed(1111) R> mu0 <- c(3,4) R> App.GM <- MitISEM(KERNEL = GelmanMeng, mu0 = mu0) The output of the function MitISEM is a list. The first component is CV, a vector containing the coefficient of variation at each step of the adaptive fitting procedure. The second component is mit, a list consisting of the modes (mu), scale matrices (Sigma), degrees of freedom parameters (df) and mixing probabilities (p) of the mixture of Student-tdensities constructed by MitISEM. The third component is summary, a data frame containing information on the adaptive fitting procedure, which will be explained in the GARCH example. Similarly, the ‘naive’ approximation results are obtained by restricting the candidate density in the MitISEM approximation to have a single multivariate Student-tcomponent where the degrees of freedom parameter is 1 by default, where only the mode and scale are optimized in the MitISEM algorithm: R> control <- list(optim.df = FALSE, Hmax = 1) R> app.Naive <- MitISEM(KERNEL = GelmanMeng, mu0 = mu0, control = control) After obtaining the MitISEM approximation, the Student-tcomponents of the obtained candidate can be plotted as follows: R> mit <- App.GM$mit R> x1 <- seq(-2,6,0.05) R> x2 <- seq(-2,7,0.05) R> H <- length(mit$p) R> Mitcontour <- function(x1, x2, mit, log=FALSE){ + dmvgt(cbind(x1, x2), mit = mit, log = log) + } R> for (h in 1:H){ + mit.h <- mapply(function(x)(as.matrix(x)[h,]), mit, + SIMPLIFY = FALSE) + mit.h$mu = matrix(mit.h$mu, nrow = 1) + mit.h$Sigma = matrix(mit.h$Sigma, nrow = 1) + it.h$p = 1 + z <- outer(x1, x2, FUN = Mitcontour, mit = mit.h) + contour(x1, x2, z, col = h, lty = h, labels = "", add = (h!=1), + xlab = expression(x[1]), ylab = expression(x[2]), + main = "MitISEM approximation") + } R> legend("topright", paste("component ", 1:H), lty = 1:H, col = 1:H, + bty = ' n ' ) For both approximations we use N= 104draws to form the mixture components. Figure 3 shows the target density kernel and approximations by the naive and MitISEM approximations, the computational time and CoV measures for both approximations. The naive 16 The R package MitISEM Student-tdensity captures only one mode of the target density while the MitISEM approximation captures the banana shape in the target kernel, with 4 components. The accuracy measure, the coefficient of variation (CoV) of the importance weights, is substantially different for the two methods: the CoV is more than six times lower for the MitISEM candidate. −2 0 2 4 6 −2 0 2 4 6 x1 x2 −2 0 2 4 6 −2 0 2 4 6 x1 x2 component 1 component 2 component 3 component 4 target kernel composition of the MitISEM candidate −2 0 2 4 6 −2 0 2 4 6 x1 x2 −2 0 2 4 6 −2 0 2 4 6 x1 x2 MitISEM candidate (4 components) Naive candidate CoV: 0.33, time: 17.07 seconds CoV: 2.28, time: 1.20 seconds Figure 3: Banana shaped target density kernel, approximation by the naive Student-tdensity (achieved by step 0 and step 1 of the MitISEM algorithm), and optimal MitISEM candidate for the Gelman-Meng density with A= 1, B = 0, C1=C2= 3. Gelman-Meng density with a distinctly bi-modal shape In this subsection, we simulate draws from a Gelman-Meng distribution using the Metropolis- Hastings algorithm with the MitISEM candidate, and compare these simulations with the simulated draws from the Gibbs sampler. We specifically show that the simulated points using the Gibbs sampler fail to cover the whole domain of the Gelman-Meng density. For this comparison, we consider a Gelman-Meng density in Equation 12 with two distinct modes, Nalan Ba¸st¨ urk, Lennart Hoogerheide, Anne Opschoor, Herman K. van Dijk 17 −2 0 2 4 6 8 10 −2 0 2 4 6 8 10 x1 x2 ●Gibbs sampler draws draws from MitISEM approximation −2 0 2 4 6 8 10 −2 0 2 4 6 8 10 x1 x2 ●Gibbs sampler draws draws from MitISEM approximation Figure 4: Comparison of simulations using the MitISEM approximation and the Gibbs sampler for Gelman-Meng density with A= 1, B = 0, C1=C2= 6. The left panel shows 500 draws from both samplers, the right panel shows 10000 draws from both samplers. with parameters A= 1, B = 0, C1=C2= 6. Figure 4shows simulated points from this density using the MitISEM approximation and using the Gibbs sampler, based on 500 draws (left panel) and 10000 draws (right panel). The MitISEM approximation to the Gelman-Meng density is obtained using only 1000 draws. Shaded areas in the figure correspond to the high-density regions of the Gelman-Meng function. The left panel of Figure 4shows that using the MitISEM candidate and a relatively small number of simulations, we obtain points from both modes of the density. In the left panel of Figure 4, the Gibbs sampler fails to ‘cover’ the second mode. Note that the MitISEM approximation is obtained using merely 1000 draws for the approximation. The MitISEM approximation would become even more accurate if a larger number of draws would be used for density approximation. In this case, the outperformance of the MitISEM method compared to the Gibbs sampler would be even more pronounced. From this comparison, we conclude that simulated data points and inference based on these simulations are erroneous using the Gibbs sampler even for a large number of draws from the density. 3.2. Approximating posterior densities: GARCH and IV models In this subsection the MitISEM approach is applied to the posterior density of two GARCH models and an Instrumental Variable (IV) model using data from Card (1995). The standard GARCH model and its extensions may adequately capture changing volatility patterns, but the likelihood function, hence the posterior density under an uninformative prior may have non-elliptical shapes (Zivot 2009). For the applications of GARCH models we use the S&P 500 index percentage returns (100 times the change of the closing price) from January 2 1998 to December 26 2002. Figure 5shows the returns data and their histogram. These data are characterized by changing volatility patterns as well as fat tails. For this reason, several extensions of the standard GARCH models are proposed to capture such data 18 The R package MitISEM patterns. 0 200 400 600 800 1000 1200 −6 −4 −2 0 2 4 6 observations S&P 500 % returns returns Frequency −6 −4 −2 0 2 4 6 0 10 20 30 40 50 Figure 5: Daily log-returns of the S&P 500 index for the period from January 2 1998 to December 26 2002. Approximating posterior densities: A standard GARCH(1,1) model We first illustrate the use of the MitISEM approach for the Bayesian estimation of the standard GARCH model (Bollerslev 1986) for the S&P500 data. An extended two-component Gaussian Mixture GARCH (1,1) model (Aus´ın and Galeano 2007), which possibly leads to more irregular posterior densities, is considered afterwards. The standard GARCH(1,1) model for a time series yt(t= 1,2, . . . , T) is given by yt=µ+phtεt,(13) ht=ω+α(yt−1−µ)2+βht−1,(14) εt∼N(0,1) i.i.d. (15) with htthe conditional variance of ytgiven the information set It−1={yt−1, yt−2, yt−3, . . .}. In addition, h0is treated as a known constant, set as the sample variance of the time series yt, which will consist of daily stock index (log) returns in this example. We restrict ω > 0, α ≥0 and β≥0 to ensure positivity of ht. We specify flat priors for the model parameters. Moreover, we truncate ωand µsuch that these have proper (noninformative) priors. For the k= 4 dimensional parameter vector θ= (ω, β, α, µ), we have a uniform prior on [−1,1] ×(0,1] ×[0,1) ×[0,1) with α+β < 1 which implies covariance stationarity. The posterior density for the GARCH(1,1) model is implemented as follows: R> prior.GARCH<-function(omega, beta, alpha, mu, log = TRUE){ + c1 <- (omega > 0 & omega < 1 & beta >= 0 & alpha >= 0) + c2 <- (beta + alpha < 1) + c3 <- (mu > -1 & mu < 1) + r1 <- c1 & c2 & c3 Nalan Ba¸st¨ urk, Lennart Hoogerheide, Anne Opschoor, Herman K. van Dijk 19 + r2 <- rep.int(-Inf, length(omega)) + r2[r1==TRUE] <- 0 + if (!log) + r2 <- exp(r2) + cbind(r1, r2) + } R> post.GARCH <- function(theta, data, h1, log = TRUE){ + if (is.vector(theta)) + theta <- matrix(theta, nrow = 1) + omega <- theta[,1] + beta <- theta[,2] + alpha <- theta[,3] + mu <- theta[,4] + N <- nrow(theta) + pos <- 2:length(data) + prior <- prior.GARCH(omega = omega, beta = beta, alpha = alpha, + mu = mu) + d <- rep.int(-Inf, N) + for (i in 1:N){ + if (prior[i,1] == TRUE){ + h <- c(h1, omega[i] + alpha[i] * (data[pos-1] - mu[i])^2) + for (j in pos) + h[j] <- h[j] + beta[i] * h[j-1] + tmp <- dnorm(data[pos], mu[i], sqrt(h[pos]), log = TRUE) + d[i] <- sum(tmp) + prior[i,2] + } + } + if (!log) d <- exp(d) + as.numeric(d) + } The function prior.GARCH is coded outside the kernel function to render the program more readable and flexible. The function prior.GARCH tests whether the constraints are fulfilled, and outputs a (N×2) matrix whose first column indicates if the constraints are satisfied, and the second column returns the value of the prior at the corresponding point. Given the data vector/matrix and an initial point satisfying the prior parameter constraints, the MitISEM approximation is obtained. Posterior parameter draws can then be obtained using the Metropolis-Hastings or rejection sampling algorithm given the candidate constructed by MitISEM, or one can estimate posterior moments using importance sampling. In order to use the MitISEM candidate for importance sampling or the Metropolis-Hastings algorithm, one can make use of the function AdMitIS or AdMitMH provided by the Rpackage AdMit, since these functions just perform IS or MH using a given candidate that is a mixture of Student-t distributions. Specifically, the mixture of Student-tdistribution obtained from the MitISEM candidate is used as an input, mit, for functions AdMitIS or AdMitMH for posterior inference. An Rcode to obtain posterior parameters of the GARCH model is provided below, where we use the Rpackage tseries,Trapletti and Hornik (2017), to extract S&P 500 data. 20 The R package MitISEM R> require("tseries") R> require("AdMit") R> prices <- as.vector(get.hist.quote("^GSPC", quote = "AdjClose", + start = "1998-01-02", end = "2002-12-26")) R> data <- 100 * (prices[-1] - prices[-length(prices)]) / + (prices[-length(prices)]) R> plot(data, xlab = "observation", ylab = "S&P500 % returns") R> hist(data, xlab = "returns") R> theta <- c(0.08, 0.86, 0.02, 0.03) R> names(theta) <- c("omega", "beta", "alpha", "mu") R> h1 <- var(data); R> set.seed(1111) R> app.GARCH <- MitISEM(KERNEL = post.GARCH, mu0 = theta, h1 = h1, + data = data, control = list(trace = TRUE)) 1 1 BFGS 0.76 1.1352420 1.135242e-04 2 1 IS-EM 28.70 0.7567956 7.567956e-05 3 2 IS-EM 57.91 0.4105256 4.105256e-05 4 3 IS-EM 56.76 0.3864224 3.864224e-05 R> IS.GARCH <- AdMitIS(N = 10e4, KERNEL = post.GARCH, + mit = app.GARCH$mit, data = data, h1 = h1) R> print(IS.GARCH) $ghat [1] 0.08884915 0.84851733 0.10637618 0.03354568 $NSE [1] 1.158643e-04 1.133241e-04 7.695703e-05 1.187978e-04 $RNE [1] 0.6974687 0.7058110 0.7292880 0.8363404 The summary output of the function MitISEM is a data frame containing information on the adaptive fitting procedure: His the number of Student-tcomponents; METHOD indicates whether the IS-weighted EM algorithm has been used to optimize the candidate (where the BFGS method has been used to compute the mode of the target density); TIME gives the computing time required for this optimization; CV gives the coefficient of variation of the importance sampling weights; std.dev. gives the standard deviation of the IS weights. The output of the function AdMitIS is a list. The first component is ghat, the importance sampling estimator ˆ G=PN i=1 WiG(θi) PN i=1 Wiof the property of interest E[G(θ)], which is in our case the posterior mean of the parameters. The second component is NSE, a vector containing the numerical standard errors (i.e., the standard deviation of the estimates that can be expected if the simulations were to be repeated) of the components of ghat. The third component is RNE, a vector containing the relative numerical efficiencies of the components of ghat (i.e., the ratio between the estimated variance of a hypothetical estimator based on direct sampling and the importance sampling estimator’s estimated variance with the same number of draws). RNE is an indicator of the efficiency of the chosen importance density; if target and importance Nalan Ba¸st¨ urk, Lennart Hoogerheide, Anne Opschoor, Herman K. van Dijk 21 densities coincide, RNE equals one, whereas a very poor importance density will have a RNE close to zero. Both NSE and RNE are estimated by the method given in Geweke (1989). For estimating E[G(θ)] the Ncandidate draws are approximately as ‘valuable’ as RNE ×N independent draws from the target would be. The MitISEM approximation of the posterior density consists of 3 Student-tcomponents. The low CoV values and the high RNE values show that the MitISEM candidate approximates the posterior density accurately. Approximating posterior densities: A mixture GARCH(1,1) model In this subsection the MitISEM approach is applied to the non-elliptical posterior density in the two-component Gaussian Mixture GARCH (1,1) model of Aus´ın and Galeano (2007). For the Bayesian estimation of this model, Aus´ın and Galeano (2007) propose a griddy Gibbs sampler (Ritter and Tanner 1992), since the recursive structure of the likelihood in GARCH- type models implies that a regular Gibbs sampling approach is not feasible. The griddy Gibbs sampler is known to be very slow. As an alternative we use importance sampling with a candidate density resulting from the MitISEM algorithm, and compare the performance of the MitISEM candidate density with the naive Student-tcandidate density and a candidate obtained from the AdMit method. The two-component Gaussian mixture GARCH(1,1) model for the returns yt(t= 1,2, . . . , T) is given by yt=µ+phtεt,(16) ht=ω+α(yt−1−µ)2+βht−1,(17) εt∼(N(0, σ2) with probability ρ, N(0, σ2/λ) with probability 1 −ρ,(18) with htthe conditional variance of ytgiven the information set It−1={yt−1, yt−2, yt−3, . . .}. In addition, 0 <λ<1, and σ2≡1/(ρ+ (1 −ρ)/λ) so that var(εt) = 1; h0is treated as a known constant, set as the sample variance of the return series. We restrict ω > 0, α ≥0 and β≥0 to ensure positivity of ht. We follow Aus´ın and Galeano (2007) by imposing the prior restriction 0.5<ρ<1, so that it is ensured that the state with smaller variance has larger probability than the state with larger variance. The mixture distribution in (18) has fatter tails than a Gaussian distribution. We follow Aus´ın and Galeano (2007) also in specifying flat priors for the model parameters. Moreover, we truncate ωand µsuch that these have proper (non-informative) priors. For the k= 6 dimensional parameter vector θ= (ω, λ, β, α, ρ, µ), we have a uniform prior on (0,1] ×(0,1) ×[0,1) ×[0,1) ×(0.5,1] ×[−1,1] with α+β < 1 which implies covariance stationarity. The posterior density for the Gaussian mixture GARCH(1,1) model is implemented as follows: R> prior.mGARCH<-function(omega, lambda, beta, alpha, rho, mu, + log = TRUE){ + c1 <- (omega > 0 & omega < 1 & beta >= 0 & alpha >= 0) + c2 <- (beta + alpha< 1) + c3 <- (lambda >= 0 & lambda <= 1) + c4 <- (rho>0.5 & rho<1) 22 The R package MitISEM + c5 <- (mu>-1 & mu<1) + r1<-c1&c2&c3&c4&c5 + r2 <- rep.int(-Inf, length(omega)) + tmp <- log(2) + r2[r1==TRUE] <- tmp + if (!log) + r2 <- exp(r2) + cbind(r1, r2) + } R> post.mGARCH <- function(theta, data, h1, log = TRUE){ + if (is.vector(theta)) + theta <- matrix(theta, nrow = 1) + omega <- theta[,1] + lambda <- theta[,2] + beta <- theta[,3] + alpha <- theta[,4] + rho <- theta[,5] + mu <- theta[,6] + N <- nrow(theta) + pos <- 2:length(data) + prior <- prior.mGARCH(omega = omega, lambda = lambda, + beta = beta, alpha = alpha, rho = rho, mu = mu) + d <- rep.int(-Inf,N) + for (i in 1:N){ + if (prior[i,1] == TRUE){ + h <- c(h1, omega[i] + alpha[i] * (data[pos-1]-mu[i])^2) + for (j in pos){ + h[j] <- h[j] + beta[i] * h[j-1] + } + sigma <- 1 / (rho[i] + ((1-rho[i]) / lambda[i])) + tmp1 <- dnorm(data[pos], mu[i], sqrt(h[pos] * sigma), + log = TRUE) + tmp2 <- dnorm(data[pos], mu[i], sqrt(h[pos] * sigma / + lambda[i]), log = TRUE) + tmp <- log(rho[i] * exp(tmp1) + (1 - rho[i]) * exp(tmp2)) + d[i] <- sum(tmp) + prior[i,2] + } + } + if (!log) + d <- exp(d) + as.numeric(d) + } Given the data vector/matrix data the MitISEM approximation is calculated starting from an initial point satisfying the prior parameter constraints. Posterior parameter draws (or appropriately weighted candidate draws) are then obtained using the Metropolis-Hastings algorithm (or importance sampling) given the candidate constructed by MitISEM. Nalan Ba¸st¨ urk, Lennart Hoogerheide, Anne Opschoor, Herman K. van Dijk 29 β π σ2 11 ρ σ2 22 Time True values 0.73 0.06 0.21 -0.43 0.17 Posterior means and standard deviations Griddy Gibbs Mean 0.13 0.05 0.15 0.10 0.16 2728 Std. dev. 0.09 0.02 0.01 0.10 0.01 MH Mean 0.76 0.06 0.22 -0.44 0.17 64 Std. dev. 0.33 0.02 0.07 0.22 0.01 IS Mean 0.76 0.06 0.21 -0.44 0.16 62 Std. dev. 0.30 0.02 0.06 0.20 0.01 Table 3: Estimated posterior means and standard deviations of parameters for simulated IV data based on griddy Gibbs sampler and MH and IS algorithms using MitISEM approximation. MitISEM candidate is based on 10000 draws. MH and griddy Gibbs results are based on 10000 posterior and 10000 burn-in draws. IS results are based on 10000 draws. For the griddy Gibbs sampler we use 200 grid points for each parameter. The last column of the table reports the elapsed time for each posterior sampler in minutes. For IS and MH algorithms we report total time, including the time required to construct the MitISEM candidate. -0.05 0.00 0.05 0.10 -0.5 0.0 0.5 1.0 1.5 p b griddy Gibbs MH -0.5 0.0 0.5 -0.5 0.0 0.5 1.0 1.5 r b griddy Gibbs MH Figure 7: Parameter (β, π) and (β, ρ) draws for simulated IV data based on the griddy Gibbs sampler and the MH algorithm using MitISEM approximation. Horizontal and vertical lines are the true parameter values. Posterior results are obtained as in Table 3. 30 The R package MitISEM 1000 2000 3000 4000 5000 -0.5 0.0 0.5 1.0 1.5 2.0 griddy Gibbs posterior draw b p s1 2rs2 2 1000 2000 3000 4000 5000 -0.5 0.0 0.5 1.0 1.5 2.0 MH posterior draw b p s1 2rs2 2 Figure 8: Posterior draws of all parameters for simulated IV data based on the griddy Gibbs sampler and the MH algorithm using MitISEM approximation. Posterior results are obtained as in Table 3. college proximity data, and transform these into residuals after regression on the exogenous covariates in the dataset, which is equivalent to integrating out the corresponding coefficients under a flat prior. Similar to the simulation study, the griddy Gibbs sampling results are different from the Metropolis-Hastings and importance sampling results using the MitISEM candidate, as seen in Table 4. Here, posterior draws from the correlation coefficient ρare concentrated around 0.12 with again a relatively small standard deviation. This small standard deviation confirms that the griddy Gibbs sampler fails to cover the whole domain of the posterior density and that the MitISEM approximation substantially improves the simulation inference for these data. 3.3. Approximating model probabilities using the concept of predictive likelihoods In this subsection we show how the candidate density obtained by the MitISEM method can be used to accurately calculate a model’s predictive likelihood. The calculation of model probabilities can be based on the models’ marginal likelihoods or the predictive likelihoods, where the former are problematic under non-informative priors on parameters that only occur in one of the models, in the sense that the ‘smaller’ model may be favored even if the ‘larger’ model is the true Data Generating Process (DGP) (Bartlett 1957). The MitISEM package provides functions to calculate the marginal or predictive likelihood of a model given its posterior density kernel and a candidate density obtained by the MitISEM method. The reason is that the computation of marginal or predictive likelihoods is an important ingredient of many Bayesian analyses. The predictive likelihood of a model M1is obtained by splitting the data y= (y1,...yT) into y∗= (y1,...ym) and ˜y= (ym+1,...yT) (Gelfand and Dey 1994;Eklund and Karlsson 2007): p(˜y|y∗, M1) = Zp(˜y|θ1, y∗, M1)p(θ1|y∗, M1)dθ1,(21) to be extracted using the authors’ codebook in the website. The Rcode to prepare Card (1995) data for the example IV model is supplied in replication scripts. Nalan Ba¸st¨ urk, Lennart Hoogerheide, Anne Opschoor, Herman K. van Dijk 31 β π σ2 11 ρ σ2 22 Time Griddy Gibbs Mean 0.11 0.05 0.15 0.12 0.16 23.7 Std. dev. 0.09 0.02 0.01 0.10 0.01 MH Mean 0.73 0.07 0.21 -0.43 0.17 1.1 Std. dev. 0.28 0.02 0.05 0.20 0.00(∗) IS Mean 0.73 0.06 0.21 -0.43 0.17 1.1 Std. dev. 0.28 0.02 0.05 0.20 0.00(∗) Table 4: Estimated posterior means and standard deviations of parameters for the IV model for Card (1995) data obtained using the griddy Gibbs sampler, Metropolis-Hastings algorithm based on the MitISEM candidate and importance sampling based on the MitISEM candidate. MitISEM candidate is based on 104draws. MH and griddy Gibbs results are based on 5000 posterior and 5000 burn-in draws. IS results are based on 10000 draws. For the griddy Gibbs sampler we use 200 grid points for each parameter. The last column of the table reports the elapsed time for each posterior sampler in minutes. For IS and MH algorithms we report total time, including the time required to construct the MitISEM candidate. For values indicated by (∗), the standard deviation is 0.0044 at the 4-digit level. which is the marginal likelihood if we consider ˜yas ‘the data’ and p(θ1|y∗, M1), the exact posterior density, i.e., density including the normalizing constant, and the posterior kernel, after observing y∗, as the prior. Using Bayes’ rule for this exact posterior density p(θ1|y∗, M1) and substituting into Equation 21 yields p(˜y|y∗, M1) = Rp(y|θ1, M1)p(θ1|M1)dθ1 Rp(y∗|θ1, M1)p(θ1|M1)dθ1 ,(22) where p(θ1|M1) is the prior on model parameters θ1for model M1. Hence this predictive likelihood is the ratio of the marginal likelihood for all observations over the marginal likelihood for the first part of the data. The integral in Equation 22 can be evaluated by numerical integration using θ1draws obtained from the Metropolis-Hastings algorithm in package AdMit using the MitISEM candidate density. Model probability for M1is then calculated using the posterior density in Equation 22 p(M1|y) = p(M1|˜y, y∗) = p(M1|y∗)p(˜y|y∗, M1) p(˜y|y∗)∝p(M1|y∗)p(˜y|y∗, M1),(23) where (p(˜y|y∗))−1, which is independent of the model M1, is the normalizing constant and p(M1|y∗) is the prior model probability conditional on prior data points y∗. In practice, this prior model probability is often defined independent of prior data points and ensures equal prior model weights. Approximating model probabilities using predictive likelihood: A mixture GARCH(1,1) model As a first illustration, we apply the model in (16)–(18) to S&P 500 data and perform the simulation-based computation of the predictive likelihoods. We also compare the performance of the MitISEM candidate with a ‘naive’ candidate. The first half of the observations are 32 The R package MitISEM regarded as the ‘training sample’ y∗= (y1,...ym). Predictive likelihood calculation using the MitISEM approximation is implemented as: R> library("MitISEM") R> library("tseries") R> source("PostmGARCH.R") R> prices <-as.vector(get.hist.quote("^GSPC", quote = "AdjClose", + start = "1998-01-02", end = "2002-12-26")) R> data <- 100 * (prices[-1] - prices[-length(prices)]) / + (prices[-length(prices)]) R> data.ss <- data[1:626] R> h1 <- var(data) R> mu0 <- c(0.08, 0.37, 0.86, 0.03, 0.82, 0.03) R> names(mu0) <- c("omega", "lambda", "beta", "alpha", "p", "mu") R> set.seed(1234) R> mit.ss <- MitISEM(KERNEL = post.mGARCH, mu0 = mu0, data = data.ss, + h1 = h1, control=list(trace=TRUE))$mit R> mit.fs <- MitISEM(KERNEL = post.mGARCH, mu0 = mu0, data = data, + h1 = h1, control=list(trace=TRUE))$mit R> PL.mGARCH <- PredLik(N,mit.fs, mit.ss, post.mGARCH, data, data.ss, h1=h1) where the posterior density function for the mixture of GARCH(1,1) is defined as in Section 3.2.2,y.ss is the training sample of 626 observations for predictive likelihood calculations, the initial variance h1 of the GARCH model is defined as the sample variance of the data, initial parameters are defined as mu0 and predictive likelihood calculation is based on N draws. In order to calculate the accuracy of the estimates, we replicate the predictive likelihood calculation 50 times. Table 5shows simulation results where the average predictive likelihoods and Numerical Standard Errors are calculated from 50 replications. The candidates for all cases are calculated using 104draws, and the estimated predictive likelihood values are based on 103draws, where the latter was done to decrease the computing time of the 50 repetitions. # t components Predictive likelihood Training sample Full sample Mean NSE 4 3 1.68 ×10−470 1.28 ×10−472 Table 5: Approximation and predictive likelihood for the mixture of GARCH model. Candidate approximations and posterior results are based on 104and 103draws, respectively. Mean and Numerical Standard Error (NSE) for each estimate are based on 50 replications. The MitISEM candidate consists of four and three mixture components for the training sample and the full sample, respectively, indicating highly non-elliptical posterior shapes for both datasets. Despite these irregularities in the posterior densities, the small NSE reported in Table 5shows that, even with the relatively small number of posterior draws, calculated predictive likelihoods for this model are quite accurate given the MitISEM approximation to the posterior density. Nalan Ba¸st¨ urk, Lennart Hoogerheide, Anne Opschoor, Herman K. van Dijk 33 Computing a sequence of predictive likelihoods using sequential MitISEM We next apply the sequential MitISEM algorithm to the two-component mixture GARCH model with the S&P 500 data. Sequential MitISEM is used to efficiently construct a series of candidates that approximate posteriors for increasing data sets, where the candidate can be used for estimation of posterior moments, marginal likelihoods or predictive likelihoods. In this example we consider the latter. We use the first half of the observations as the training sample y∗(for the marginal likelihood in the denominator of the predictive likelihood in Equation 22). At each time t= 1204,...,1252, the predictive likelihood is computed while the training sample y∗is kept fixed. Such a sequence of updated predictive likelihoods could be used in an application of Bayesian model averaging (BMA), combining forecasts from several models at each time t= 1204,...,1252 by weighting these with the estimated model probabilities. Once the posterior kernel is specified, the sequential MitISEM approximations can be obtained as follows: R> require("tseries") R> require("AdMit") R> prices <- as.vector(get.hist.quote("^GSPC", quote = "AdjClose", + start = "1998-01-02", end = "2002-12-26")) R> data <- 100 * (prices[-1] - prices[-length(prices)]) / + (prices[-length(prices)]) R> mu0 <- c(0.08, 0.37, 0.86, 0.03, 0.82, 0.03) R> names(mu0) <- c("omega", "lambda", "beta", "alpha", "rho", "mu") R> h1 = var(data) R> data.ss <- data[1:floor(length(data) / 2)] R> MitISEMapp.subsample <- MitISEM(KERNEL = post.mGARCH, mu0 = mu0, h1 = h1, + data = data.ss) R> control.seq <- list(T0 = 1203, tau = 1:20) R> app.mGARCH.SeqMitISEM <- SeqMitISEM(data, KERNEL = post.mGARCH, mu0 = mu0, + control.seq = control.seq, h1 = h1) Table 6presents the number of mixture components, CoV values and estimated predictive likelihoods for each sequential algorithm, and provides more details about the results of the sequential MitISEM algorithm. Note that for the calculation of predictive likelihoods in increased data samples, an ‘ad hoc’ MitISEM procedure would be applied 20 times, while the sequential MitISEM ‘adopts’ the candidate density only once for sample size 1208 and ‘extends’ the candidate density only once for sample size 1209. In the remaining time periods, the candidate is simply ‘reused’, with minimal computational time. Table 6shows that the MitISEM approximation using a subsample of the data is ‘reused’ 18 times, indication approximately 18 times speed gains compared to the standard MitISEM approximation for each sample. Similarly, one MitISEM candidate is only ‘adjusted’, again providing speed gains compared to employing the whole MitISEM algorithm for each subsample. Note that the CoV values remain low, so that the huge gains in computing time do not lead to a bad quality of the candidate distribution. Approximating model probabilities using predictive likelihood: An IV model As a third application of predictive likelihood approximations using the MitISEM algorithm, we consider the IV model in Equation 19 and Equation 20 with the Jeffreys prior for the Card 34 The R package MitISEM #Observations #t CoV Predictive likelihood 1204 3 0.98 3.76×10−435 1205 3 1.01 0.64×10−435 1206 3 0.95 0.83×10−436 1207 3 1.04 1.35×10−437 1208 6 0.99 2.36×10−438 1209 6∗0.72 3.57×10−439 1210 6 0.72 0.50×10−439 1211 6 0.72 1.04×10−440 1212 6 0.73 2.09×10−441 1213 6 0.85 3.93×10−442 1214 6 0.76 0.97×10−442 1215 6 0.76 1.27×10−443 1216 6 0.75 2.97×10−444 1217 6 0.81 0.75×10−444 1218 6 0.82 1.81×10−445 1219 6 0.72 1.17×10−446 1220 6 0.77 2.59×10−447 1221 6 0.73 2.22×10−448 1222 6 0.74 0.52×10−448 1223 6 0.74 1.43×10−449 Sequential MitISEM steps # reused 18 # adapted 1 # adapted and extended 1 Table 6: Predictive Likelihoods for the mixture GARCH model using sequential MitISEM. Candidate approximations and posterior results are based on 104and 103draws, respectively. #t denotes the number of Student-tcomponents in MitISEM approximation. (∗) indicates that the candidate density from the previous approximation is adapted. data on income and education described in Section 3.1. We define two models, one treating education as an endogenous explanatory variable (i.e., the IV model in Equation 19 and Equation 20, and the second model treating education as an exogenous explanatory variable (i.e., the simple linear regression model). The linear regression model is a nested model compared to the IV model in Equation 19 and Equation 20 with the parameter restriction ρ= 0 and posterior inference for the effect of education on income, β, in this case is based only on Equation 19. For a comparison of these two models under uninformative priors, we use the predictive likelihoods. The predictive probability of the null model (which assumes exogeneity) can be calculated using the Savage-Dickey Density Ratio (SDDR). Dickey (1971) shows that the Bayes factor can be calculated using a single model if the null model is a restricted version of the alternative model and the prior densities satisfy the condition that the prior for the restricted model equals the corresponding conditional prior (conditional upon satisfying the restriction) in the unrestricted model. Under that condition the model Nalan Ba¸st¨ urk, Lennart Hoogerheide, Anne Opschoor, Herman K. van Dijk 35 probabilities can be simplified to: p(M0|y) p(M1|y)=p(˜y|y∗, M0) p(˜y|y∗, M1) p(M0) p(M1)=p(ρ= 0 |˜y, y∗, M1) p(ρ= 0 |y∗, M1)×p(M0) p(M1),(24) hence the model probabilities can be calculated from the unrestricted model only, using draws from the marginal posterior density of the endogeneity parameter ρconditioning on the training sample and the full sample to compute p(ρ= 0 |˜y, y∗, M1) and p(ρ= 0 |y∗, M1) using kernel density estimates. We get these parameter draws from the Metropolis-Hastings sampler, using the MitISEM candidate and the AdMitMH function from the Rpackage AdMit. Then we calculate the predictive likelihoods using Equation 24, a random training sample consisting of 5% of the original data points, and using the ‘naive’ and the MitISEM approximations to the posterior density. The implementation of this predictive likelihood approach is straightforward using MitISEM: R> require("AdMit") R> load("dataIV.Rdata") R> data.fs <- dataIV R> set.seed(1234) R> mu0 <- c(0.8, 0.1, 0.5, 0, 0.5) R> pc.train = 0.05 R> N <- nrow(data.fs) R> M <- round(N * pc.train) R> data.ss <- data.fs[sample(1:N, M),] R> mit.fs <- MitISEM(KERNEL = post.IV, mu0 = mu0, df0 = 30, data = data.fs, + control = list(tol.pr = 0.02)) R> mit.ss <- MitISEM(KERNEL = post.IV, mu0 = mu0, df0 = 30, data = data.ss, + control = list(tol.pr = 0.02)) R> post.fs <- AdMitMH(N = N, post.IV, mit = mit.fs$mit, data = data.fs) R> post.ss <- AdMitMH(N = N, post.IV, mit = mit.ss$mit, data = data.ss) R> ind.post = (N / 5 + 1):N R> rho.fs <- post.fs$draws[ind.post,4] R> rho.ss <- post.ss$draws[ind.post,4] R> Pred.Lik <- density(rho.fs, from = 0, to = 0)$y[1] / density(rho.ss, + from = 0, to = 0)$y[1] We repeat the whole predictive likelihood estimation 20 times, with 20 different random seeds, so that also the random selection of the training sample and the approximation of the posterior for the training data are different each time. We specify equal prior probabilities p(M0) = p(M1) = 1 2. Table 7presents the details of the MitISEM and ‘naive’ density approximations to the posterior, together with the predictive likelihoods. First, the average number of Student-tcomponents is close to three in training samples and the full sample, indicating non-elliptical posterior shapes for this model. Hence a flexible candidate density, such as the MitISEM candidate, is motivated. Second, the obtained predictive likelihoods are more accurate, as indicated by relatively smaller NSE values of the resulting estimated posterior model probabilities, when the candidate density is obtained from the MitISEM method. Note that 0.09 may seem only slightly smaller than 0.10, but since in this case most of the variation is caused by the random selection of the training sample rather than the 36 The R package MitISEM finiteness of the number of candidate draws, the relative improvement of quality provided by the MitISEM candidate is still considerable. In examples with a fixed training sample, the relative outperformance of the MitISEM method is much stronger. MitISEM candidate Naive candidate CoV # t components CoV Full Sample 1.33 2.9 14.4 Training Sample 2.61 2.8 13.4 MitISEM candidate Naive candidate Mean NSE Mean NSE p(M0|y) 0.65 0.10 0.65 0.10 p(M1|y) 0.35 0.10 0.35 0.10 Table 7: Model probabilities (p(M0|y) and p(M1|y), for models without/with endogeneity) based on predictive likelihood Equation 24 using ‘naive’ and MitISEM approximations. ‘# t components’ denotes the average number of Student-tcomponents in the MitISEM candidate over the 20 repetitions. Mean, NSE and # tare also based on these 20 repetitions. The candidate and posterior results at each repetition are based on 104draws, respectively. For the Metropolis-Hastings method, we use a burn-in sample size of 2000. 4. Concluding remarks We presented the Rpackage MitISEM which provides an automatic algorithm for the approximation of a possibly non-elliptical target density using an adaptive mixture of Student-t densities as approximating or candidate density. The obtained approximation can, in particular, be used for Bayesian analysis of models with non-elliptical posterior shapes, and for Bayesian model comparison based on marginal or predictive likelihoods. The package also provides the ‘sequential MitISEM’ algorithm, which decreases the computational time substantially if the candidate density is used to assess posterior densities or model probabilities for increasing data samples, where the posterior density is updated using new observations. For Bayesian estimation, the package provides an efficient method to calculate marginal and predictive likelihoods, given a user-supplied kernel of a posterior density. We illustrated the approximation properties of the MitISEM algorithm using two different, distinctly non-elliptical, Gelman-Meng (Gelman and Meng 1991) densities. After that, we made use of posterior densities of two canonical econometric models: a mixture GARCH model for S&P 500 data and an IV model for the Card (1995) data. The posterior densities of these models are also characterized by non-elliptical shapes in which case Bayesian inference of model parameters and model probabilities, using importance sampling and Metropolis- Hastings algorithms, requires a flexible and appropriate candidate density. We illustrated the use of the MitISEM method for forming such a flexible candidate density, and showed that the obtained candidate can be used for efficient estimations of model parameters as well as predictive likelihoods. Finally, we showed that the ‘sequential MitISEM’ algorithm provides computational gains in subsequent estimation of the predictive likelihoods. In future research we will explore the possibility of parallelized computation for the different steps of Nalan Ba¸st¨ urk, Lennart Hoogerheide, Anne Opschoor, Herman K. van Dijk 37 the MitISEM method, so that one can utilize graphical cards or multi-core computer systems to substantially speed up the calculations. Acknowledgements During this project, Nalan Ba¸st¨ urk and Herman K. van Dijk were partially supported by the Netherlands Organisation for Scientific Research (NWO) Secondment Grant, number 400-07-703. Lennart Hoogerheide was partially supported by the NWO Veni Grant, number 451-09-028. We thank Tommi Tervonen and David Ardia for helpful comments. 38 The R package MitISEM References Ardia D, Hoogerheide LF, Van Dijk HK (2009). “Adaptive mixture of Student-tdistributions as a flexible candidate distribution for efficient simulation: The Rpackage AdMit.” Journal of Statistical Software,29(3), 1–32. Ardia D, Hoogerheide LF, Van Dijk HK (2017). AdMit: Adaptive mixture of Student-t distributions in R.Rpackage version 2.1.3, URL http://CRAN.R-project.org/package= AdMit. Aus´ın MC, Galeano P (2007). “Bayesian estimation of the Gaussian mixture GARCH model.” Computational Statistics & Data Analysis,51(5), 2636–2652. Bartlett MS (1957). “A comment on DV Lindley’s statistical paradox.” Biometrika,44(3–4), 533. Ba¸st¨ urk N, Hoogerheide LF, Opschoor A, Van Dijk HK (2017). MitISEM: Mixture of Student-tdistributions using importance sampling and expectation maximization in R. Version 1.1, URL http://cran.r-project.org/web/packages/MitISEM. Berger JO (1985). Statistical decision theory and Bayesian analysis. Springer-Verlag. Bollerslev T (1986). “Generalized autoregressive conditional heteroskedasticity.” Journal of Econometrics,31(3), 307–327. Bos CS, Mahieu RJ, Van Dijk HK (2000). “Daily exchange rate behaviour and hedging of currency risk.” Journal of Applied Econometrics,15(6), 671–696. Bowden RJ, Turkington DA (1990). Instrumental variables. Cambridge University Press. Capp´e O, Douc R, Guillin A, Marin JM, Robert CP (2008). “Adaptive importance sampling in general mixture classes.” Statistics and Computing,18(4), 447–459. Card D (1995). “Using geographic variation in college proximity to estimate the return to schooling.” In LN Christofides, EK Grant, R Swidinsky (eds.), Aspects of labour market behaviour: Essays in honour of John Vanderkamp, chapter 7. University of Toronto Press, Toronto. Dempster AP, Laird NM, Rubin DB (1977). “Maximum Likelihood from incomplete data via the EM algorithm.” Journal of the Royal Statistical Society B (Methodological), pp. 1–38. Dickey JM (1971). “The weighted likelihood ratio, linear hypotheses on normal location parameters.” The Annals of Mathematical Statistics,42(1), 204–223. Dr`eze JH (1976).“Bayesian limited information analysis of the simultaneous equations model.” Econometrica: Journal of the Econometric Society,44(5), 1045–1075. Dr`eze JH (1977). “Bayesian regression analysis using poly-t densities.” Journal of Econometrics,6(3), 329–354. Eklund J, Karlsson S (2007). “Forecast combination and model averaging using predictive measures.” Econometric Reviews,26(2–4), 329–363.