1 |
x |
|
tr |
|
grp |
|
MAT |
|
lev.col |
|
var.col |
|
nboot |
|
SEED |
|
pr |
|
IV |
|
loc.fun |
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 | ##---- 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, tr = 0.2, grp = NA, MAT = FALSE, lev.col = 1, var.col = 2,
nboot = 100, SEED = TRUE, pr = TRUE, IV = NULL, loc.fun = median)
{
library(MASS)
if (SEED)
set.seed(2)
if (is.data.frame(x))
x = as.matrix(x)
if (MAT) {
if (!is.matrix(x))
stop("With MAT=T, data must be stored in a matrix")
if (length(lev.col) != 1)
stop("Argument lev.col should have 1 value")
temp = selby(x, lev.col, var.col)
x = temp$x
grp2 = rank(temp$grpn)
x = x[grp2]
}
if (!is.null(IV[1])) {
if (pr)
print("Assuming x is a vector containing all of the data, the dependent variable")
xi = elimna(cbind(x, IV))
x = fac2list(xi[, 1], xi[, 2])
}
if (is.matrix(x))
x <- listm(x)
if (is.na(sum(grp[1])))
grp <- c(1:length(x))
if (!is.list(x))
stop("Data are not stored in a matrix or in list mode.")
J <- length(grp)
h <- vector("numeric", J)
w <- vector("numeric", J)
xbar <- vector("numeric", J)
pts = NULL
nval = 0
for (j in 1:J) x[[j]] = elimna(x[[j]])
for (j in 1:J) {
val <- x[[j]]
val <- elimna(val)
nval[j] = length(val)
pts = c(pts, val)
x[[j]] <- val
h[j] <- length(x[[grp[j]]]) - 2 * floor(tr * length(x[[grp[j]]]))
if (winvar(x[[grp[j]]], tr) == 0)
print(paste("The Winsorized variance is zero for group",
j))
w[j] <- h[j] * (h[j] - 1)/((length(x[[grp[j]]]) - 1) *
winvar(x[[grp[j]]], tr))
xbar[j] <- mean(x[[grp[j]]], tr)
}
u <- sum(w)
xtil <- sum(w * xbar)/u
A <- sum(w * (xbar - xtil)^2)/(J - 1)
B <- 2 * (J - 2) * sum((1 - w/u)^2/(h - 1))/(J^2 - 1)
TEST <- A/(B + 1)
nu1 <- J - 1
nu2 <- 1/(3 * sum((1 - w/u)^2/(h - 1))/(J^2 - 1))
sig <- 1 - pf(TEST, nu1, nu2)
nv = lapply(x, length)
chkn = var(nval)
if (chkn == 0) {
top = var(xbar)
bot = winvarN(pts, tr = tr)
e.pow = top/bot
}
if (chkn != 0) {
vals = 0
N = min(nval)
xdat = list()
for (i in 1:nboot) {
for (j in 1:J) {
xdat[[j]] = sample(x[[j]], N)
}
vals[i] = t1way.effect(xdat, tr = tr)$Var.Explained
}
e.pow = loc.fun(vals, na.rm = TRUE)
}
list(TEST = TEST, nu1 = nu1, nu2 = nu2, n = nv, p.value = sig,
Var.Explained = e.pow, Effect.Size = sqrt(e.pow))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.