**A**n X’idated reader of **Monte Carlo Statistical Methods** had trouble with our Example 3.13, the very one our academic book reviewer disliked so much as to “diverse *[sic]* a 2 star”. The issue is with computing the integral

when *f* is the Student’s t(5) distribution density. In our book, we compare a few importance sampling solutions, but it seems someone (the instructor?) suggested to this X’idated reader to use a mixture importance density

with

and

i.e. with a Cauchy and a power component. The suggested solution in our book is a folded Gamma distribution

**T**he above graph is my final answer to this X’idated reader (after several exchanges in the comments), comparing the three solutions in terms of variability. I used

> m=function(x){
+ sqrt(abs(x/{1-x}))*dt(x,df=5)}
> sam1=matrix(rt(10^7,df=5),ncol=100)
> fam1=m(sam1)

for the first box (the matrix is used for computing 100 replicas),

> g=function(x){
+ .5*dcauchy(x)+.125*((x>0)*(x<2))/sqrt(abs(1-x))}
> sam22=1+sample(c(-1,1),5*10^6,rep=TRUE)*runif(5*10^6)^2
> sam21=rcauchy(5*10^6)
> sam2=matrix(sample(c(sam21,sam22)),ncol=100)
> fam2=m(sam2)*dt(sam2,df=5)/g(sam2)

for the second box (with the details that

is the cdf associated with the second component and that it can be easily inverted into *1±u²* for simulation,

> sam3=matrix(1+sample(c(-1,1),5*10^7,
+ rep=TRUE)*rgamma(10^7,.5),ncol=100)
> fam3=m(sam3)*dt(sam3,df=5)/(.5*dgamma(abs(1-sam3),.5))

for the third box. The gradual improvement brought by importance sampling is clear there. Which makes me think we should present the comparison that way in the next edition of **Monte Carlo Statistical Methods**.

Filed under: Books, Kids, R, Statistics, University life Tagged: cross validated, importance sampling, Monte Carlo methods, Monte Carlo Statistical Methods, simulation

*Related*

To

**leave a comment** for the author, please follow the link and comment on his blog:

** Xi'an's Og » R**.

R-bloggers.com offers

**daily e-mail updates** about

R news and

tutorials on topics such as: visualization (

ggplot2,

Boxplots,

maps,

animation), programming (

RStudio,

Sweave,

LaTeX,

SQL,

Eclipse,

git,

hadoop,

Web Scraping) statistics (

regression,

PCA,

time series,

trading) and more...

If you got this far, why not

__subscribe for updates__ from the site? Choose your flavor:

e-mail,

twitter,

RSS, or

facebook...

**Tags:** Books, cross validated, importance sampling, Kids, Monte Carlo methods, Monte Carlo Statistical Methods, R, Simulation, statistics, University life