## R exam

**F**ollowing 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).

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

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

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

**S**o the harmonic means does better than the regular Monte Carlo estimate in this case!

January 31, 2012 at 4:16 pm

[…] of my students wrote the following code for his R exam, trying to do accept-reject simulation (of a Rayleigh distribution) and constant approximation at […]

December 16, 2011 at 12:13 am

[…] for frequentist inference. I spent the past two weeks teaching non-parametric bootstrap to my R class and the students are now fluent with the concept, even though they are unsure about the meaning of […]