1 |
x |
|
y |
|
w |
|
sig |
|
alpha |
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 | ##---- 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, w = FALSE, sig = TRUE, alpha = 0.05)
{
x <- x[!is.na(x)]
y <- y[!is.na(y)]
w <- as.logical(w)
sig <- as.logical(sig)
tie <- logical(1)
siglevel <- NA
z <- sort(c(x, y))
tie = duplicated(z)
v <- 1
for (i in 1:length(z)) v[i] <- abs(ecdf(x, z[i]) - ecdf(y,
z[i]))
ks <- max(v)
crit = sqrt(0 - log(alpha/2) * (length(x) + length(y))/(2 *
length(x) * length(y)))
if (!w && sig && !tie)
siglevel <- kssig(length(x), length(y), ks)
if (!w && sig && tie)
siglevel <- kstiesig(x, y, ks)
if (w) {
crit <- (max(length(x), length(y)) - 5) * 0.48/95 + 2.58 +
abs(length(x) - length(y)) * 0.44/95
if (length(x) > 100 || length(y) > 100)
warning(paste("When either sample size is\ngreater than 100, the approximate critical value can be inaccurate. It is\nrecommended that the exact significance level be computed."))
for (i in 1:length(z)) {
temp <- (length(x) * ecdf(x, z[i]) + length(y) *
ecdf(y, z[i]))/length(z)
temp <- temp * (1 - temp)
v[i] <- v[i]/sqrt(temp)
}
v <- v[!is.na(v)]
ks <- max(v) * sqrt(length(x) * length(y)/length(z))
if (sig)
siglevel <- kswsig(length(x), length(y), ks)
if (tie && sig)
warning(paste("Ties were detected. The reported significance level of the\nweighted Kolmogorov-Smirnov test statistic is not exact."))
}
list(test = ks, critval = crit, p.value = siglevel)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.