Yeah, now it works. Thanks a lot, William and everyone who helped me. This
forum is really helpful for beginners like me. :)
Mano.
On Fri, Nov 1, 2013 at 3:54 PM, William Dunlap <
wdu...@tibco.com> wrote:
> You are not using the inv_ecdf function that Rui sent. His was****
>
> inv_ecdf_orig <-****
>
> function (f) ****
>
> {****
>
> x <- environment(f)$x****
>
> y <- environment(f)$y****
>
> approxfun(y, x)****
>
> }****
>
> (There is no 'xnew' in the environment of f.)****
>
> ** **
>
> Bill Dunlap****
>
> Spotfire, TIBCO Software****
>
> wdunlap
tibco.com****
>
> ** **
>
> *From:* Manoranjan Muthusamy [mailto:
ranjan...@gmail.com]
> *Sent:* Friday, November 01, 2013 4:38 AM
> *To:* William Dunlap;
dulc...@bigpond.com
> *Cc:* Rui Barradas;
r-h...@r-project.org
>
> *Subject:* Re: [R] Extracting values from a ecdf (empirical cumulative
> distribution function) curve****
>
> ** **
>
> Thanks, Bill & Duncan. Actually I tried values which are inside the
> defined region. please find below the extracted script****
>
> ** **
>
> > xnew<-rlnorm(seq(0,4000000,10000), meanlog=9.7280055, sdlog=2.0443945)**
> **
>
> > f <- ecdf(xnew)****
>
> > y <- f(x)****
>
> > y1<-f(2000000) ## finding y for a given xnew value of
> 2000000****
>
> > y1****
>
> [1] 0.9950125 ## It works.****
>
> ** **
>
> > inv_ecdf <- function(f){****
>
> + xnew <- environment(f)$xnew****
>
> + y <- environment(f)$y****
>
> + approxfun(y, xnew)****
>
> + }****
>
> ## Interpolation to find xnew for a known y value.****
>
> ** **
>
> > g <- inv_ecdf(f)****
>
> > g(0.9950125)****
>
> [1] NA****
>
> > g(0.99) ## It doesn't****
>
> [1] NA****
>
> > g(0.5)****
>
> [1] NA ## again****
>
> > g(0.2)****
>
> [1] NA ## and again****
>
> ** **
>
>
> I am stuck here. Any help is appreciated.
>
> Mano.****
>
> ** **
>
> On Fri, Nov 1, 2013 at 2:48 AM, William Dunlap <
wdu...@tibco.com> wrote:*
> ***
>
> > it gives 'NA' (for whatever y value).****
>
> What 'y' values were you using? inf_f maps probabilities (in [0,1]) to
> values in the range of the orginal data, x, but it will have problems for
> a probability below 1/length(x) because the original data didn't tell
> you anything about the ecdf in that region.
>
> > X <- c(101, 103, 107, 111)
> > f <- ecdf(X)
> > inv_f <- inv_ecdf(f)
> > inv_f(seq(0, 1, by=1/8))
> [1] NA NA 101 102 103 105 107 109 111
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap
tibco.com****
>
>
>
> > -----Original Message-----
> > From:
r-help-...@r-project.org [mailto:
r-help-...@r-project.org]
> On Behalf
> > Of Manoranjan Muthusamy
> > Sent: Thursday, October 31, 2013 6:18 PM
> > To: Rui Barradas
> > Cc:
r-h...@r-project.org
> > Subject: Re: [R] Extracting values from a ecdf (empirical cumulative
> distribution function)
> > curve
> >
> > Thank you, Barradas. It works when finding y, but when I tried to find x
> > using interpolation for a known y it gives 'NA' (for whatever y value). I
> > couldn't find out the reason. Any help is really appreciated.
> >
> > Thanks,
> > Mano
> >
> >
> > On Thu, Oct 31, 2013 at 10:53 PM, Rui Barradas <
ruipba...@sapo.pt>
> > >>****
>
> > >> ______________________________**________________
> > >> posting-guide.html <
http://www.R-project.org/posting-guide.html>****
> > and provide commented, minimal, self-contained, reproducible code.****
>
> ** **