1 |
x |
|
y |
|
crit |
|
flag |
|
plotit |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (x, y, crit = (max(length(x), length(y)) - 5) * 0.48/95 +
2.58 + abs(length(x) - length(y)) * 0.44/95, flag = FALSE,
plotit = FALSE)
{
x <- x[!is.na(x)]
y <- y[!is.na(y)]
plotit <- as.logical(plotit)
flag <- as.logical(flag)
pc <- NA
if (flag) {
print("Computing the exact value of the probability coverage")
pc <- 1 - kswsig(length(x), length(y), crit)
}
xsort <- sort(x)
ysort <- sort(y)
l <- 0
u <- 0
ysort[0] <- NA
ysort[length(y) + 1] <- NA
m <- length(x) * length(y)/(length(x) + length(y))
lambda <- length(x)/(length(x) + length(y))
cc <- crit^2/m
temp1 <- 1 + cc * (1 - lambda)^2
for (ivec in 1:length(x)) {
uu <- ivec/length(x)
temp <- 0.5 * sqrt(cc^2 * (1 - lambda)^2 + 4 * cc * uu *
(1 - uu))
hminus <- (uu + 0.5 * cc * (1 - lambda) * (1 - 2 * lambda *
uu) - temp)/temp1
hplus <- (uu + 0.5 * cc * (1 - lambda) * (1 - 2 * lambda *
uu) + temp)/temp1
isub <- max(0, floor(length(y) * hminus) + 1)
l[ivec] <- ysort[isub + 1] - xsort[ivec]
if (hminus < 0)
l[ivec] = NA
isub <- max(0, floor(length(y) * hplus) + 1)
u[ivec] <- ysort[isub + 1] - xsort[ivec]
}
num <- length(l[l > 0 & !is.na(l)]) + length(u[u < 0 & !is.na(u)])
qhat <- c(1:length(x))/length(x)
m <- matrix(c(qhat, l, u), length(x), 3)
dimnames(m) <- list(NULL, c("qhat", "lower", "upper"))
if (plotit) {
temp2 <- m[, 2]
temp2 <- temp2[!is.na(temp2)]
xsort <- sort(x)
ysort <- sort(y)
del <- 0
for (i in 1:length(x)) del[i] <- ysort[round(length(y) *
i/length(x))] - xsort[i]
xaxis <- c(xsort, xsort, xsort)
yaxis <- c(del, m[, 2], m[, 3])
plot(xaxis, yaxis, type = "n", ylab = "delta", xlab = "x (first group)")
lines(xsort, del)
lines(xsort, m[, 2], lty = 2)
lines(xsort, m[, 3], lty = 2)
temp <- summary(x)
text(temp[3], min(temp2), "+")
text(temp[2], min(temp2), "o")
text(temp[5], min(temp2), "o")
}
list(m = m, crit = crit, numsig = num, pc = pc)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.