1 |
x |
|
y |
|
x1 |
|
y1 |
|
regfun |
|
nboot |
|
alpha |
|
plotit |
|
SEED |
|
xout |
|
outfun |
|
xlab |
|
ylab |
|
pr |
|
... |
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 | ##---- 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, x1, y1, regfun = tsreg, nboot = 599, alpha = 0.05,
plotit = TRUE, SEED = TRUE, xout = FALSE, outfun = outpro,
xlab = "X", ylab = "Y", pr = TRUE, ...)
{
x <- as.matrix(x)
xx <- cbind(x, y)
xx <- elimna(xx)
x <- xx[, 1:ncol(x)]
x <- as.matrix(x)
y <- xx[, ncol(x) + 1]
x1 <- as.matrix(x1)
xx1 <- cbind(x1, y1)
xx1 <- elimna(xx1)
x1 <- xx1[, 1:ncol(x1)]
x1 <- as.matrix(x1)
y1 <- xx1[, ncol(x1) + 1]
x = as.matrix(x)
x1 = as.matrix(x1)
if (xout) {
if (pr)
print("outfun now defaults to outpro rather than out")
flag1 = outfun(x, plotit = FALSE, ...)$keep
flag2 = outfun(x1, plotit = FALSE, ...)$keep
x = x[flag1, ]
y = y[flag1]
x1 = x1[flag2, ]
y1 = y1[flag2]
}
n = length(y)
n[2] = length(y1)
x <- as.matrix(x)
x1 <- as.matrix(x1)
est1 = regfun(x, y, ...)$coef
est2 = regfun(x1, y1, ...)$coef
if (SEED)
set.seed(2)
data <- matrix(sample(length(y), size = length(y) * nboot,
replace = TRUE), nrow = nboot)
bvec <- apply(data, 1, regboot, x, y, regfun, xout = FALSE,
...)
data <- matrix(sample(length(y1), size = length(y1) * nboot,
replace = TRUE), nrow = nboot)
bvec1 <- apply(data, 1, regboot, x1, y1, regfun, xout = FALSE,
...)
bvec <- bvec - bvec1
p1 <- ncol(x) + 1
regci <- matrix(0, p1, 6)
dimnames(regci) <- list(NULL, c("Parameter", "ci.lower",
"ci.upper", "p.value", "Group 1", "Group 2"))
ilow <- round((alpha/2) * nboot) + 1
ihi <- nboot - (ilow - 1)
for (i in 1:p1) {
temp <- sum(bvec[i, ] < 0)/nboot + sum(bvec[i, ] == 0)/(2 *
nboot)
regci[i, 4] <- 2 * min(temp, 1 - temp)
bsort <- sort(bvec[i, ])
regci[i, 2] <- bsort[ilow]
regci[i, 3] <- bsort[ihi]
regci[, 1] <- c(0:ncol(x))
}
regci[, 5] = est1
regci[, 6] = est2
if (ncol(x) == 1 && plotit) {
plot(c(x, x1), c(y, y1), type = "n", xlab = xlab, ylab = ylab)
points(x, y)
points(x1, y1, pch = "+")
abline(regfun(x, y, ...)$coef)
abline(regfun(x1, y1, ...)$coef, lty = 2)
}
list(n = n, output = regci)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.