title: Empirical CDF vs Theoretical CDF in R
body: <p>I want to check the "probability integral transform" theorem using R.
  Let's suppose <code>X</code> is an exponential random variable with <code>lambda = 5</code>.
  I want to check that the random variable <code>U = F_X = 1 - exp(-5*X)</code>  has a uniform (0,1) distribution.
  How would you do it?</p>
  
  <p>I would start in this way:</p>
  
  <pre><code>nsample &lt;- 1000
  lambda &lt;- 5
  x &lt;- rexp(nsample, lambda) #1000 exponential observation
  u &lt;- 1- exp(-lambda*x) #CDF of x 
  </code></pre>
  
  <p>Then I need to find the CDF of u and compare it with the CDF of a Uniform (0,1).</p>
  
  <p>For the empirical CDF of u I could use the ECDF function:</p>
  
  <pre><code>ECDF_u &lt;- ecdf(u) #empirical CDF of U
  </code></pre>
  
  <p>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.</p>
  
  <p>Can you help with the code?</p>