1 |
x |
|
y |
|
corfun |
|
alpha |
|
nboot |
|
SEED |
|
MC |
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 | ##---- 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, corfun = wincor, alpha = 0.05, nboot = 500, SEED = TRUE,
MC = FALSE)
{
if (nrow(x) != nrow(y))
stop("x and y have different sample sizes; should be equal")
m1 = cbind(x, y)
if (ncol(m1) != 4)
stop("Both x and y should have two columns")
m1 <- elimna(m1)
nval = nrow(m1)
x <- m1[, 1:2]
y = m1[, 3:4]
r12 = corfun(x[, 1], x[, 2])$cor
r13 = corfun(y[, 1], y[, 2])$cor
if (SEED)
set.seed(2)
data <- matrix(sample(nrow(y), size = nrow(y) * nboot, replace = TRUE),
nrow = nboot)
data = listm(t(data))
if (MC) {
library(parallel)
bvec1 <- mclapply(data, corbsub, x[, 1], x[, 2], corfun)
bvec2 <- mclapply(data, corbsub, y[, 1], y[, 2], corfun)
}
if (!MC) {
bvec1 <- lapply(data, corbsub, x[, 1], x[, 2], corfun)
bvec2 <- lapply(data, corbsub, y[, 1], y[, 2], corfun)
}
mat1 = matl(bvec1)
mat2 = matl(bvec2)
ihi <- floor((1 - alpha/2) * nboot + 0.5)
ilow <- floor((alpha/2) * nboot + 0.5)
bsort <- sort(mat1 - mat2)
ci12 <- bsort[ilow]
ci12[2] <- bsort[ihi]
ci12
pv = mean(bsort < 0)
pv = 2 * min(c(pv, 1 - pv))
list(est.rho1 = r12, est.rho2 = r13, est.dif = r12 - r13,
ci = ci12, p.value = pv)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.