1 |
x |
|
y |
|
nboot |
|
alpha |
|
qval |
|
q |
|
SEED |
|
pr |
|
xout |
|
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 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 | ##---- 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, nboot = 100, alpha = 0.05, qval = 0.5, q = NULL,
SEED = TRUE, pr = TRUE, xout = FALSE, outfun = outpro, ...)
{
if (!is.null(q))
qval = q
xx <- elimna(cbind(x, y))
np <- ncol(xx)
p <- np - 1
y <- xx[, np]
x <- xx[, 1:p]
x <- as.matrix(x)
if (xout) {
x <- as.matrix(x)
flag <- outfun(x, plotit = FALSE, ...)$keep
x <- x[flag, ]
y <- y[flag]
}
x <- as.matrix(x)
n <- length(y)
if (SEED)
set.seed(2)
if (pr)
print("Taking bootstrap samples. Please wait.")
data <- matrix(sample(length(y), size = length(y) * nboot,
replace = T), nrow = nboot)
crit <- NA
if (alpha == 0.1)
crit <- 1.645 - 1.19/sqrt(n)
if (alpha == 0.05)
crit <- 1.96 - 1.37/sqrt(n)
if (alpha == 0.025)
crit <- 2.24 - 1.18/sqrt(n)
if (alpha == 0.01)
crit <- 2.58 - 1.69/sqrt(n)
crit.fwe <- crit
if (length(qval) == 2 || p == 2) {
if (alpha == 0.1)
crit.fwe <- 1.98 - 1.13/sqrt(n)
if (alpha == 0.05)
crit.fwe <- 2.37 - 1.56/sqrt(n)
if (alpha == 0.025)
crit.fwe <- 2.6 - 1.04/sqrt(n)
if (alpha == 0.01)
crit.fwe <- 3.02 - 1.35/sqrt(n)
}
if (length(qval) == 3 || p == 3) {
if (alpha == 0.1)
crit.fwe <- 2.145 - 1.31/sqrt(n)
if (alpha == 0.05)
crit.fwe <- 2.49 - 1.49/sqrt(n)
if (alpha == 0.025)
crit.fwe <- 2.86 - 1.52/sqrt(n)
if (alpha == 0.01)
crit.fwe <- 3.42 - 1.85/sqrt(n)
}
if (is.na(crit.fwe)) {
print("Could not determine a critical value")
print("Only alpha=.1, .05, .025 and .01 are allowed")
}
if (p == 1) {
bvec <- apply(data, 1, Qindbt.sub, x, y, q = qval)
estsub <- NA
for (i in 1:length(qval)) {
estsub[i] <- Qreg(x, y, q = qval[i])$coef[2]
}
if (is.matrix(bvec))
se.val <- sqrt(apply(bvec, 1, FUN = var))
if (!is.matrix(bvec))
se.val <- sqrt(var(bvec))
test <- abs(estsub)/se.val
ci.mat <- matrix(nrow = length(qval), ncol = 3)
dimnames(ci.mat) <- list(NULL, c("Quantile", "ci.lower",
"ci.upper"))
ci.mat[, 1] <- qval
ci.mat[, 2] <- estsub - crit * se.val
ci.mat[, 3] <- estsub + crit * se.val
}
if (p > 1) {
if (length(qval) > 1) {
print("With p>1 predictors,only the first qval value is used")
}
bvec <- apply(data, 1, regboot, x, y, regfun = Qreg,
qval = qval[1])
se.val <- sqrt(apply(bvec, 1, FUN = var))
estsub <- Qreg(x, y, q = qval[1])$coef
test <- abs(estsub)/se.val
ci.mat <- matrix(nrow = np, ncol = 3)
dimnames(ci.mat) <- list(NULL, c("Predictor", "ci.lower",
"ci.upper"))
ci.mat[, 1] <- c(0:p)
ci.mat[, 2] <- estsub - crit * se.val
ci.mat[, 3] <- estsub + crit * se.val
}
list(n = length(y), test = test, se.val = se.val, crit.val = crit,
crit.fwe = crit.fwe, est.values = estsub, ci = ci.mat)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.