11.07.2015 Views

statisticalrethinkin..

statisticalrethinkin..

statisticalrethinkin..

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

8.3. EASY HMC: MAP2STAN 255mcmcpairs(post)R code8.8FIGURE 8.5 shows the resulting plot. is is a pairs plot, so it’s still a matrix of bivariate scatterplots. But now along the diagonal the smoothed histogram of each parameter is shown, alongwith its name. And in the lower triangle of the matrix, below the diagonal, the correlationbetween each pair of parameters is shown, with stronger correlations indicated by relativesize.For this model and these data, the resulting posterior distribution is quite nearly multivariateGaussian. e density for sigma is certainly skewed in the expected direction. Butotherwise the quadratic approximation does almost as well as Hamiltonian Monte Carlo.is is a very simple kind of model structure of course, with Gaussian priors, so an approximatelyquadratic posterior should be no surprise. Later, we’ll see some more exotic posteriordistributions.Overthinking: Stan messages. When you fit a model using map2stan, R will first translate yourmodel formula into a Stan language model. en it sends that model to Stan. e messages yousee in your R console are status updates from Stan. Stan first again translates the model, this timeinto C++ code. at code is then sent to a C++ compiler, to build an executable file is a specializedsampling engine for your model. en Stan feeds the data and starting values to that executable file,and if all goes well, sampling begins. You will see Stan count through the iterations. During sampling,you might occasionally see a scary looking warning something like this:Informational Message:The current Metropolis proposal is about to berejected because of the following issue: Error in function stan::prob::multi_normal_log(N4stan5Covariance matrixCovariance matrix is not positive definite.Covariancematrix(0,0) is 0:0. If this warning occurs sporadically, such as forhighly constrained variable types like covariance matrices, then thesampler is fine, but if this warning occurs often then your model may beeither severely ill-conditioned or misspecified.Severely ill-conditioned or misspecified? at certainly sounds bad. But rarely does this messageindicate a serious problem. As long as it happens only a handful of times, and especially if it onlyhappens during warmup, then odds are very good the chain is fine. You should still always check thechain for problems, of course. Just don’t panic when you see this message.8.3.4. Using the samples. Once you have samples in an object like post, you work withthem just as you’ve already learned to do. If you have the samples from the posterior and youknow the model, you can do anything: simulate predictions, compute differences betweenparameters, and calculate DIC.Actually, by default map2stan computes DIC for you. You can extract it’s value withDIC(m8.1stan), for example. DIC is also reported and broken down by its components onthe default show output for a map2stan model fit.show(m8.1stan)R code8.9map2stan model fitFormula:log_gdp ~ dnorm(mu, sigma)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!