Rayleigh: a function to generate samples from a Rayleigh(σ)...

Description Usage Arguments Value Examples

Description

*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 ?

Usage

1
Rayleigh(n, sigma, ant = T)

Arguments

n

The number of random Numbers generated

sigma

Parameter of Rayleigh(σ) distribution

ant

Parameter of function

Value

a random sample of size n

Examples

 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)

liujin07/StartComp18065 documentation built on May 5, 2019, 11:07 p.m.