1 |
x |
|
y |
|
est |
|
nboot |
|
alpha |
|
fr |
|
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 | ##---- 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, est = tmean, nboot = 100, alpha = 0.05, fr = NA,
SEED = TRUE, ...)
{
if (!is.matrix(x))
stop("X values should be stored in a matrix")
if (ncol(x) == 1)
stop("There should be two or more predictors")
temp <- cbind(x, y)
p <- ncol(x)
p1 <- p + 1
temp <- elimna(temp)
x <- temp[, 1:p]
x <- as.matrix(x)
y <- temp[, p1]
if (alpha < 0.05 && nboot <= 100)
warning("You used alpha<.05 and nboot<=100")
if (is.na(fr)) {
fr <- 0.8
if (ncol(x) == 2) {
nval <- c(20, 30, 50, 80, 150)
fval <- c(0.4, 0.36, 0.18, 0.15, 0.09)
if (length(y) <= 150)
fr <- approx(nval, fval, length(y))$y
if (length(y) > 150)
fr <- 0.09
}
}
if (SEED)
set.seed(2)
x <- as.matrix(x)
mflag <- matrix(NA, nrow = length(y), ncol = length(y))
for (j in 1:length(y)) {
for (k in 1:length(y)) {
mflag[j, k] <- (sum(x[j, ] <= x[k, ]) == ncol(x))
}
}
yhat <- adrunl(x, y, plotit = FALSE, fr = fr, pyhat = T)
regres <- y - yhat
print("Taking bootstrap sample, please wait.")
data <- matrix(runif(length(y) * nboot), nrow = nboot)
data <- sqrt(12) * (data - 0.5)
rvalb <- apply(data, 1, adtestls1, yhat, regres, mflag, x,
fr)
rvalb <- rvalb/sqrt(length(y))
dstatb <- apply(abs(rvalb), 2, max)
wstatb <- apply(rvalb^2, 2, mean)
dstatb <- sort(dstatb)
wstatb <- sort(wstatb)
v <- c(rep(1, length(y)))
rval <- adtestls1(v, yhat, regres, mflag, x, fr)
rval <- rval/sqrt(length(y))
dstat <- max(abs(rval))
wstat <- mean(rval^2)
ib <- round(nboot * (1 - alpha))
critd <- dstatb[ib]
critw <- wstatb[ib]
list(dstat = dstat, wstat = wstat, critd = critd, critw = critw)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.