set.seed(155)
Recycled.MC.Phi <- function(thescale, R = 10000, antithetic = TRUE) {
o = thescale
u = runif(R/2)
if (!antithetic){
v = runif(R/2)}
else
{
v = 1 - u
}
#When activating antitheticals; half of the vector is replaced by 1-vector
u = c(u, v)
rayleigh = function(x,o){
o*sqrt(-2*log(x))
}
results= sapply(u,rayleigh,o)
return(results)# Our integrand
}
avReducRayleighSamp = var(Recycled.MC.Phi(4))
rayleighSamp = var(Recycled.MC.Phi(4,antithetic = FALSE))
label = c('Antithetical','RV','% Reduction')
theData = c(avReducRayleighSamp,rayleighSamp,(rayleighSamp - avReducRayleighSamp)/avReducRayleighSamp*100)
rbind(label,theData)## [,1] [,2] [,3]
## label "Antithetical" "RV" "% Reduction"
## theData "6.52312427136351" "6.95708746115825" "6.65268929031184"