[R] [Plea to the R Gods] Theoretical and Empirical CDFs

Patrick Breheny patrick.breheny at uky.edu
Thu Jun 2 13:56:23 CEST 2011


On 06/02/2011 02:18 AM, teriri wrote:
> I have generated a plot of two empirical CDFs (attachment 1). As a
> result, they are stepwise when plotted.
>  ...
> But what I need instead are smooth curves, similar to ones that are
> generated from a theoretical cdf (attachment 2).

To obtain a smooth curve, you would need to estimate the density, which, 
from a statistical standpoint, is a vastly different problem.  Once you 
have a density, however, you could integrate it to obtain the cdf:

x <- rnorm(10)
fit <- density(x)
plot(fit$x[-1],diff(fit$x)*cumsum(fit$y)[-1],type="l")
## For comparison:
plot(ecdf(x),add=TRUE,do.points=FALSE,verticals=TRUE)

Please be aware, however, that density estimation is a complicated topic 
with an extensive literature.

-- 
Patrick Breheny
Assistant Professor
Department of Biostatistics
Department of Statistics
University of Kentucky



More information about the R-help mailing list