Archive for code

Statistical rethinking [book review]

Posted in Books, Kids, R, Statistics, University life with tags , , , , , , , , , , , , , , , , , , , , , on April 6, 2016 by xi'an

Statistical Rethinking: A Bayesian Course with Examples in R and Stan is a new book by Richard McElreath that CRC Press sent me for review in CHANCE. While the book was already discussed on Andrew’s blog three months ago, and [rightly so!] enthusiastically recommended by Rasmus Bååth on Amazon, here are the reasons why I am quite impressed by Statistical Rethinking!

“Make no mistake: you will wreck Prague eventually.” (p.10)

While the book has a lot in common with Bayesian Data Analysis, from being in the same CRC series to adopting a pragmatic and weakly informative approach to Bayesian analysis, to supporting the use of STAN, it also nicely develops its own ecosystem and idiosyncrasies, with a noticeable Jaynesian bent. To start with, I like the highly personal style with clear attempts to make the concepts memorable for students by resorting to external concepts. The best example is the call to the myth of the golem in the first chapter, which McElreath uses as an warning for the use of statistical models (which almost are anagrams to golems!). Golems and models [and robots, another concept invented in Prague!] are man-made devices that strive to accomplish the goal set to them without heeding the consequences of their actions. This first chapter of Statistical Rethinking is setting the ground for the rest of the book and gets quite philosophical (albeit in a readable way!) as a result. In particular, there is a most coherent call against hypothesis testing, which by itself justifies the title of the book. Continue reading

Verbatim code

Posted in Books, Linux with tags , , , , , on October 27, 2009 by xi'an

When rendering computer code and output in LateX, I usually resort to the basic verbatim environment, as in

> matrix(1:4,ncol=3)
[,1] [,2] [,3]
[1,]    1    3    1
[2,]    2    4    2
Warning message:
data length [4] is not a submultiple or multiple of the number of columns [3] in matrix in: matrix(1:4, ncol = 3)

However, I do not like the way tildes are represented in this environment, being considered as accents rather than standard characters, as in the R command


Asking Springer-Verlag TeXperts for help during my last round of corrections of Introducing Monte Carlo Methods with R before it left for the printer, I received a solution which is to use the alltt environment instead, which allows for LaTeX commands within the verbatim rendering, using \(\sim\) instead of ~. (I have been looking for this solution for ages and of course, provided with the solution of using alltt instead, I immediately found a lot of related posts!) There is a drag, though, which is that curly brackets {} vanish from the R code, unless replaced with the LaTeX versions \(\{\) and \(\}\).

When ~is used in the in-line rendering


alltt does not work but a simple


is sufficient.