1 |
m1 |
|
m2 |
|
cop |
|
pr |
|
plotit |
|
pop |
|
fr |
|
op |
|
dop |
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 | ##---- 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 (m1, m2, cop = 5, pr = TRUE, plotit = TRUE, pop = 1,
fr = 0.8, op = 1, dop = 1)
{
library(akima)
if (is.null(dim(m1)))
stop("m1 is not a matrix or data frame")
if (is.null(dim(m2)))
stop("m2 is not a matrix or data frame")
if (ncol(m1) != ncol(m2))
stop("number of columns for m1 and m2 are not equal")
if (ncol(m1) == 1)
stop("Use R function cid or bmp")
nn <- min(c(nrow(m1), nrow(m2)))
mdif <- matrix(as.vector(outer(m1[, 1], m2[, 1], "-")), ncol = 1)
for (j in 2:ncol(m1)) {
mdif <- cbind(mdif, matrix(as.vector(outer(m1[, j], m2[,
j], "-")), ncol = 1))
}
if (op == 1) {
if (ncol(m1) == 2)
temp2 <- depth2(rbind(mdif, c(rep(0, ncol(m1)))))
if (ncol(m1) > 2) {
if (cop == 1)
center <- dmean(mdif, tr = 0.5, dop = dop)
if (cop == 2)
center <- cov.mcd(mdif)$center
if (cop == 3)
center <- apply(mdif, 2, median)
if (cop == 4)
center <- cov.mve(mdif)$center
if (cop == 5)
center <- smean(mdif)
temp2 <- fdepth(rbind(mdif, c(rep(0, ncol(m1)))))
}
}
if (op == 2) {
temp2 <- pdis(rbind(mdif, c(rep(0, ncol(m1)))))
temp2 <- 1/(temp2 + 1)
}
center <- dmean(mdif, tr = 0.5, dop = dop)
phat <- temp2[nrow(mdif) + 1]/max(temp2)
crit <- NA
alpha <- c(0.1, 0.05, 0.025, 0.01)
crit[1] <- 1 - 1.6338/sqrt(nn)
crit[2] <- 1 - 1.8556/sqrt(nn)
crit[3] <- 1 - 2.0215/sqrt(nn)
crit[4] <- 1 - 2.1668/sqrt(nn)
if (pr) {
print("For alpha=.1,.05,.025,.01, the correspoding critical values are")
print(crit)
print("Reject if phat is less than or equal to the critical value")
}
if (plotit && ncol(m1) == 2) {
if (pop == 2)
rdplot(mdif, fr = fr)
if (pop == 1) {
plot(mdif[, 1], mdif[, 2], xlab = "VAR 1", ylab = "VAR 2",
type = "n")
points(mdif[, 1], mdif[, 2], pch = ".")
points(center[1], center[2], pch = "o")
points(0, 0, pch = "+")
}
if (pop == 3)
akerdmul(mdif, fr = fr)
}
list(phat = phat, center = center, crit.val = crit)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.