1 | MULtr.anova(x, J = NULL, p = NULL, tr = 0.2, alpha = 0.05)
|
x |
|
J |
|
p |
|
tr |
|
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | ##---- 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, J = NULL, p = NULL, tr = 0.2, alpha = 0.05)
{
if (is.matrix(x) || is.data.frame(x)) {
if (is.null(J) && is.null(p))
stop("Specify J or P")
x = MAT2list(x, p = p, J = J)
}
x = lapply(x, as.matrix)
x = lapply(x, elimna)
p = ncol(x[[1]])
iden = diag(p)
J = length(x)
tvec = list()
nval = lapply(x, nrow)
Rtil = lapply(x, wincov, tr = tr)
tvec = lapply(x, mmean, tr = tr)
g = list()
gmean = rep(0, p)
groupm = list()
Wsum = matrix(0, ncol = p, nrow = p)
W = list()
f = 0
Aw = 0
for (j in 1:J) {
tvec[[j]] = as.matrix(tvec[[j]])
g[[j]] = floor(nval[[j]] * tr)
Rtil[[j]] = Rtil[[j]] * (nval[[j]] - 1)/((nval[[j]] -
2 * g[[j]]) * (nval[[j]] - 2 * g[[j]] - 1))
f[j] = nval[[j]] - 2 * g[[j]] - 1
W[[j]] = solve(Rtil[[j]])
groupm[[j]] = apply(x[[j]], 2, tmean, tr = tr)
Wsum = Wsum + W[[j]]
gmean = gmean + W[[j]] %*% tvec[[j]]
}
Wsuminv = solve(Wsum)
for (j in 1:J) {
temp = iden - Wsuminv %*% W[[j]]
tempsq = temp %*% temp
Aw = Aw + (sum(diag(tempsq)) + (sum(diag(temp)))^2)/f[j]
}
Aw = Aw/2
gmean = as.matrix(gmean)
gmean = solve(Wsum) %*% gmean
df = p * (J - 1)
crit <- qchisq(1 - alpha, df)
crit <- crit + (crit/(2 * df)) * (Aw + 3 * Aw * crit/(df +
2))
test = 0
for (k in 1:p) {
for (m in 1:p) {
for (j in 1:J) {
test = test + W[[j]][k, m] * (groupm[[j]][m] -
gmean[m]) * (groupm[[j]][k] - gmean[k])
}
}
}
list(test.stat = test, crit.value = crit)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.