1 |
x |
|
y |
|
nboot |
|
alpha |
|
SEED |
|
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 | ##---- 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 = 599, alpha = 0.05, SEED = TRUE, xout = FALSE,
outfun = out)
{
x <- as.matrix(x)
p <- ncol(x)
pp <- p + 1
temp <- elimna(cbind(x, y))
x <- temp[, 1:p]
y <- temp[, p + 1]
if (xout) {
m <- cbind(x, y)
flag <- outfun(x, plotit = FALSE)$keep
m <- m[flag, ]
x <- m[, 1:p]
y <- m[, pp]
}
x <- as.matrix(x)
if (SEED)
set.seed(2)
print("Taking bootstrap samples; please wait")
data <- matrix(sample(length(y), size = length(y) * nboot,
replace = TRUE), nrow = nboot)
bvec <- apply(data, 1, regboot, x, y, lsfit)
if (p == 1) {
if (alpha != 0.05) {
print("Resetting alpha to .05")
print("With p=1, unknown how to adjust confidence interval")
print("when alpha is not equal to .05.")
}
ilow <- 15
ihi <- 584
if (length(y) < 250) {
ilow <- 13
ihi <- 586
}
if (length(y) < 180) {
ilow <- 10
ihi <- 589
}
if (length(y) < 80) {
ilow <- 7
ihi <- 592
}
if (length(y) < 40) {
ilow <- 6
ihi <- 593
}
ilow <- round((ilow/599) * nboot)
ihi <- round((ihi/599) * nboot)
}
if (p > 1) {
ilow <- round(alpha * nboot/2) + 1
ihi <- nboot - ilow
}
lsfitci <- matrix(0, ncol(x), 2)
for (i in 1:ncol(x)) {
ip <- i + 1
bsort <- sort(bvec[ip, ])
lsfitci[i, 1] <- bsort[ilow + 1]
lsfitci[i, 2] <- bsort[ihi]
}
bsort <- sort(bvec[1, ])
interceptci <- c(bsort[15], bsort[584])
crit.level <- NA
pmat <- NA
if (p > 1) {
crit.level <- alpha/p
pmat <- matrix(NA, nrow = p, ncol = 2)
dimnames(pmat) <- list(NULL, c("Slope", "p-value"))
for (pv in 1:p) {
pmat[pv, 1] <- pv
pp <- pv + 1
pmat[pv, 2] <- (sum(bvec[pp, ] < 0) + 0.5 * sum(bvec[pp,
] == 0))/nboot
temp3 <- 1 - pmat[pv, 2]
pmat[pv, 2] <- 2 * min(pmat[pv, 2], temp3)
}
}
list(intercept.ci = interceptci, slope.ci = lsfitci, crit.level = crit.level,
p.values = pmat)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.