Yes. The xCDF/yCDF objects that are returned by the ecdf function can be
called like functions.
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)
So yes, you can do subtraction on this basis
x = rnrom(50); xCDF = ecdf(x); Fx <- function(z) { xCDF(z) }
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
Hope this helps,
Michael
On Mon, Aug 22, 2011 at 3:30 PM, Jim Silverton
<jim.silverton@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@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@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
>>> 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]]