I am working with different sampling functions, and I am wondering why these two formulations do not give the same result
n=2
set.seed(1)
rweibull(n,shape = 1,scale = 1)
# [1] 1.3261078 0.9885284
set.seed(1)
rexp(n,rate = 1)
# [1] 0.7551818 1.1816428
when this is equivalent:
x <- c(0, rlnorm(50))
all.equal(dweibull(x, shape = 1), dexp(x))
Is it a problem of reverse transformation sampling ?
If yes, why ?
Thanks,
First of all,
d*denotes the density function, which is deterministic and that's why you can achieve the same results in the following codeHowever,
r*gives random samples of a given distribution, which depends on how the randomness is triggered.rweibullrexpwhere
exp_rand()is used to generate exponential random variable, which is NOT simply the same aspow(-log(unif_rand()), 1.0 / shape)shown inrweibull.c, but more complicated like below