When variable X
has uniform distribution (0,1), I can make a formula Y = -(lambda)lnX
and the distribution of Y
would show Exp(lambda)
.
And I'm trying to prove this case when lambda
is 3, showing that two distribution curves match.
I've made it this far, but can't figure out really how.
w <- seq(0, 10, length=500)
x <- dunif(w, 0, 1)
y <- (-1)*(3)*log(x)
z <- dexp(w, 3)
plot(w, y, type="l")
par(new=F)
plot(w, z)
This is a problem related to inverse CDF method.
First of all, you get inverse CDF wrong. It is -1/3
, not -3
.
Secondly, as the name suggests, it is inverse CDF, not inverse PDF. You can't do such transformation on density function. Instead, draw samples and use quantile-quantile plot.
n <- 500
x <- runif(n)
y <- -1/3 * log(x)
z <- rexp(n, 3)
qqplot(y, z)
abline(0, 1)
Alternatively, compare empirical CDF with theoretical CDF.
plot(ecdf(y))
curve(pexp(x, 3), add = TRUE, col = 2)