**I** just arXived a survey entitled *Bayesian computational tools* in connection with a chapter the editors of the *Annual Review of Statistics and Its Application* asked me to write. (A puzzling title, I would have used *Applications*, not *Application*. Puzzling journal too: endowed with a prestigious editorial board, I wonder at the long-term perspectives of the review, once “all” topics have been addressed. At least, the “non-profit” aspect is respected: $100 for personal subscriptions and $250 for libraries, plus a one-year complimentary online access to volume 1.) Nothing terribly novel in my review, which illustrates some computational tool in some Bayesian settings, missing five or six pages to cover particle filters and sequential Monte Carlo. I however had fun with a double-exponential (or Laplace) example. This distribution indeed allows for a closed-form posterior distribution on the location parameter under a normal prior, which can be expressed as a mixture of truncated normal distributions. A mixture of *(n+1)* normal distributions for a sample of size *n*. We actually noticed this fact (which may already be well-known) when looking at our leading example in the consistent ABC choice paper, but it vanished from the appendix in the later versions. As detailed in the previous post, I also fought programming issues induced by this mixture, due to round-up errors in the most extreme components, until all approaches provided similar answers.

## Archive for truncated normal

## Bayesian computational tools

Posted in Statistics with tags ABC model choice, academic journals, Annual Review of Statistics and Its Application, consistency, Laplace distribution, summary statistics, truncated normal on April 10, 2013 by xi'an## painful truncnorm

Posted in R, Statistics with tags Monte Carlo Statistical Methods, msm package, quantile function, R, rtnorm function, simulation, truncated normal on April 9, 2013 by xi'an**A**s I wanted to simulate truncated normals in a hurry, I coded the inverse cdf approach:

truncnorm=function(a,b,mu,sigma){ u=runif(1) u=qnorm(pnorm((a-mu)/sigma)*(1-u)+u*pnorm((b-mu)/sigma)) return(mu+sigma*u) }

instead of using my own accept-reject algorithm. Poor shortcut as the method fails when a and b are too far from μ

> truncnorm(1,2,3,4) [1] -0.4912926 > truncnorm(1,2,13,1) [1] Inf

**S**o I introduced a control (and ended up wasting more time than if I had used my optimised accept-reject version!)

truncnorm=function(a,b,mu,sigma){ u=runif(1) if (pnorm((b-mu)/sigma)-pnorm((a-mu)/sigma)>0){ u=qnorm(pnorm((a-mu)/sigma)*(1-u)+u*pnorm((b-mu)/sigma)) }else{ u=-qnorm(pnorm(-(a-mu)/sigma)*(1-u)-u*pnorm(-(b-mu)/sigma))} return(mu+sigma*u) }

**A**s shown by the above, it works, even when a=1, b=2 and μ=20. However, this eventually collapses as well and I ended up installing the msm R package that includes rtnorm, an R function running my accept-reject version. (This package was written by Chris Jackson from the MRC Unit in Cambridge.)

## R for dummies

Posted in Books, R, Statistics, University life with tags book reviews, CHANCE, constant, R, R course, R for dummies, R-bloggers, truncated normal, Université Paris Dauphine on October 20, 2012 by xi'an**J**ust saw this nice review of ** R for dummies**. And thought after this afternoon class that my students in the simulation course at Paris-Dauphine could clearly benefit from reading it! They in fact had a terrible time simulating a truncated normal distribution by accept-reject. As they could not get the notion of normalising constants… (Yes, indeed, this very truncated normal distribution!) Even the validity of simulating a normal variate until the truncation is satisfied was not obvious to them and they took forever to program the corresponding code. Anyway, I will certainly order the book to check for myself (after receiving

**to make sure I use the right vocabulary, even though it is a bit too light in the end…)! And write a review for CHANCE if it generates enough interest in doing so…**

*Genetics for dummies*## new typos in Monte Carlo Statistical Methods

Posted in Books, Statistics, University life with tags exponential distribution, gamma distribution, importance sampling, Metropolis-Hastings algorithms, Monte Carlo Statistical Methods, scale, simulation, truncated normal, typos on December 7, 2011 by xi'an**T**hanks to Jay Bartroff for pointing out those typos after teaching from ** Monte Carlo Statistical Methods**:

- On page 52, the gamma
*Ga(α, β)*distribution uses*β*as a rate parameter while in other places it is a scale parameter, see, e.g. eqn (2.2)*[correct, I must say the parameterisation of the gamma distribution is a pain and, while we tried to homogenise the notation with the second parameter being the rate, there are places like this where either the rate convention (as in the exponential distribution) or the scale convention (as in the generation) is the natural one...]*

- Still on page 52, in Example 2.20, truncated normals are said to be discussed after Example 1.5, but they’re not.
*[There is a mention made of constrained parameters right after but this is rather cryptic!]*

- On page 53, the ratio
*f/g*following the second displayed eqn is missing some terms_{α}*[or, rather, the equality sign should be a proportional sign]*

- Still on page 53, in eqn (2.11), the whole expression, rather than the square root, should be divided by 2
*[yes, surprising typo given that it was derived correctly in the original paper!]*

- On page 92, the exact constraint is that supp(g) actually needs only contain the intersection of supp(f) and supp(h), such as when approximating tail probabilities
*[correct if the importance sampling method is only used for a single function h, else the condition stands as is]*

- On page 94, f
_{Y}does not need that integral in the denominator*[correct, we already corrected for the truncation by subtracting 4.5 in the exponential]*

- On page 114, Problem 3.22, ω
_{i}is missing a factor of 1/n*[correct]*

- On page 218, in Example 6.24, P
_{00}=0*[indeed, our remark that P*_{xx}>0 should start with x=1. Note that this does not change the aperiodicity, though]

- On page 282, the
*log α*after the 2nd displayed equation should be*e*^{α}[correct, this was pointed out in a previous list of typos, but clearly not corrected in the latest printing!]

- On page 282, in the 5th displayed equation there are missing factors
*π(α’|b)/π(α*in rejection probability_{0}|b)*[actually, no, because, those terms being both proposals and priors, they cancel in the ratio. We could add a sentence to this effect to explain why, though.]*

- On page 634, the reference page for exponential distribution is mistakenly given as 99
*[wow, very thorough reading! There is an exponential distribution involved on page 99 but I agree this is not the relevant page...]*

## Simulation of truncated normal variables [reprint]

Posted in Statistics with tags accept-reject algorithm, simulation, truncated normal on July 24, 2009 by xi'an**A**s I do get on a very regular basis emailed requests for reprints of my 1995 Statistics and Computing paper “Simulation of truncated normal variables”, I decided to put a reprint of the original version on arXiv. As is (or was), i.e., in the T_{E}X format of 1992… I take the opportunity, though, to recall here that a fundamentally identical solution was proposed by John Geweke in the * Proceedings of the 23rd Symposium in the Interface* in 1991. Although I was unaware of this paper until John pointed it out to me, it is the one deserving the citation.