From p.dalgaard at biostat.ku.dk  Sun Oct 17 11:24:06 2004
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Sun Oct 17 11:27:18 2004
Subject: [Rd] ecdf with lots of ties is inefficient (PR#7292)
In-Reply-To: <Pine.LNX.4.44.0410170759090.2031-100000@gannet.stats>
References: <Pine.LNX.4.44.0410170759090.2031-100000@gannet.stats>
Message-ID: <x27jpp8zpl.fsf@biostat.ku.dk>

Prof Brian Ripley <ripley@stats.ox.ac.uk> writes:

>     vals <- sort(unique(x))
>     y <- tabulate(match(x, vals))
>     rval <- approxfun(vals, cumsum(y)/n, method = "constant", yleft = 0,
>                       yright = 1, f = 0, ties = "ordered")
> 
> should work better for you and may be little slower if there are no ties, 
> but will use more memory.

...and if all you need is the plot, continue Brian's code with

  Fv <- c(0,cumsum(y))/sum(y)
  xx <- c(vals[1],vals)
  plot(xx, Fv, type="s")

which might well be close enough for your purposes. Or, of course,

  Fs <- stepfun(vals,c(0,cumsum(y)/sum(y)))
  plot(Fs,verticals=FALSE)

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907


[Rd] ecdf with lots of ties is inefficient (PR#7292)
Peter Dalgaard