Archive for February, 2010

How to use mcsm

Posted in Books, R, Statistics with tags , , , , , on February 28, 2010 by xi'an

Within the past two days, I received this email

Dear Prof.Robert
I have just bought your recent book on Introducing Monte Carlo Methods with R.  Although I have checked your web page for the R programs (bits of the code in the book, codes for generating the figures and tec – not the package available on cran)  used in the book, I have not found them.
I wonder whether you could make them available.
Thank you very much for your time and patience.
Yours Sincerely

and that one

Dear Prof. Robert,
I bought “Introducing Monte Carlo Methods with R” from Amazon booksore. I am a teacher at […] University, and I choose this book as a textbook in my class.
I can not find the R package “mcsm” according to your book (page 5). Where can I download the R package “mcsm”?
I highly appreciate your help.
Best regards,

so I fear that readers may miss the piece of information provided in the book. As indicated on pages 36-37 of Introducing Monte Carlo Methods with R, mcsm is a registred R package, readers can therefore download it manually from CRAN,  but they should first try using install.packages in R as this is both easier and safer. (They should check on the main R project webpage for more help in installing packages.)

Another useful information for readers is that the code used on the examples of Introducing Monte Carlo Methods with R is available from mcsm through the demo command/code. Typing demo(Chapter.3) starts the production of the examples of Chapter 3:

> demo(Chapter.3)

Type  <Return>   to start :
> # Section 3.1, Introduction
> ch=function(la){ integrate(function(x){x^(la-1)*exp(-x)},0,Inf)$val}
> plot(lgamma(seq(.01,10,le=100)),log(apply(as.matrix(
+  seq(.01,10,le=100)),1,ch)),xlab=”log(integrate(f))”,
+  ylab=expression(log(Gamma(lambda))),pch=19,cex=.6)
> S=readline(prompt=”Type  <Return>   to continue : “)
Type  <Return>   to continue :

and obviously the same for all other chapters. This also means the code is available in the corresponding file, something like


depending on your system.

Scottish “Happy Hours”

Posted in Mountains with tags , , on February 27, 2010 by xi'an

In preparation for my trip to Ben Nevis, next Tuesday, a pretty accurate definition of the meaning of “great weather” for Scottish climbers… My guide will be Max Hunter, whose blog is full of tantalising pictures. Looking forward some great weather!

Welcome, Robin!

Posted in R, Statistics, University life with tags , , , on February 26, 2010 by xi'an

Robin Ryder started his new blog with his different solutions to Le Monde puzzle of last Saturday (about the algebraic sum of products…), solutions that are much more elegant than my pedestrian rendering. I particularly like the one based on the Jacobian of a matrix! (Robin is doing a postdoc in Dauphine and CREST—under my supervision—on ABC and other computational issues, after completing a PhD in Oxford on philogenic trees for language history with Geoff Nicholls. His talk at the Big’MC seminar last month is reproduced there.)

And, in a totally unrelated way, here is the Sudoku (in Le Monde) that started my post on simulated annealing, nicely represented on Revolutions. (Although I cannot see why the central columns are set in grey…) I must mention that I am quite surprised at the number of visits my post received, given that using simulated annealing for solving Sudokus has been around for a while. Even my R code, while original, does not compete with simulated annealing solutions that take a few seconds… I thus completely share Dirk Eddelbuettel‘s surprise in this respect (but point to him that Robin’s blog entry has nothing to do with Sudokus, but with another Le Monde puzzle!)

Another review of Search for Certainty

Posted in Books, Statistics with tags , , , , , on February 25, 2010 by xi'an

The best thing about this book is that it will offend and annoy both frequentists and subjectivists. I implore my friends on both sides of the philosophical divide to read the book with an open mind.

Our comments, Andrew‘s and mine‘s, led Larry Wasserman to read Krzysztof Burdzy’s The Search for Certainty to make his own opinion and Andrew just posted Larry’s review. The review is highly positive, arguing that “this is an interesting and important book” and that “Burdzy makes a convincing case that the philosophy of probability is a complete failure“. While remaining utterly unconvinced (that the book has any bearing on the philosophical foundations of Statistics),  I will not engage here into another debate about The Search for Certainty as the readers can check for themselves the strength of Larry’s arguments. Needless to say, I cannot be convinced into redefining probability as an experimental science where Burdzy’s five laws would replace Kolmogorov’s three axioms…

