On Mon, Aug 22, 2011 at 4:57 PM, David Winsemius <dwinsem...@comcast.net>wrote:
> > On Aug 22, 2011, at 4:34 PM, David Winsemius wrote: > > >> On Aug 22, 2011, at 3:50 PM, R. Michael Weylandt wrote: >> >> Yes. The xCDF/yCDF objects that are returned by the ecdf function can be >>> called like functions. >>> >> >> Because they _are_ functions. >> >> > "function" %in% class(xCDF) >> [1] TRUE >> > is.function(xCDF) >> [1] TRUE >> >> You know, I spent a good 30 seconds trying to figure out how to put that, knowing that whatever I said someone would pounce on, yes it is a function on one hand, but it's not only a function on the other...the dangerous world of being the small fish in the semi-anonymous list serve pool...point definitely taken though. What's the official way to say it? "xCDF has a function class"? > >>> For example: >>> >>> x = rnrom(50); xCDF = ecdf(x); xCDF(0.3) >>> # This value tells you what fraction of x is less than 0.3 >>> >>> You can also assign this behavior to a function: >>> >>> F <- function(z) { xCDF(z) } >>> >>> F does not inherit xCDF directly though and looses the step-function-ness >>> of >>> the xCDF object. (Compare plots of F and xCDF to see one consequence) >>> >> >> Not correct. Steps are still there in the same locations. >> > Yes, but > "stepfun" %in% class(xCDF) TRUE > "stepfun" %in% class(F) FALSE is what I meant. plot.stepfun() gives those nice little dots at the jumps that plot.function() doesn't -- hence my reference to the graph. It is an admittedly minor difference though. > >> >>> So yes, you can do subtraction on this basis >>> >>> x = rnrom(50); Fx = ecdf(x); Fx <- function(z) { xCDF(z) } >>> >> >> You are adding an unnecessary function "layer". Try (after correcting the >> misspelling): >> >> xCDF(seq(-2,2,by=0.02)) == Fx(seq(-2,2,by=0.02)) # => creating Fx is >> superfluous >> >> x <- function(x){function(x) x} <==> x <- function(x){ x} >> >> "Turtles all the way down." >> > Just a stupid typo: meant to define xCDF = ecdf(x) as before: I know the extra function term is silly. I do like turtles though...preferably in chocolate than soup >> >> y = rnrom(50); yCDF = ecdf(x); Fy <- function(z) { yCDF(z) } >>> >>> F <- function(z) {Fx(z) - Fy(z)} >>> # F <- function(z) {xCDF(z)-yCDF(z)} # Another way to do the same thing >>> >> >> As this would have this: >> >> F = function(z) xCDF(z)-yCDF(z) >> plot(seq(-2,2,by=0.02), F(seq(-2,2,by=0.02)) ,type="l") >> >> Interesting plot by the way. Unit steps at Gaussian random intervals. I'm >> not sure my intuition would have gotten there all on its own. I guess that >> arises from the discreteness of the sampling. I wasn't think that ecdf was >> the inverse function but seem to remember someone (some bloke named >> Weylandt, now that I check) saying as much earlier in the day. >> >> > I take it back. Not necessarily unit jumps, Quantized, yes, but the sample > I'm looking at has jumps of 0,1,2, and 3 * 0.02 units. Poisson? (Probably > a homework problem in Feller.) That is a fun little puzzle: now I have something to ponder on the train tonight. And don't listen to that Weylandt bloke, I have it on quite good authority he doesn't actually know what he's doing. (By the way, is this a reference to the question about qexp() earlier today? I hope I said that was the inverse CDF, not the CDF itself: if so, I owe someone quite an apology...) > > > -- >> David. >> >>> >>> Hope this helps, >>> >>> Michael >>> >>> >>> On Mon, Aug 22, 2011 at 3:30 PM, Jim Silverton <jim.silver...@gmail.com> >>> **wrote: >>> >>> WHat about if you have two cdfs and you want to subtract them? Like G(x) >>>> - >>>> H(x)? Can ecdf do this? >>>> >>>> >>>> On Mon, Aug 22, 2011 at 2:24 PM, R. Michael Weylandt < >>>> michael.weyla...@gmail.com> wrote: >>>> >>>> Number 1 can be done as follows: >>>>> >>>>> x = rnorm(50); y = rnorm(50) >>>>> xCDF = ecdf(x); yCDF = ecdf(y) >>>>> >>>>> plot(xCDF) >>>>> lines(yCDF,col=2) >>>>> >>>>> For the other ones, you are going to have to be a little more specific >>>>> as >>>>> to how you want to do the approximation...but ?density might be a place >>>>> to >>>>> start for #4, assuming you meant density of the PDF. If you meant CDF, >>>>> it I >>>>> think that's implicit in number 2. >>>>> >>>>> Michael Weylandt >>>>> >>>>> On Mon, Aug 22, 2011 at 2:15 PM, Jim Silverton < >>>>> jim.silver...@gmail.com>**wrote: >>>>> >>>>> Hello all, >>>>>> >>>>>> I have two columns of numbers. I would like to do the following: >>>>>> (1) Plot both cdfs, F1 and F2 on the same graph. >>>>>> (2) Find smoothed approximations of F1 and F2 lets call them F1hat and >>>>>> F2hat >>>>>> (3) Find values for F1hat when we substitue a value of x in it. >>>>>> (4) Find the corresponding densities of the cdfs. >>>>>> Any ideas? >>>>>> >>>>>> -- >>>>>> Thanks, >>>>>> Jim. >>>>>> >>>>>> [[alternative HTML version deleted]] >>>>>> >>>>>> ______________________________**________________ >>>>>> R-help@r-project.org mailing list >>>>>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> >>>>>> PLEASE do read the posting guide >>>>>> http://www.R-project.org/**posting-guide.html<http://www.R-project.org/posting-guide.html> >>>>>> and provide commented, minimal, self-contained, reproducible code. >>>>>> >>>>>> >>>>> >>>>> >>>> >>>> -- >>>> Thanks, >>>> Jim. >>>> >>>> >>>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________**________________ >>> R-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> >>> PLEASE do read the posting guide http://www.R-project.org/** >>> posting-guide.html <http://www.R-project.org/posting-guide.html> >>> and provide commented, minimal, self-contained, reproducible code. >>> >> >> David Winsemius, MD >> West Hartford, CT >> >> ______________________________**________________ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> >> PLEASE do read the posting guide http://www.R-project.org/** >> posting-guide.html <http://www.R-project.org/posting-guide.html> >> and provide commented, minimal, self-contained, reproducible code. >> > > David Winsemius, MD > West Hartford, CT > > Michael (who has learned not to tempt the gods with imprecise references to R's class functionality :-) ) [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.