1 |
x |
|
y |
|
regfun |
|
nboot |
|
alpha |
|
SEED |
|
pr |
|
null.val |
|
xout |
|
outfun |
|
plotit |
|
xlab |
|
ylab |
|
... |
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 | ##---- 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 = 599, alpha = 0.05, SEED = TRUE,
pr = TRUE, null.val = NULL, xout = FALSE, outfun = outpro,
plotit = FALSE, xlab = "Predictor 1", ylab = "Predictor 2",
...)
{
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]
nrem = length(y)
estit = regfun(x, y, xout = xout, ...)$coef
if (xout) {
if (pr)
print("Default for outfun is now outpro, not out")
m <- cbind(x, y)
flag <- outfun(x, plotit = FALSE, ...)$keep
m <- m[flag, ]
x <- m[, 1:p]
y <- m[, p1]
}
if (is.null(null.val))
null.val = rep(0, p1)
flagF = identical(regfun, tsreg)
if (flagF) {
if (pr) {
if (sum(duplicated(y) > 0))
print("Duplicate values detected; tshdreg might have more power than tsreg")
}
}
nv = length(y)
x <- as.matrix(x)
if (SEED)
set.seed(2)
if (pr)
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, regfun, xout = FALSE,
...)
regci <- matrix(0, p1, 5)
vlabs = "Intercept"
for (j in 2:p1) vlabs[j] = paste("Slope", j - 1)
dimnames(regci) <- list(vlabs, c("ci.low", "ci.up", "Estimate",
"S.E.", "p-value"))
ilow <- round((alpha/2) * nboot)
ihi <- nboot - ilow
ilow <- ilow + 1
se <- NA
pvec <- NA
for (i in 1:p1) {
bsort <- sort(bvec[i, ])
pvec[i] <- (sum(bvec[i, ] < null.val[i]) + 0.5 * sum(bvec[i,
] == null.val[i]))/nboot
if (pvec[i] > 0.5)
pvec[i] <- 1 - pvec[i]
regci[i, 1] <- bsort[ilow]
regci[i, 2] <- bsort[ihi]
se[i] <- sqrt(var(bvec[i, ]))
}
if (p1 == 3) {
if (plotit) {
plot(bvec[2, ], bvec[3, ], xlab = xlab, ylab = ylab)
}
}
regci[, 3] = estit
pvec <- 2 * pvec
regci[, 4] = se
regci[, 5] = pvec
list(regci = regci, n = nrem, n.keep = nv)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.