1 |
x1 |
|
y1 |
|
x2 |
|
y2 |
|
fr1 |
|
fr2 |
|
tr |
|
alpha |
|
pts |
|
SEED |
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 | ##---- 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 (x1, y1, x2, y2, fr1 = 1, fr2 = 1, tr = 0.2, alpha = 0.05,
pts = NA, SEED = T)
{
if (SEED)
set.seed(2)
x1 = as.matrix(x1)
p = ncol(x1)
p1 = p + 1
m1 = elimna(cbind(x1, y1))
x1 = m1[, 1:p]
y1 = m1[, p1]
x2 = as.matrix(x2)
p = ncol(x2)
p1 = p + 1
m2 = elimna(cbind(x2, y2))
x2 = m2[, 1:p]
y2 = m2[, p1]
if (is.na(pts[1])) {
x1 <- as.matrix(x1)
pts <- ancdes(x1)
}
pts <- as.matrix(pts)
if (nrow(pts) >= 29) {
print("WARNING: More than 28 design points")
print("Only first 28 are used.")
pts <- pts[1:28, ]
}
n1 <- 1
n2 <- 1
vecn <- 1
mval1 <- cov.mve(x1)
mval2 <- cov.mve(x2)
for (i in 1:nrow(pts)) {
n1[i] <- length(y1[near3d(x1, pts[i, ], fr1, mval1)])
n2[i] <- length(y2[near3d(x2, pts[i, ], fr2, mval2)])
}
flag <- rep(T, nrow(pts))
for (i in 1:nrow(pts)) if (n1[i] < 10 || n2[i] < 10)
flag[i] <- F
flag = as.logical(flag)
pts <- pts[flag, ]
if (sum(flag) == 1)
pts <- t(as.matrix(pts))
if (sum(flag) == 0)
stop("No comparable design points found, might increase span.")
mat <- matrix(NA, nrow(pts), 8)
dimnames(mat) <- list(NULL, c("n1", "n2", "DIF", "TEST",
"se", "ci.low", "ci.hi", "p.value"))
for (i in 1:nrow(pts)) {
g1 <- y1[near3d(x1, pts[i, ], fr1, mval1)]
g2 <- y2[near3d(x2, pts[i, ], fr2, mval2)]
g1 <- g1[!is.na(g1)]
g2 <- g2[!is.na(g2)]
test <- yuen(g1, g2, tr = tr)
mat[i, 1] <- length(g1)
mat[i, 2] <- length(g2)
if (length(g1) <= 5)
print(paste("Warning, there are", length(g1), " points corresponding to the design point X=",
pts[i, ]))
if (length(g2) <= 5)
print(paste("Warning, there are", length(g2), " points corresponding to the design point X=",
pts[i, ]))
mat[i, 3] <- test$dif
mat[i, 4] <- test$teststat
mat[i, 5] <- test$se
mat[i, 8] <- test$p.value
if (nrow(pts) >= 2)
critv <- smmcrit(test$df, nrow(pts))
if (nrow(pts) == 1)
critv <- qt(0.975, test$df)
cilow <- test$dif - critv * test$se
cihi <- test$dif + critv * test$se
mat[i, 6] <- cilow
mat[i, 7] <- cihi
}
list(points = pts, output = mat, crit = critv)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.