Inverse function of an unknown cumulative function
Asked Answered
I

2

6

I'm working with a data file, the observations inside are random values. In this case I don't know the distribution of x (my observations). I'm using the function density in order to estimate the density, because I must apply a kernel estimation.

T=density(datafile[,1],bw=sj,kernel="epanechnikov")

After this I must integrate this because I'm looking for a quantile (similar to VaR, 95%). For this I have 2 options:

ecdf()
quantile()

Now I have the value of the quantile 95, but this is the data estimated by kernel.

Is there a function which I can use to know the value of the quantile 95 of the original data?

I remark that this is a distribution unknown, for this I would like to imagine a non parametric method as Newton, like the one that is in SAS solve()

Integrant answered 21/1, 2013 at 20:22 Comment(0)
F
8

You can use quantile() for this. Here is an example using random data:

> data<-runif(1000)

> q<-quantile(data, .95)
> q
      95% 
0.9450324 

Here, the data is uniformly distributed between 0 and 1, so the 95th percentile is close to 0.95.

To perform the inverse transformation:

> ecdf(data)(q)
[1] 0.95
Fierro answered 21/1, 2013 at 20:28 Comment(7)
But quantile will give me the value of the last estimated data and a I'm looking for the original. Remember that the data have been estimated by kernel. Estimated_data = density(Original,bw=sj,kernel="epanechnikov") quantile(Estimated_data, .95) This would give me the value of the accumulated 95% in the Estimated_data and not in the "Original".Integrant
@user1970451: In my example, data refers to your original data.Fierro
Yes data referes to the original data, but the quantile have been calculated over runif(1000) and the quantile 0.95 will be near 95% in this case the vale is 0.94 but this value correspond to the transformed data, my question was if there is a way to find the inverse of this in order to obtain the value that 0.94 may refer in the original data.Integrant
@user1970451: Are you looking for ecdf(original_data)(q)? See my updated answer for an example.Fierro
I'm looking for the inverse of ecdf.Integrant
quantile IS the inverse of ecdf.Burgoo
I think we're running in circles.Fierro
D
1

Dont know if this is on any relevance for you anymore... However I think what may be helpful to the answer above

data <- rnorm(1000)

my_ecdf <- ecdf(data)

my_ecdf_inv <- function(x) {quantile(data, x)}

my_ecdf_inv(my_ecdf(2))

x <- seq(-3, 3, 0.1)
plot(x, sapply(sapply(x, my_ecdf),my_ecdf_inv))
Damek answered 24/6, 2021 at 15:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.