经验 CDF 函数通常由阶跃函数估计。是否有理由以这种方式而不是通过使用线性插值来完成?阶跃函数是否有任何有趣的理论特性让我们更喜欢它?
以下是两者的示例:
ecdf2 <- function (x) {
x <- sort(x)
n <- length(x)
if (n < 1)
stop("'x' must have 1 or more non-missing values")
vals <- unique(x)
rval <- approxfun(vals, cumsum(tabulate(match(x, vals)))/n,
method = "linear", yleft = 0, yright = 1, f = 0, ties = "ordered")
class(rval) <- c("ecdf", class(rval))
assign("nobs", n, envir = environment(rval))
attr(rval, "call") <- sys.call()
rval
}
set.seed(2016-08-18)
a <- rnorm(10)
a2 <- ecdf(a)
a3 <- ecdf2(a)
par(mfrow = c(1,2))
curve(a2, -2,2, main = "step function ecdf")
curve(a3, -2,2, main = "linear interpolation function ecdf")