ecdf.ks <- function(x, f=pnorm, col2="#00000010", accent="#d02020", cex=0.6,
limits=FALSE, ...) {
obj <- ecdf(x)
x <- sort(x)
n <- length(x)
y <- f(x) - (0:(n - 1))/n
p <- pmax(y, 1/n - y)
dp <- max(p)
i <- which(p >= dp)[1]
q <- ifelse(f(x[i]) > (i-1)/n, (i-1)/n, i/n)
# if (dp != ks.test(x, f)$statistic) stop("Incorrect.")
plot(obj, col=col2, cex=cex, ...)
points(x[i], q, col=accent, pch=19, cex=cex)
if (limits) {
curve(pmin(1, f(x)+dp), add=TRUE, col=accent)
curve(pmax(0, f(x)-dp), add=TRUE, col=accent)
}
c(i, dp)
}
ecdf.ks <- function(x, f=pnorm, col2="#00000010", accent="#d02020", cex=0.6,
limits=FALSE, ...) {
obj <- ecdf(x)
x <- sort(x)
n <- length(x)
y <- f(x) - (0:(n - 1))/n
p <- pmax(y, 1/n - y)
dp <- max(p)
i <- which(p >= dp)[1]
q <- ifelse(f(x[i]) > (i-1)/n, (i-1)/n, i/n)
# if (dp != ks.test(x, f)$statistic) stop("Incorrect.")
plot(obj, col=col2, cex=cex, ...)
points(x[i], q, col=accent, pch=19, cex=cex)
if (limits) {
curve(pmin(1, f(x)+dp), add=TRUE, col=accent)
curve(pmax(0, f(x)-dp), add=TRUE, col=accent)
}
c(i, dp)
}