1 |
x |
|
y |
|
tr |
|
alpha |
|
nboot |
|
SEED |
|
PV |
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 | ##---- 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, tr = 0.2, alpha = 0.05, nboot = 600, SEED = TRUE,
PV = FALSE)
{
if (SEED)
set.seed(2)
x <- x[!is.na(x)]
y <- y[!is.na(y)]
xcen <- x - mean(x, tr)
ycen <- y - mean(y, tr)
print("Taking bootstrap samples. Please wait.")
datax <- matrix(sample(xcen, size = length(x) * nboot, replace = TRUE),
nrow = nboot)
datay <- matrix(sample(ycen, size = length(y) * nboot, replace = TRUE),
nrow = nboot)
val <- NA
for (ib in 1:nboot) val[ib] <- yhall(datax[ib, ], datay[ib,
], tr = tr, alpha)$test.stat
temp <- yhall(x, y, tr = tr)
sigtil <- temp$sig.tilda
nhat <- temp$nu.tilda
val <- sort(val)
dif <- mean(x, tr = tr) - mean(y, tr = tr)
ilow <- round(alpha * nboot/2)
il <- ilow + 1
uval <- nboot - ilow
b.low <- 3 * ((1 + nhat * val[il] - nhat/6)^{
1/3
})/nhat - 3/nhat
uval <- nboot - ilow
b.low <- 3 * ((1 + nhat * val[il] - nhat/6)^{
1/3
})/nhat - 3/nhat
b.hi <- 3 * ((1 + nhat * val[uval] - nhat/6)^{
1/3
})/nhat - 3/nhat
ci.LOW <- dif - sigtil * b.hi
ci.UP <- dif - sigtil * b.low
pv = NULL
if (PV) {
pv = 1
flag = F
if (dif != 0) {
alpha = seq(1:100)/1000
for (i in 1:length(alpha)) {
ilow <- round(alpha[i] * nboot/2)
il <- ilow + 1
uval <- nboot - ilow
b.low <- 3 * ((1 + nhat * val[il] - nhat/6)^{
1/3
})/nhat - 3/nhat
b.hi <- 3 * ((1 + nhat * val[uval] - nhat/6)^{
1/3
})/nhat - 3/nhat
ci.low <- dif - sigtil * b.hi
ci.up <- dif - sigtil * b.low
if (ci.low > 0 || ci.up < 0) {
pv = alpha[i]
flag = T
}
if (flag)
break
}
if (!flag) {
alpha = c(1:99)/100
for (i in 1:length(alpha)) {
ilow <- round(alpha[i] * nboot/2)
il <- ilow + 1
uval <- nboot - ilow
b.low <- 3 * ((1 + nhat * val[il] - nhat/6)^{
1/3
})/nhat - 3/nhat
b.hi <- 3 * ((1 + nhat * val[uval] - nhat/6)^{
1/3
})/nhat - 3/nhat
ci.low <- dif - sigtil * b.hi
ci.up <- dif - sigtil * b.low
if (ci.low > 0 || ci.up < 0) {
pv = alpha[i]
flag = T
}
if (flag)
break
}
}
}
}
list(est.dif = dif, conf.interval = c(ci.LOW, ci.UP), p.value = pv)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.