0

I want to check the "probability integral transform" theorem using R. Let's suppose X is an exponential random variable with lambda = 5. I want to check that the random variable U = F_X = 1 - exp(-5*X) has a uniform (0,1) distribution. How would you do it?

I would start in this way:

nsample <- 1000
lambda <- 5
x <- rexp(nsample, lambda) #1000 exponential observation
u <- 1- exp(-lambda*x) #CDF of x 

Then I need to find the CDF of u and compare it with the CDF of a Uniform (0,1).

For the empirical CDF of u I could use the ECDF function:

ECDF_u <- ecdf(u) #empirical CDF of U

Now I should create the theoretical CDF of Uniform (0,1) and plot it on the same graph of the ECDF in order to compare the two graphs.

Can you help with the code?

Luca Dibo
  • 227
  • 1
  • 2
  • 12

1 Answers1

0

You are almost there. You don't need to compute the ECDF yourself – qqplot will take care of this. All you need is your sample (u) and data from the distribution you want to check against. The lazy (and not quite correct) approach would be to check against a random sample drawn from a uniform distribution:

qqplot(runif(nsample), u)

But of course, it is better to plot against the theoretical quantiles:

# the actual plot
qqplot( qunif(ppoints(length(u))), u )
# add a line
qqline(u, distribution=qunif, col='red', lwd=2)

enter image description here

Looks pretty good to me.

Phil
  • 185
  • 1
  • 9