1
$\begingroup$

Consider the following code that gives us (an estimate of) the pdf of a random variable $X$:

X = rnorm(100,10,1)
XDensity = density(X)

I want to obtain the ecdf of $X$. Of course I could just use the ecdf() function on $X$ itself, but suppose we don't have access to $X$. Instead we are given XDensity. Can we convert XDensity to an ecdf? Or course it may not be the true ecdf but it could at least serve as an estimate of it.

Is it possible to do this, can a density estimate be converted to an ecdf estimate?

$\endgroup$
8
  • 2
    $\begingroup$ See our posts on deconvolution of densities. $\endgroup$
    – whuber
    Commented Jan 9, 2021 at 22:51
  • $\begingroup$ Yes that's correct, I didn't know XDensity contains X. I mean when we don't have access to the data. and instead just have values such as those contained in XDensity$x and XDensity$y. Can we convert these to an ecdf somehow? $\endgroup$
    – sonicboom
    Commented Jan 9, 2021 at 22:55
  • 2
    $\begingroup$ I was wrong about the earlier comment that XDensity contains X, so I had deleted it. Yes, with some work you can convert the density back to the empirical density, whose cumulative sum is the ecdf. The problems are that deconvolutions are unstable and the density isn't fully defined--a little bit of its tails are cut off. The gist of it is in the line kords <- fft(fft(y) * Conj(fft(kords)), inverse = TRUE) near the end of the density function: that can be solved for y using fft, after you recreatekords (the kernel function). $\endgroup$
    – whuber
    Commented Jan 9, 2021 at 23:04
  • 1
    $\begingroup$ You can, but unless the bandwidth is much smaller than the range of the data, it's often not a good estimate because the density extends beyond the range of the original data. Compare them graphically: plot(ecdf(X)); lines(XDensity$x, cumsum(XDensity$y)/XDensity$y, col="Red", lwd=2) It might look good, but then try again after generating data like X <- c(rnorm(70), rnorm(30, 2, 1/10)) $\endgroup$
    – whuber
    Commented Jan 9, 2021 at 23:11
  • 2
    $\begingroup$ That, then, is the question you should be asking. $\endgroup$
    – whuber
    Commented Jan 10, 2021 at 15:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.