Description Usage Arguments Value Examples
*Implement a function to generate samples from a Rayleigh(σ) distribution,using antithetic variables. What is the percent reduction in variance of (X+X)/2? compared with (X 1 +X 2)/2 for independent X 1 , X 2 ?
1 |
n |
The number of random Numbers generated |
sigma |
Parameter of Rayleigh(σ) distribution |
ant |
Parameter of function |
a random sample of size n
1 2 3 4 5 6 7 8 9 10 11 | ## Not run:
idpt_sample <-Rayleigh(4000,2,ant = F)#obtain 4000 independent samples
ant_sample<-Rayleigh(4000,2,ant = T)#4000 antithetic samples
var_idpt_sample<- var((idpt_sample[1:2000]+idpt_sample[2001:4000])/2)#compute the variance of independent sample
var_ant_sample <- var((ant_sample[1:2000]+ant_sample[2001:4000])/2)#compute the variance of antithetic sample
cat('the variance of independent sample is',var_idpt_sample,'.\n
the variance of antithetic sample is',var_ant_sample,'.\n
the percentage of variance reduction is',(var_idpt_sample-var_ant_sample)/var_idpt_sample,'.\n\n
the covariance of independent sample is',(cov(idpt_sample[1:2000],ant_sample[2001:4000]))) # show the variance
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.