1 |
x |
|
y |
|
regfun |
|
nboot |
|
alpha |
|
xout |
|
SEED |
|
outfun |
|
... |
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 | ##---- 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 = 500, alpha = 0.05, xout = FALSE,
SEED = TRUE, outfun = out, ...)
{
if (SEED)
set.seed(2)
if (identical(regfun, Qreg))
print("When using Qreg, be sure to include res.vals=TRUE")
if (identical(regfun, tshdreg))
print("When using tshdreg, be sure to include RES=TRUE")
x <- as.matrix(x)
d <- ncol(x)
temp <- elimna(cbind(x, y))
x <- temp[, 1:d]
x <- as.matrix(x)
y <- temp[, d + 1]
if (xout) {
flag <- outfun(x, ...)$keep
x <- x[flag, ]
x <- as.matrix(x)
y <- y[flag]
}
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))
}
}
reg <- regfun(x, y, ...)
yhat <- y - reg$residuals
print("Taking bootstrap samples, please wait.")
data <- matrix(runif(length(y) * nboot), nrow = nboot)
data <- sqrt(12) * (data - 0.5)
rvalb <- apply(data, 1, lintests1, yhat, reg$residuals, mflag,
x, regfun, ...)
rvalb <- rvalb/sqrt(length(y))
dstatb <- apply(abs(rvalb), 2, max)
wstatb <- apply(rvalb^2, 2, mean)
v <- c(rep(1, length(y)))
rval <- lintests1(v, yhat, reg$residuals, mflag, x, regfun,
...)
rval <- rval/sqrt(length(y))
dstat <- max(abs(rval))
wstat <- mean(rval^2)
ib <- round(nboot * (1 - alpha))
p.value.d <- 1 - sum(dstat >= dstatb)/nboot
p.value.w <- 1 - sum(wstat >= wstatb)/nboot
list(dstat = dstat, wstat = wstat, p.value.d = p.value.d,
p.value.w = p.value.w)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.