I am trying to do a simulation in Stata with a random sample of 10000 for (i) the variable X with pdf f(x) = 2*x*exp(-x^2), X>0, and (ii) Y=X^2 I worked out the cdf of F to be 1-exp(-x^2), so the inverse of F is sqrt(-ln(1-u). I used the following code in Stata:
(1)
clear
set obs 10000
set seed 527665
gen u= runiform()
gen x= sqrt(-ln(1-u))
histogram x
summ x, detail
(mean 0.88, sd 0.46)
(2)
clear
set obs 10000
set seed 527665
gen u= runiform()
gen x= (sqrt(-ln(1-u)))^2
summ x, detail
(mean 0.99, sd 0.99)
(3)
clear
set obs 10000
set seed 527665
gen u= rexponential(1)
gen x= 2*u*exp(-(u^2))
summ x, detail
(mean 0.49, sd 0.28)
(4)
clear
set obs 10000
set seed 527665
gen v= runiform()
gen u=1/v
gen x= 2*u*exp(-(u^2))
histogram x
summ x, detail
(mean 0.22, sd 0.26)
My queries are: (i) (1) and (2) are based on the probability integral transformation, which I have come across but do not understand. If (1) and (2) are valid approaches, what is the intuition behind this, (ii) the output for (3) does not seem correct; I am not sure if I am applying the rexponential function correctly, and what is the scale parameter (there seems to be no explanation on this in stata help) (iii) the output for (4) also does not seem correct, and I was wondering why this approach is flawed.
Thanks
Aucun commentaire:
Enregistrer un commentaire