1 | rfanova(x, grp = 0)
|
x |
|
grp |
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | ##---- 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, grp = 0)
{
library(MASS)
if (!is.list(x))
x <- listm(x)
chk = tlist(x)
if (chk != 0)
print("Warning: tied values detected")
xall <- NA
if (sum(grp) == 0) {
J <- length(x)
grp <- c(1:J)
}
if (sum(grp) > 0)
J <- length(grp)
nval <- 1
nrat <- 1
nmax <- 0
rbar <- 1
mrbar <- 0
for (j in grp) {
temp <- x[[j]]
temp <- temp[!is.na(temp)]
nrat[j] <- (length(temp) - 1)/length(temp)
nval[j] <- length(temp)
if (j == grp[1])
xall <- temp
if (j != grp[1])
xall <- c(xall, temp)
if (length(temp) > nmax)
nmax <- length(temp)
}
pv <- array(NA, c(J, nmax, J))
tv <- matrix(NA, J, nmax)
rv <- matrix(0, J, nmax)
for (i in 1:J) {
data <- x[[i]]
data <- data[!is.na(data)]
for (j in 1:length(data)) {
tempr <- data[j] - xall
rv[i, j] <- length(tempr[tempr >= 0])
for (l in 1:J) {
templ <- x[[l]]
templ <- templ[!is.na(templ)]
temp <- data[j] - templ
pv[i, j, l] <- length(temp[temp >= 0])
}
tv[i, j] <- sum(pv[i, j, ]) - pv[i, j, i]
}
rbar[i] <- sum(rv[i, ])/nval[i]
mrbar <- mrbar + sum(rv[i, ])
}
amat <- matrix(0, J, J)
for (i in 1:J) {
temptv <- tv[i, ]
temptv <- temptv[!is.na(temptv)]
amat[i, i] <- (length(temptv) - 1) * var(temptv)
for (l in 1:J) {
tempp <- pv[l, , i]
tempp <- tempp[!is.na(tempp)]
if (l != i) {
amat[i, i] <- amat[i, i] + (length(tempp) - 1) *
var(tempp)
}
}
for (j in 1:J) {
if (j > i) {
for (l in 1:J) {
temp1 <- pv[l, , i]
temp2 <- pv[l, , j]
temp1 <- temp1[!is.na(temp1)]
temp2 <- temp2[!is.na(temp2)]
if (i != l && l != j)
amat[i, j] <- amat[i, j] + (length(temp1) -
1) * var(temp1, temp2)
}
temp1 <- pv[i, , j]
temp2 <- tv[i, ]
temp1 <- temp1[!is.na(temp1)]
temp2 <- temp2[!is.na(temp2)]
amat[i, j] <- amat[i, j] - (length(temp1) - 1) *
var(temp1, temp2)
temp1 <- pv[j, , i]
temp2 <- tv[j, ]
temp1 <- temp1[!is.na(temp1)]
temp2 <- temp2[!is.na(temp2)]
amat[i, j] <- amat[i, j] - (length(temp1) - 1) *
var(temp1, temp2)
}
amat[j, i] <- amat[i, j]
}
}
N <- sum(nval)
amat <- amat/N^3
amati <- ginv(amat)
uvec <- 1
mrbar <- mrbar/N
for (i in 1:J) uvec[i] <- nval[i] * (rbar[i] - mrbar)/(N *
(N + 1))
testv <- N * prod(nrat) * uvec %*% amati %*% uvec
test <- testv[1, 1]
df <- J - 1
siglevel <- 1 - pchisq(test, df)
list(test = test, p.value = siglevel, df = df)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.