## Typos in Chapters 6-7

**O**ver the weekend and during the R exams, I managed to complete the solution set for Chapters 6 and 7 of “** Introducing Monte Carlo Methods with R**”. Chapter 6 only exhibited a few typos, despite me covering most exercises in Chapter 6, hence the merging of both chapters.

— in Exercise 6.13, both and must use a double exponential proposal in the Metropolis-Hastings algorithm of question b,

in Exercise 6.15, the distribution should be a normal distribution,

— in Example 7.3, part of the code is wrong: it should be

> sigma2=theta=rep(0,Nsim) #init arrays > sigma2[1]=1/rgamma(1,shape=a,rate=b) #init chains > B=sigma2[1]/(sigma2[1]+n*tau2) > theta[1]=rnorm(1,m=B*theta0+(1-B)*xbar,sd=sqrt(tau2*B))

instead of

> sigma=theta=rep(0,Nsim) #init arrays > sigma{1}=1/rgamma(1,shape=a,rate=b) #init chains > B=sigma2{1}/(sigma2{1}+n*tau2) > theta{1}=rnorm(1,m=B*theta0+(1-B)*xbar,sd=sqrt(tau2*B))

(I frankly don’t understand where those curly brackets came from!)

— in Example 7.6, I forgot to include the truncation probability in the likelihood (!) and the notations are not completely coherent with Example 5.13 and 5.14 in that the *x*‘s became *y*‘s…

— in Exercise 7.21, *rtnorm* is missing *sigma* as one of its arguments.

— Exercise 7.23 has nothing wrong *per se* but it is rather a formal (mathematical) exercise

— in Exercise 7.25 the in question a should be to avoid any confusion.

January 18, 2010 at 11:28 am

:) !!!

Brute-force solution, O(1): try it on those curly brackets!

January 17, 2010 at 5:31 pm

Overall, I think the use of “n” to indicate parameters or variables should be avoided in R codes. In fact, if ever one wants to use the debugger (not with a one line code of course!), “n” would be straightforwardly interpreted as the command “next” (instruction), and there would be no way to retrieve information about the “n” variable/parameter used in the program.

I know that most talented people never need using debug(), but I speak for us, humans…. :)

January 18, 2010 at 9:08 am

I use spray for bugs…

January 15, 2010 at 11:28 am

In the first code sample above, I think there’s a typo:

theta[1}]=rnorm(1,m=B*theta0+(1-B)*xbar,sd=sqrt(tau2*B))

should be

theta[1] = …

Also

B=sigma2[1]/(sigma2{1}+n*tau2)

should be

B=sigma2[1]/(sigma2[1]+n*tau2)

It’s those curly brackets again;)

January 15, 2010 at 11:44 am

Typos within the typos! This is endless… Thank you very much, I will keep you posted about those curly brackets!!