I am trying to plot this kind of behaviour of a data set. I have tried with Ecdf()
library(Hmisc)
dd<-read.table('critical.1.dat',head=F)
cdf<-Ecdf(dd$V1)
df<-hist(dd$V1)
ll<-((1-cdf$y[df$mids])/(df$density))
plot(df$mids,ll)
and seems all goes fine. After this answer i have tried with ecdf()
dd<-read.table('critical.1.dat',head=F)
cdf<-ecdf(dd$V1)
df<-hist(dd$V1)
ll<-(1-cdf(df$mids))/df$density
plot(df$mids,ll)
and the outcome looks very different Ecdf().
Where is my mistake? why they looks me different?
First Edit: My actual code is
library(Hmisc)
dd<-read.table('critical.1.dat',head=F)
cdf<-Ecdf(dd$V1)
ccdf<-ecdf(dd$V1)
df<-hist(dd$V1)
ll<-((1-cdf$y[df$mids])/(df$density))
llc<-(1-ccdf(df$mids))/df$density
par( mfrow = c( 2, 1 ) )
plot(df$mids,ll,ylab='Ecdf()')
plot(df$mids,llc,ylab='ecdf()')
Ecdfreturns a list whileecdfreturns a function:To summarize the comments below … the list representation of an ECDF needs a different access method than the functional representation. So at least one of the the mistakes was in using df$mids in
cdf$y[df$mids]when processing the return object fromEcdf(). The beauty of the base::ecdf function is that it can process an X value directly, whereas the list representation will need to use a function likefindInterval()to construct an appropriate index.