| 1 |
### Fixme: In the following, computing and plotting should be separated |
| 2 |
|
| 3 |
###--> ./ecdf.R plot.ecdf() should get conf.type and conf.int argument!! |
| 4 |
|
| 5 |
### Also, I've posted a pre-version of this: |
| 6 |
## Date: Mon, 22 Oct 2001 19:15:35 +0200 |
| 7 |
## From: Martin Maechler <[email protected]> |
| 8 |
## Subject: [R] Re: conf.int. for ecdfs {was "Two questions"} |
| 9 |
## To: [email protected] |
| 10 |
## Cc: Kjetil Halvorsen <[email protected]>, [email protected] |
| 11 |
|
| 12 |
### Note -- this is related to the pkstwo() function inside ks.test() |
| 13 |
### ==== in stats : ~/R/D/r-devel/R/src/library/stats/R/ks.test.R |
| 14 |
|
| 15 |
ecdf.ksCI <- function(x, main = NULL, sub = NULL, |
| 16 |
xlab = deparse(substitute(x)), ci.col = "red", ...) |
| 17 |
{ |
| 18 |
force(xlab) |
| 19 |
if(is.null(main)) |
| 20 |
main <- paste0("ecdf(",deparse(substitute(x)),") + 95% K.S. bands") |
| 21 |
n <- length(x) |
| 22 |
if(is.null(sub)) |
| 23 |
sub <- paste("n = ", n) |
| 24 |
ec <- ecdf(x) |
| 25 |
xx <- get("x", envir=environment(ec))# = sort(x) |
| 26 |
yy <- get("y", envir=environment(ec)) |
| 27 |
D <- KSd(n) |
| 28 |
yyu <- pmin(yy + D, 1) |
| 29 |
yyl <- pmax(yy - D, 0) |
| 30 |
ecu <- stepfun(xx, c(yyu, 1) ) |
| 31 |
ecl <- stepfun(xx, c(yyl, yyl[n]) ) |
| 32 |
|
| 33 |
## Plots -- all calling plot.stepfun |
| 34 |
|
| 35 |
plot(ec, main = main, sub = sub, xlab = xlab, ...) |
| 36 |
plot(ecu, add=TRUE, verticals=TRUE, do.points=FALSE, |
| 37 |
col.hor= ci.col, col.vert= ci.col, ...) |
| 38 |
plot(ecl, add=TRUE, verticals=TRUE, do.points=FALSE, |
| 39 |
col.hor= ci.col, col.vert= ci.col, ...) |
| 40 |
} |
| 41 |
|
| 42 |
KSd <- function(n) |
| 43 |
{ |
| 44 |
## `approx.ksD()' |
| 45 |
## approximations for the critical level for Kolmogorov-Smirnov statistic D, |
| 46 |
## for confidence level 0.95. Taken from Bickel & Doksum, table IX, p.483 |
| 47 |
## and Lienert G.A.(1975) who attributes to Miller,L.H.(1956), JASA |
| 48 |
ifelse(n > 80, |
| 49 |
1.358/( sqrt(n) + .12 + .11/sqrt(n)),## Bickel&Doksum, table IX,p.483 |
| 50 |
|
| 51 |
splinefun(c(1:9, 10, 15, 10 * 2:8),# from Lienert |
| 52 |
c(.975, .84189, .70760, .62394, .56328,# 1:5 |
| 53 |
.51926, .48342, .45427, .43001, .40925,# 6:10 |
| 54 |
.33760, .29408, .24170, .21012,# 15,20,30,40 |
| 55 |
.18841, .17231, .15975, .14960)) (n)) |
| 56 |
} |