Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
The antithetic variates method is a variance reduction technique used in Monte Carlo methods.
## Antithetic sampling reframes our estimate as a sum of negatively
## correlated random variables, using the fact that negative
## correlation reduces the variance of a sum.
g <- function(x) 1/(1+x)
N <- 1500
n <- 50
u1 <- matrix(runif(2 * n * N), ncol = n)
theta1 <- colMeans(g(u1))
u2 <- matrix(runif(n * N), ncol = n)
theta2 <- 0.5 * (colMeans(g(u2)) + colMeans(g(1 - u2)))
var1 <- var(theta1)
var2 <- var(theta2)
res <- data.frame(Estimate=c(mean(theta1),mean(theta2)),
rownames(res) <- c("Classical Estimate", "Antithetic Variates")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.