#Antithetic variables h = function(x) { x/(2^x-1) } xp=seq(-8,8, by=0.01) plot(xp,h(xp)) #Independent sampling set.seed(231171) N = 2e5 x = rnorm(N) mu.hat = mean(h(x)) sd.mu = sd(h(x))/sqrt(N) show(c(mu.hat,sd.mu)) #Antithetic sampling N2 = N/2 x1 = x[1:N2] mu1.hat = mean(h(x1)) mu2.hat = mean(h(-x1)) mu.hat.as = 0.5*(mu1.hat+mu2.hat) var.mu.as = var(h(x1))*(1 + cor(h(x1),h(-x1)))/(2*N2) sd.mu.as = sqrt(var.mu.as) show(c(mu.hat.as,sd.mu.as)) set.seed(231171) N = 2e5 x = rnorm(N) N2 = N/2 x1 = x[1:N2] x12=matrix(t(cbind(x1,-x1)), 1,N) plot(1:N, cumsum(h(x))/(1:N),type='l',col='red', ylim=c( 1.48 ,1.52)) lines(1:N, cumsum(h(x12))/(1:N) , col='blue')