1 |
x |
|
y |
|
regfun |
|
nboot |
|
alpha |
|
plotit |
|
grp |
|
nullvec |
|
xout |
|
outfun |
|
SEED |
|
pr |
|
... |
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 | ##---- 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, y, regfun = tsreg, nboot = 600, alpha = 0.05, plotit = TRUE,
grp = c(1:ncol(x)), nullvec = c(rep(0, length(grp))), xout = FALSE,
outfun = outpro, SEED = TRUE, pr = TRUE, ...)
{
library(parallel)
x <- as.matrix(x)
p1 <- ncol(x) + 1
p <- ncol(x)
xy <- cbind(x, y)
xy <- elimna(xy)
x <- xy[, 1:p]
y <- xy[, p1]
if (xout) {
if (pr)
print("Default for outfun is now outpro")
m <- cbind(x, y)
flag <- outfun(x, plotit = FALSE, ...)$keep
m <- m[flag, ]
x <- m[, 1:p]
y <- m[, p1]
}
x <- as.matrix(x)
if (length(grp) != length(nullvec))
stop("The arguments grp and nullvec must have the same length.")
if (SEED)
set.seed(2)
data <- matrix(sample(length(y), size = length(y) * nboot,
replace = TRUE), nrow = nboot)
data = listm(t(data))
bvec = mclapply(data, regbootMC, x, y, regfun, mc.preschedule = TRUE)
bvec = matl(bvec)
grp <- grp + 1
est <- regfun(x, y)$coef
estsub <- est[grp]
bsub <- t(bvec[grp, ])
if (length(grp) == 1) {
m1 <- sum((bvec[grp, ] - est)^2)/(length(y) - 1)
dis <- (bsub - estsub)^2/m1
}
if (length(grp) > 1) {
mvec <- apply(bsub, 2, FUN = mean)
m1 <- var(t(t(bsub) - mvec + estsub))
dis <- mahalanobis(bsub, estsub, m1)
}
dis2 <- order(dis)
dis <- sort(dis)
critn <- floor((1 - alpha) * nboot)
crit <- dis[critn]
test <- mahalanobis(t(estsub), nullvec, m1)
sig.level <- 1 - sum(test > dis)/nboot
if (length(grp) == 2 && plotit) {
plot(bsub, xlab = "Parameter 1", ylab = "Parameter 2")
points(nullvec[1], nullvec[2], pch = 0)
xx <- bsub[dis2[1:critn], ]
xord <- order(xx[, 1])
xx <- xx[xord, ]
temp <- chull(xx)
lines(xx[temp, ])
lines(xx[c(temp[1], temp[length(temp)]), ])
}
list(test = test, crit = crit, sig.level = sig.level, nullvec = nullvec,
est = estsub)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.