Dear all, I would like to calculate the complementary cumulative distribution function. As it is known, the ccdf is the 1-ecdf(X)==1-F(x). (From ?ecdf help is shown that ecdf returns a function which is the F(x) I would like to use that function inside my function and after call curve (which accepts function as input). My code looks like that onVector<-seq(1:100) offVector<-seq(101:200) myecdfOn<-function(onVector){1-ecdf(onVector)} # This gives the ccdf curve(myecdfOn,from=1,to=max(c(onVector,offVector)), add=TRUE,lwd=2) Unfortunately fails and I can not really see what is he problem of it. Could you please help me? B.R Alex [[alternative HTML version deleted]]
On Apr 24, 2012, at 4:47 AM, Alaios wrote:> Dear all, > I would like to calculate the complementary cumulative distribution > function. As it is known, the ccdf is the 1-ecdf(X)==1-F(x). (From ? > ecdf help is shown that ecdf returns a function which is the F(x) > > I would like to use that function inside my function and after call > curve (which accepts function as input). My code looks like that > > > onVector<-seq(1:100) > offVector<-seq(101:200)Heh, .... I've made that mistake myself. It's a difficult one for the brain to catch. Unfortunately it does not throw an error. (Arguably this is an infelicity that should be flagged with at least a warning.)> myecdfOn<-function(onVector){1-ecdf(onVector)} # This gives the ccdfI do not think it does. Have your tried to do anything with it?> > curve(myecdfOn,from=1,to=max(c(onVector,offVector)), add=TRUE,lwd=2) > > Unfortunately fails and I can not really see what is he problem of it.Try reading the error message more closely (... and next time post it.)>-- David Winsemius, MD West Hartford, CT
Hello, Alaios, take a look at the help page of ecdf() where it says that the result of ecdf(x) is a 'function (!) of class "ecdf"', not a vector of function values. Take a look at what> 1- ecdf(onVector)(onVector)does, and maybe> myecdfOn <- function( x) { 1- ecdf(x)(x)}followed by> myecdfOn( OnVector)does what you want, and can finally be input to curve(). HtH -- Gerrit On Tue, 24 Apr 2012, Alaios wrote:> Dear all, I would like to calculate the complementary cumulative > distribution function. As it is known, the ccdf is the > 1-ecdf(X)==1-F(x). (From ?ecdf help is shown that ecdf returns a > function which is the F(x) > > > I would like to use that function inside my function and after call > curve (which accepts function as input). My code looks like that > > > > > onVector<-seq(1:100) > offVector<-seq(101:200) > myecdfOn<-function(onVector){1-ecdf(onVector)} # This gives the ccdf > > curve(myecdfOn,from=1,to=max(c(onVector,offVector)), add=TRUE,lwd=2) > > > > > > Unfortunately fails and I can not really see what is he problem of it. > > Could you please help me? > > B.R > Alex > > [[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.