1 |
x1 |
|
y1 |
|
x2 |
|
y2 |
|
fr1 |
|
fr2 |
|
est |
|
alpha |
|
pts |
|
SEED |
|
test |
|
DH |
|
FRAC |
|
cov.fun |
|
pr |
|
q |
|
plotit |
|
pv |
|
theta |
|
xlab |
|
ylab |
|
SCAT |
|
zlab |
|
... |
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 111 112 113 114 115 116 | ##---- 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, est = tmean, alpha = 0.05,
pts = NULL, SEED = TRUE, test = yuen, DH = FALSE, FRAC = 0.5,
cov.fun = skip.cov, pr = FALSE, q = 0.5, plotit = FALSE,
pv = FALSE, theta = 50, xlab = " ", ylab = " ", SCAT = FALSE,
zlab = " ", ...)
{
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.null(pts[1])) {
x1 <- as.matrix(x1)
pts <- ancdes(x1, DH = DH, FRAC = FRAC)
}
pts <- as.matrix(pts)
n1 <- 1
n2 <- 1
vecn <- 1
mval1 <- cov.fun(x1)
mval2 <- cov.fun(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(TRUE, 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))
dd = NULL
if (sum(flag) == 0) {
print("No comparable design points found, might increase span.")
pts = NULL
mat = NULL
dd = NULL
}
if (sum(flag) > 0) {
mat <- matrix(NA, nrow(pts), 6)
mat[, 5] = 0
dimnames(mat) <- list(NULL, c("n1", "n2", "p.value",
"crit.p.value", "Sig", "est.dif"))
output = list()
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)]
if (identical(test, qcomhd))
temp = qcomhd(g1, g2, q = q, plotit = FALSE)
if (!identical(test, qcomhd))
temp = test(g1, g2, ...)
if (is.null(temp$p.value))
print("Apparently argument test is a function that does not return a p-value")
mat[i, 3] = temp$p.value
output[[i]] = temp
mat[i, 1] <- length(g1)
mat[i, 2] <- length(g2)
mat[i, 6] = est(g1) - est(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, ]))
}
npt = nrow(pts)
dvec = alpha/c(1:npt)
temp2 <- order(0 - mat[, 3])
sigvec <- (mat[temp2, 3] >= dvec)
dd = 0
if (sum(sigvec) < npt)
dd <- npt - sum(sigvec)
mat[temp2, 4] = dvec
flag = mat[, 3] <= mat[, 4]
if (sum(flag) > 0)
mat[flag, 5] = 1
}
if (SCAT)
plotit = FALSE
if (DH) {
if (ncol(x1) == 2) {
if (plotit) {
if (pv)
lplot(pts, mat[, 3], xlab = xlab, ylab = ylab,
ticktype = "det", zlab = zlab, theta = theta)
if (!pv)
lplot(pts, mat[, 6], xlab = xlab, ylab = ylab,
ticktype = "det", zlab = zlab, theta = theta)
}
if (SCAT) {
chk = mat[, 5] == 1
plot(pts[!chk, 1], pts[!chk, 2], xlab = xlab,
ylab = ylab)
points(pts[chk, 1], pts[chk, 2], pch = "*")
}
}
}
list(points = pts, results = mat, num.sig = dd)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.