**O**ver the past week, I wrote a short introduction to the Metropolis-Hastings algorithm, mostly in the style of our Introduction to Monte Carlo with R book, that is, with very little theory and worked-out illustrations on simple examples. (And partly over the Atlantic on my flight to New York and Columbia.) This vignette is intended for the Wiley StatsRef: Statistics Reference Online Series, modulo possible revision. Again, nothing novel therein, except for new examples.

## Archive for Introducing Monte Carlo Methods with R

## a vignette on Metropolis

Posted in Books, Kids, R, Statistics, Travel, University life with tags Columbia University, Introducing Monte Carlo Methods with R, Metropolis-Hastings algorithm, mixture, New York city, testing as mixture estimation, vignette on April 13, 2015 by xi'an## an email exchange about integral representations

Posted in Books, R, Statistics, University life with tags accept-reject algorithm, George Casella, Introducing Monte Carlo Methods with R, Lebesgue integration, Riemann integration on April 8, 2015 by xi'an**I** had an interesting email exchange [or rather exchange of emails] with a (German) reader of Introducing Monte Carlo Methods with R in the past days, as he had difficulties with the validation of the accept-reject algorithm via the integral

in that it took me several iterations [as shown in the above] to realise the issue was with the notation

which seemed to be missing a density term or, in other words, be different from

What is surprising for me is that the integral

has a clear meaning as a Riemann integral, hence should be more intuitive….

## another R new trick [new for me!]

Posted in Books, Kids, R, Statistics, University life with tags C code, importance sampling, Introducing Monte Carlo Methods with R, kolmim, Kolmogorov-Smirnov distance, R, stackoverflow, Université Paris Dauphine on July 16, 2014 by xi'an**W**hile working with Andrew and a student from Dauphine on importance sampling, we wanted to assess the distribution of the resulting sample via the Kolmogorov-Smirnov measure

where F is the target. This distance (times √n) has an asymptotic distribution that does not depend on n, called the Kolmogorov distribution. After searching for a little while, we could not figure where this distribution was available in R. It had to, since ks.test was returning a p-value. Hopefully correct! So I looked into the ks.test function, which happens not to be entirely programmed in C, and found the line

PVAL <- 1 - if (alternative == "two.sided") .Call(C_pKolmogorov2x, STATISTIC, n)

which means that the Kolmogorov distribution is coded as a C function C_pKolmogorov2x in R. However, I could not call the function myself.

> .Call(C_pKolmogorov2x,.3,4) Error: object 'C_pKolmogorov2x' not found

Hence, as I did not want to recode this distribution cdf, I posted the question on stackoverflow (long time no see!) and got a reply almost immediately as to use the package kolmim. Followed by the extra comment from the same person that calling the C code only required to add the path to its name, as in

> .Call(stats:::C_pKolmogorov2x,STAT=.3,n=4) [1] 0.2292

## Ｒによるモンテカルロ法入門

Posted in Books, R, Statistics with tags George Casella, Introducing Monte Carlo Methods with R, Japanese translation on May 14, 2013 by xi'an**H**ere is the cover of the Japanese translation of our Introducing Monte Carlo methods with R book. A few year after the French translation. It actually appeared last year in August but I was not informed of this till a few weeks ago. The publisher is Maruzen, with an associated webpage if you want to order… Unless I am confused the translators are Hiro Ishida and Kazue Ishida; they deserve a major ありがとう ! And too bad George is no longer with us: this must have been the first translation of one of his books in Japanese..

## CHANCE: special issue on George Casella’s books

Posted in Books, R, Statistics, University life with tags CHANCE, George Casella, Introducing Monte Carlo Methods with R, Monte Carlo Statistical Methods, Sam Behesta, statistical inference, Theory of Point Estimation, Variance Components on February 10, 2013 by xi'an **T**he special issue of CHANCE on George Casella’s books has now appeared and it contains both my earlier post on George passing away and reviews of several of his books, as follows:

- Andrew Gelman on Introducing Monte Carlo Methods with R
- Bill Strawderman on Statistical Inference
- Jean-Louis Foulley on Variance Components
- Larry Wasserman on Theory of Point Estimation
- Xiao-Li Meng on Monte Carlo Statistical Methods

Although all of those books have appeared between twenty and five years ago, the reviews are definitely worth reading! *(Disclaimer: I am the editor of the Books Review section who contacted friends of George to write the reviews, as well as the co-author of two of those books!)* They bring in my *(therefore biased)* opinion a worthy evaluation of the depths and impacts of those major books, and they also reveal why George was a great teacher, bringing much into the classroom and to his students… *(Unless I am confused the whole series of reviews is available to all, and not only to CHANCE subscribers. Thanks, Sam!)*

## Example 7.17 in Introduction to Monte Carlo methods with R

Posted in Books, R, Statistics, University life with tags Introducing Monte Carlo Methods with R, mcsm on January 4, 2012 by xi'an**I** received the following email about ** Introducing Monte Carlo Methods with R** a few days ago:

Hallo Dr. Robert,

I am studying your fine book for myself. There´s a little problem in examples 7.17 and 8.1: in the R code a function “

gu” is used and a reference given to ex. 5.17, but I cann´t find there a definition of “gu“. (gu = log formula (5.15)?) Could you give me a hint?

from Elmar Kisslinger. Indeed, the *gu* function used in this analysis of the logit model is not available in the book, it is provided by

#function for MCMC gu=function(mu,i,beta,sigma){ sum((y[i,]*(beta*x[i,]+mu))-log(1+exp(beta*x[i,]+mu)))-0.5*mu^2/sigma^2 }

and is only available in the associated mcsm R package as part of the *randogit.R* code. (Incidentally, this is my 1500th post on the ‘Og! And this coincides with the 3000th comment…)

## what’s wrong with package comment?!

Posted in Books, R, Statistics, University life with tags comment package, Introducing Monte Carlo Methods with R, LaTeX, R, verbatim on May 4, 2012 by xi'anIspent most of the Sunday afternoon trying to understand why definingdid not have the same effect as writing the line

until I found there is a clash due to the

commentpackage… The assuredly simple codeproduces an error message:

This is quite an inconvenience as I need to compile my solution manual for “” with the even-numbered exercises commented out or not depending on the version… (Leaving this package out and using the comment command within theIntroducing Monte Carlo Methods with Rverbatimpackage does not work either becauseeradoes not seem to be recognised as the end of a commented part…)## Share:

5 Comments »