Archive for Méthodes de Monte-Carlo avec R

R exam

Posted in Kids, pictures, Statistics, University life with tags , , , , , , , on November 28, 2011 by xi'an

Following a long tradition (!) of changing the modus vivendi of each exam in our exploratory statistics with R class, we decided this year to give the students a large collection of exercises prior to the exam and to pick five among them to the exam, the students having to solve two and only two of them. (The exercises are available in French on my webpage.) This worked beyond our expectations in that the overwhelming majority of students went over all the exercises and did really (too) well at the exam! Next year, we will hopefully increase the collection of exercises and also prohibit written notes during the exam (to avoid a possible division of labour among the students).

Incidentally, we found a few (true) gems in the solutions, incl. an harmonic mean resolution of the approximation of the integral

\int_2^\infty x^4 e^{-x}\,\text{d}x=\Gamma(5,2)

since some students generated from the distribution with density f proportional to the integrand over [2,∞) [a truncated gamma] and then took the estimator

\dfrac{1-e^{-2}}{\frac{1}{n}\,\sum_{i=1}^n y_i^{-4}}\approx\dfrac{\int_2^\infty e^{-x}\,\text{d}x}{\mathbb{E}[X^{-4}]}\quad\text{when}\quad X\sim f

although we expected them to simulate directly from the exponential and average the sample to the fourth power… In this specific situation, the (dreaded) harmonic mean estimator has a finite variance! To wit;

> y=rgamma(shape=5,n=10^5)
> pgamma(2,5,low=FALSE)*gamma(5)
[1] 22.73633
> integrate(f=function(x){x^4*exp(-x)},2,Inf)
22.73633 with absolute error < 0.0017
> pgamma(2,1,low=FALSE)/mean(y[y>2]^{-4})
[1] 22.92461
> z=rgamma(shape=1,n=10^5)
> mean((z>2)*z^4)
[1] 23.92876

So the harmonic means does better than the regular Monte Carlo estimate in this case!

Typos sorted, at last!

Posted in Books, R, Statistics, University life with tags , , , , , , , , on March 24, 2011 by xi'an


After posting so many entries about typos in my books (making you wonder how there could be any text left!) and postponing their classification for so long, I decided on Saturday afternoon to collect those entries into a comprehensive pdf document that should be more useful for readers. I incidentally noticed that my book web-page had not been updated for the publication of Méthodes de Monte-Carlo avec R two months ago and did update it… I am obviously more than grateful to all those who contacted me, either thru the Og or by email to point out those numerous typos. As the Wheel had started rolling (or weaving), I took the opportunity to clean the original LaTeX files as well, including Introducing Monte Carlo methods with R. Since this is a print-on-demand edition, the changes should be immediate.

Méthodes de Monte-Carlo avec R [out]

Posted in Books, R, Statistics with tags , , on January 17, 2011 by xi'an

The translation of the book Introducing Monte Carlo Methods with R is now published and out! I have received five copies in the mail yesterday, although it was not produced in time for my R class students to get it before the exam today. The book is still indicated on amazon.com as appearing in February, while amazon.fr announces the publication for January 20. I am very pleased with the quality of the output, in contrast with the first printing of the English version.