I'm deriving a CDF from a Kernel Smoothing distribution
Here's my setup
library("DiagTest3Grp", lib.loc='~/R/win-library/3.2")
data <- c(34,46,47,48,52,53,55,56,56,56,57,58,59,59,68)
bw <- BW.ref(data)
x0 <- seq(0, 100, .1)
KS.cdfvec <- Vectorize(KernelSmoothing.cdf, vectorize.args = "c0")
x0.cdf <- KS.cdfvec(xx = data, c0 = x0, bw = bw)
plot(x0, x0.cdf, type = "l")
Produces graph
Yet, I'm so green I have no idea how to derive x given y (or vice versa), I'm hoping that since it's a simple x,y graph that I just need to look up a crosssection
Given a value y
in the CDF you want the corresponding value x
in the pdf
that corresponds to this. You can just use approx
, but since in approx
you
specify yout
not xout
, just flip the inputs
> approx(y=x0, x=x0.cdf, xout=0.8)
$x
[1] 0.8
$y
[1] 58.95378
Remember that we flipped the inputs, so this means for the value 0.8 in the CDF
this corresponds to a value of x=58.95378
. This also assumed that is this small region of the CDF linear interpolation is a reasonable approximation.
In the case that we have a value of x
and simply want the associated value of the CDF, no argument flipping is necessary, so you can just use
> approx(x=x0, y=x0.cdf, xout=55)
$x
[1] 55
$y
[1] 0.5090248