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?
X
. I mean when we don't have access to the data. and instead just have values such as those contained inXDensity$x
andXDensity$y
. Can we convert these to an ecdf somehow? $\endgroup$XDensity
containsX
, 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 linekords <- fft(fft(y) * Conj(fft(kords)), inverse = TRUE)
near the end of thedensity
function: that can be solved fory
usingfft
, after you recreatekords
(the kernel function). $\endgroup$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 likeX <- c(rnorm(70), rnorm(30, 2, 1/10))
$\endgroup$