1 |
J |
|
K |
|
data |
|
tr |
|
grp |
|
p |
|
MAT |
|
grpc |
|
coln |
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 | ##---- 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 (J, K, data, tr = 0.2, grp = c(1:p), p = J * K, MAT = FALSE,
grpc = 1, coln = c(2:3))
{
if (is.data.frame(data))
data = as.matrix(data)
if (MAT)
data = selbybw(data, grpc = grpc, coln = coln)$x
x <- data
if (is.matrix(x) || is.data.frame(x)) {
y <- list()
for (j in 1:ncol(x)) y[[j]] <- x[, j]
data <- y
}
if (!is.list(data))
stop("Data are not stored in list mode or a matrix")
if (p != length(data)) {
print("The total number of groups, based on the specified levels, is")
print(p)
print("The number of groups in data is")
print(length(data))
print("Warning: These two values are not equal")
}
if (p != length(grp))
stop("Apparently a subset of the groups was specified that does not match the total number of groups indicated by the values for J and K.")
tmeans <- 0
h <- 0
v <- matrix(0, p, p)
klow <- 1 - K
kup <- 0
for (i in 1:p) tmeans[i] <- mean(data[[grp[i]]], tr, na.rm = TRUE)
for (j in 1:J) {
h[j] <- length(data[[grp[j]]]) - 2 * floor(tr * length(data[[grp[j]]]))
klow <- klow + K
kup <- kup + K
sel <- c(klow:kup)
v[sel, sel] <- covmtrim(data[grp[klow:kup]], tr)
}
ij <- matrix(c(rep(1, J)), 1, J)
ik <- matrix(c(rep(1, K)), 1, K)
jm1 <- J - 1
cj <- diag(1, jm1, J)
for (i in 1:jm1) cj[i, i + 1] <- 0 - 1
km1 <- K - 1
ck <- diag(1, km1, K)
for (i in 1:km1) ck[i, i + 1] <- 0 - 1
cmat <- kron(cj, ik)
Qa <- johansp(cmat, tmeans, v, h, J, K)
cmat <- kron(ij, ck)
Qb <- johansp(cmat, tmeans, v, h, J, K)
cmat <- kron(cj, ck)
Qab <- johansp(cmat, tmeans, v, h, J, K)
list(Qa = Qa$teststat, Qa.p.value = Qa$p.value, Qb = Qb$teststat,
Qb.p.value = Qb$p.value, Qab = Qab$teststat, Qab.p.value = Qab$p.value)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.