[R] CDFs

David Winsemius dwinsemius at comcast.net
Mon Aug 22 22:57:31 CEST 2011


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
>
>>
>> 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.
>
>>
>> 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."
>
>
>> 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.)

> -- 
> David.
>>
>> Hope this helps,
>>
>> Michael
>>
>>
>> On Mon, Aug 22, 2011 at 3:30 PM, Jim Silverton <jim.silverton at 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.weylandt at 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.silverton at 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 at 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.
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Thanks,
>>> Jim.
>>>
>>>
>>
>> 	[[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at 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.
>
> David Winsemius, MD
> West Hartford, CT
>
> ______________________________________________
> R-help at 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list