1 | ancovaV2(x1 = NULL, y1 = NULL, x2 = NULL, y2 = NULL, fr1 = 1, fr2 = 1, p.crit = NULL, padj = FALSE, pr = TRUE, method = "hochberg", FAST = TRUE, est = tmean, alpha = 0.05, plotit = TRUE, xlab = "X", ylab = "Y", qpts = FALSE, qvals = c(0.25, 0.5, 0.75), sm = FALSE, xout = FALSE, eout = FALSE, outfun = out, LP = TRUE, nboot = 500, SEED = TRUE, nreps = 2000, MC = FALSE, nmin = 12, q = 0.5, SCAT = TRUE, pch1 = "*", pch2 = "+", ...)
|
x1 |
|
y1 |
|
x2 |
|
y2 |
|
fr1 |
|
fr2 |
|
p.crit |
|
padj |
|
pr |
|
method |
|
FAST |
|
est |
|
alpha |
|
plotit |
|
xlab |
|
ylab |
|
qpts |
|
qvals |
|
sm |
|
xout |
|
eout |
|
outfun |
|
LP |
|
nboot |
|
SEED |
|
nreps |
|
MC |
|
nmin |
|
q |
|
SCAT |
|
pch1 |
|
pch2 |
|
... |
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | ##---- 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 (x1 = NULL, y1 = NULL, x2 = NULL, y2 = NULL, fr1 = 1,
fr2 = 1, p.crit = NULL, padj = FALSE, pr = TRUE, method = "hochberg",
FAST = TRUE, est = tmean, alpha = 0.05, plotit = TRUE, xlab = "X",
ylab = "Y", qpts = FALSE, qvals = c(0.25, 0.5, 0.75), sm = FALSE,
xout = FALSE, eout = FALSE, outfun = out, LP = TRUE, nboot = 500,
SEED = TRUE, nreps = 2000, MC = FALSE, nmin = 12, q = 0.5,
SCAT = TRUE, pch1 = "*", pch2 = "+", ...)
{
if (SEED)
set.seed(2)
if (pr) {
if (!FAST) {
if (!MC & is.null(p.crit))
print("For faster execution time, set MC=TRUE, assuming a multi-core processor is available")
}
}
if (padj)
p.crit = 0
if (ncol(as.matrix(x1)) > 1)
stop("One covariate only is allowed with this function")
if (length(x1) != length(y1))
stop("x1 and y1 have different lengths")
if (length(x2) != length(y2))
stop("x2 and y2 have different lengths")
xy1 = elimna(cbind(x1, y1))
xy2 = elimna = cbind(x2, y2)
n1 = nrow(xy1)
n2 = nrow(xy2)
if (plotit) {
ef = identical(est, hd)
if (!ef)
runmean2g(xy1[, 1], xy1[, 2], xy2[, 1], xy2[, 2],
fr = fr1, est = est, sm = sm, xout = xout, LP = LP,
eout = eout, xlab = xlab, ylab = ylab, SCAT = SCAT,
pch1 = pch1, pch2 = pch2, ...)
if (ef)
runmean2g(xy1[, 1], xy1[, 2], xy2[, 1], xy2[, 2],
fr = fr1, est = hd, sm = sm, xout = xout, LP = LP,
q = q, eout = eout, xlab = xlab, ylab = ylab,
SCAT = SCAT, pch1 = pch1, pch2 = pch2, ...)
}
if (is.null(p.crit)) {
if (FAST) {
if (alpha == 0.05) {
nm = max(c(n1, n2))
if (nm <= 800) {
nv = c(50, 60, 80, 100, 200, 300, 500, 800)
if (qpts) {
pv = c(0.02709, 0.0283, 0.0306, 0.02842,
0.02779, 0.0241, 0.02683, 0.01868, 0.02122)
p.crit = lplot.pred(1/nv, pv, 1/n1)$yhat
}
if (!qpts) {
pv = c(0.020831, 0.017812, 0.015796, 0.014773,
0.012589, 0.015664, 0.011803, 0.012479)
p.crit = lplot.pred(1/nv, pv, 1/n1)$yhat
}
}
}
}
}
if (is.null(p.crit)) {
p.crit = ancovaV2.pv(n1, n2, nreps = nreps, MC = MC,
qpts = qpts, est = est, qvals = qvals, SEED = SEED,
alpha = alpha, nboot = nboot)$p.crit
}
pts = NULL
if (qpts)
for (i in 1:length(qvals)) pts = c(pts, qest(xy1[, 1],
qvals[i]))
if (!qpts)
pts = ancova(x1, y1, x2, y2, pr = FALSE, plotit = FALSE)$output[,
1]
if (SEED)
set.seed(2)
ef = identical(est, hd)
est1 = NA
est2 = NA
J = length(pts)
est1 = matrix(NA, nrow = nboot, ncol = J)
est2 = matrix(NA, nrow = nboot, ncol = J)
data1 = matrix(sample(n1, size = n1 * nboot, replace = TRUE),
ncol = nboot, nrow = n1)
data2 = matrix(sample(n2, size = n2 * nboot, replace = TRUE),
ncol = nboot, nrow = n2)
if (!MC) {
if (!ef) {
est1 = apply(data1, 2, DancGLOB_sub, xy = xy1[, 1:2],
pts = pts, est = est, fr = fr1, nmin = nmin,
...)
est2 = apply(data2, 2, DancGLOB_sub, xy = xy2[, 1:2],
pts = pts, est = est, fr = fr2, nmin = nmin,
...)
}
if (ef) {
est1 = apply(data1, 2, DancGLOB_sub, xy = xy1[, 1:2],
pts = pts, est = hd, fr = fr1, nmin = nmin, q = q,
...)
est2 = apply(data2, 2, DancGLOB_sub, xy = xy2[, 1:2],
pts = pts, est = hd, fr = fr2, nmin = nmin, q = q,
...)
}
est1 = t(as.matrix(est1))
est2 = t(as.matrix(est2))
}
if (MC) {
library(parallel)
data1 = listm(data1)
data2 = listm(data2)
if (!ef) {
est1 = mclapply(data1, DancGLOB_sub, xy = xy1[, 1:2],
pts = pts, est = est, fr = fr1, nmin = nmin,
...)
est2 = mclapply(data2, DancGLOB_sub, xy = xy2[, 1:2],
pts = pts, est = est, fr = fr2, nmin = nmin,
...)
}
if (ef) {
est1 = mclapply(data1, DancGLOB_sub, xy = xy1[, 1:2],
pts = pts, est = hd, fr = fr1, nmin = nmin, q = q,
...)
est2 = mclapply(data2, DancGLOB_sub, xy = xy2[, 1:2],
pts = pts, est = hd, fr = fr2, nmin = nmin, q = q,
...)
}
est1 = t(matl(est1))
est2 = t(matl(est2))
}
pv = NULL
if (J == 1) {
est1 = t(as.matrix(est1))
est2 = t(as.matrix(est2))
}
for (j in 1:J) {
pv[j] = mean(est1[, j] < est2[, j], na.rm = TRUE) + 0.5 *
mean(est1[, j] == est2[, j], na.rm = TRUE)
pv[j] = 2 * min(c(pv[j], 1 - pv[j]))
}
pvadj = rep(NA, length(pts))
if (padj)
pvadj = p.adjust(pv, method = method)
pvm = cbind(pts, pv, pvadj)
dimnames(pvm) = list(NULL, c("X", "p.values", "p.adjusted"))
list(output = pvm, n = c(n1, n2), p.crit = p.crit)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.