On 21 Jul 2003 at 15:42, Leif.Boysen wrote: Here are some functions doing this using the package stepfun:
ecdf.ksCI <- function(x, main = NULL, sub = NULL, xlab = deparse(substitute(x)), ...) { require(stepfun) xlab if(is.null(main)) main <- paste("ecdf(",deparse(substitute(x)),") + 95% K.S.bands", sep="") n <- length(x) if(is.null(sub)) sub <- paste("n = ", n) ec <- ecdf(x) xx <- get("x", envir=environment(ec))# = sort(x) yy <- get("y", envir=environment(ec)) D <- approx.ksD(n) yyu <- pmin(yy+D, 1) yyl <- pmax(yy-D, 0) ecu <- stepfun(xx, c(yyu, 1) ) ecl <- stepfun(xx, c(yyl, yyl[n]) ) ## Plots -- all calling plot.stepfun plot(ec, main = main, sub = sub, xlab = xlab, ...) plot(ecu, add=TRUE, verticals=TRUE, do.points=FALSE, col.hor="red" , col.vert="red", ...) plot(ecl, add=TRUE, verticals=TRUE, do.points=FALSE, col.hor="red", col.vert="red", ...) } approx.ksD <- function(n) { ## approximations for the critical level for Kolmogorov-Smirnov ## statistic D, ## for confidence level 0.95. Taken from Bickel & Doksum, table IX, ## p.483 ## and Lienert G.A.(1975) who attributes to Miller,L.H.(1956), JASA ifelse(n > 80, 1.358 /( sqrt(n) + .12 + .11/sqrt(n)),##Bickel&Doksum, table ##IX,p.483 splinefun(c(1:9, 10, 15, 10 * 2:8),# from Lienert c(.975, .84189, .70760, .62394, .56328,# 1:5 .51926, .48342, .45427, .43001, .40925,# 6:10 .33760, .29408, .24170, .21012,# 15,20,30,40 .18841, .17231, .15975, .14960)) (n)) } \name{ecdf.ksCI} \alias{ecdf.ksCI} \title{ Plotting the empirical distribution function together with confidence curves. } \description{ Plots the empirical distribution function for one- dimensional data, together with upper and lower confidence curves. Always uses pointwise confidence level of 95\%. } \usage{ ecdf.ksCI(x, main=NULL, sub=NULL, xlab = deparse(substitute(x)), ...) } %- maybe also `usage' for other objects documented here. \arguments{ \item{x}{ \code{x} numerical vector of observations. } \item{\dots}{ \code{\dots} arguments given to \code{\link{plot.stepfun}}.} } \details{ Uses the \code{\link{stepfun}} package. } \value{ Nothing. Used for its side effect, to produce a plot. } \references{ Peter J. Bickel & Kjell A. Doksum: Mathematical Statistics, Basic Ideas and Selected Topics. Holden-Day, 1977. } \author{ Kjetil Halvorsen } \seealso{ \code{\link{ecdf}} and \code{\link{plot.stepfun}} in package \code{\link{stepfun}}. } \examples{ ecdf.ksCI( rchisq(50,3) ) } \keyword{ hplot } \keyword{nonparametric} Kjetil Halvorsen > Hi, > > I was trying to draw an empirical distribution function with uniform > confidence bands. So I tried to find a way to calculate values of the > Kolmogorov-Smirnov Distribution but failed. > I guess it must be hidden somewhere (since the ks-test is implemented), > but I was unable to find it. > > Is there any way to do this? > > Thanks > > Leif Boysen > > ______________________________________________ > [EMAIL PROTECTED] mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help ______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help