Monty Hall, again

Posted in Books, Statistics with tags , on February 24, 2010 by xi'an

This little article contains nothing new, and only almost trivial mathematics. It is a plea for future generations to preserve the life of The True Monty Hall paradox, and not let themselves be misled by probability purists who say “you must compute a conditional probability”.

Richard Gill posted a paper on arXiv this morning about the Monty Hall problem. He does not mean to try yet another solution to the problem more susceptible to convince the army of skeptics out there, but rather to illustrate the hidden and implicit assumptions behind the mathematisation (sic!) of the problem… As a background to the problem, Richard Gill refers to the book The Monty Hall Problem: The Remarkable Story of Math’s Most Contentious Brain Teaser that led to my earlier post. Now, after having read the paper and come upon the final sentence reported above, I must say I am none the wiser about why the author wrote the paper! To me the Monty Hall problem is primarily an instance of wrong conditioning… Nonetheless, I appreciate the points about visualising the puzzle as a decision theoretic problem and the solution as the minimax procedure.

Sudoku via simulated annealing

Posted in R, Statistics with tags , on February 23, 2010 by xi'an

The Sudoku puzzle in this Sunday edition of Le Monde was horrendously difficult, so after spending one hour with only 4 entries filled, I decided to feed it to the simulated annealing R program I wrote while visiting SAMSI last year. The R program reached the exact (and only) solution in about 6000 iterations, as shown (?) on the graph above. The Sudoku grid is defined in the R program by a 9×9 matrix s and the simulated annealing target function counts the number of duplicates

for (r in 1:9){

After pruning out the deterministic entries (3 in my case!), the R program uses the temperature sequence


to weight the target function. and it runs over the 10,000 iterations random moves on some of the unallocated sites. On the graph above, the green dots correspond to accepted moves. The yellow dots correspond to accepted proposals to move a single site. These choices lead to a correct solution most of the time, the other cases most often producing a penalty of two. (Please note there is nothing optimised about my code. It takes ten to twenty minutes to produce the graph above. a far cry from the fastest Sudoku solvers!)

Numbers rule your world

Posted in Books, Statistics with tags , , , , , , , , , , , on February 22, 2010 by xi'an

Andrew Gelman gave me a copy of the recent book Numbers rule your world by Kaiser Fung, along with the comment that it was a nice book but not for us. I spend my “lazy Sunday” morning reading the book at the breakfast table and agree with Andrew on his assessment. (waiting for the  incoming blog review!). Numbers rule your world is unlikely to bring enlightment to professional or academic statisticians, but it provides a nice and soft introduction to the use of statistics in everyday’s life, to the point I would encourage my second and third year students to read it. It covers a few topics that are central to Statistics via ten newspaper-ised stories that make for a very light read, but nonetheless make the point. The themes in Numbers rule your world are

  • variability matters more than average, as illustrated by queuing phenomena;
  • correlation is not causation, but is often good enough to uncover patterns, as illustrated by epidemiology and credit scoring;
  • Simpson’s paradox explains for apparent bias in group differences, as illustrated by SAT score differences between black students and white students;
  • false positives and false negatives have different impacts on the error (here comes Bayes theorem!), depending on population sizes and settings, as illustrated by the (great!) case of cheating athletes and polygraph tests (with a reference to Steve Fienberg‘s work);
  • extreme events may exhibit causes, or not, as illustrated by a cheating lottery case (involving Jeff Rosenthal as the expert, not the cheater!) and a series of air crashes.

The overall tone of Numbers rule your world is pleasant and engaging, at the other end of the stylistic spectrum from Taleb’s Black Swan. Fung’s point is obviously the opposite of Taleb‘s: he is showing the reader how well statistical modelling can explain for apparently paradoxical behaviour. Fung is also adopting a very neutral tone, again a major change from Taleb, maybe being even too positive (no the only mention is made of the current housing crisis in the pages Numbers rule your world dedicates to credit scoring comes in the conclusion, pp. 176-7). Now, in terms of novelty, I cannot judge of the amount of innovation when compared with (numerous) other popular science books on the topic. For instance, I think Jeff Rosenthal’s Struck by Lightning brings a rather deeper perspective, but maybe thus restricts the readership further…