ImpSamp=function(n,nu){ # The normal simulation has not been converging when the variance is nu/(nu-2). # A variance of nu/2 is used here, but still performs poorly and the normal # simulation should probably be removed from the simulation s1=rnorm(n,0,sqrt(nu/(nu-2.0))) s2=rcauchy(n) s3=rt(n,nu) h1=sqrt(abs(s1/(1.0-s1))) h2=sqrt(abs(s2/(1.0-s2))) h3=sqrt(abs(s3/(1.0-s3))) # Form the integrands i1=h1*dt(s1,nu)/dnorm(s1,0,sqrt(nu/(nu-2.0))) i2=h2*dt(s2,nu)/dcauchy(s2) i3=h3 # Form the accumulated integrals t1= cumsum(i1)/seq(1,n) t2=cumsum(i2)/seq(1,n) t3=cumsum(i3)/seq(1,n) win.graph() ts.plot(as.ts(t1),as.ts(t2),as.ts(t3),xlab="Simulations",ylab="MC Estimate",ylim=c(0,2),lty=c(1,2,3), col=c("black","blue","green")) legend(.7*n,2,c("Normal","Cauchy","t"),col=c("black","blue","green"),lty=c(1,2,3)) abline(h=1.13,col="red") out=list(t1[n],t2[n],t3[n]) names(out)=c("Normal Estimate","Cauchy Estimate","t Estimate") out }