1 |
x |
|
y |
|
tr |
|
alpha |
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 | ##---- 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 = NULL, tr = 0.2, alpha = 0.05)
{
if (is.null(y)) {
if (!is.matrix(x))
stop("y is null and x is not a matrix")
y = x[, 2]
x = x[, 1]
}
if (length(x) != length(y))
stop("The number of observations must be equal")
m <- cbind(x, y)
flag = (apply(is.na(m), 1, sum) == 2)
m = m[!flag, ]
x <- m[, 1]
y <- m[, 2]
flagx = is.na(y)
flagy = is.na(x)
m <- elimna(m)
n = nrow(m)
n1 = sum(flagx)
n2 = sum(flagy)
h = n - 2 * floor(tr * n)
h1 = n1 - 2 * floor(tr * n1)
h2 = n2 - 2 * floor(tr * n2)
xbarn = mean(x, tr = tr, na.rm = TRUE)
xbarn1 = 0
if (h1 > 0)
xbarn1 = mean(x[flagx], tr = tr)
ybarn = mean(y[!flagy], tr = tr, na.rm = TRUE)
ybarn1 = 0
if (h2 > 0)
ybarn1 = mean(y[flagy], tr = tr)
lam1 = h/(h + h1)
lam2 = h/(h + h2)
est = lam1 * xbarn - lam2 * ybarn + (1 - lam1) * xbarn1 -
(1 - lam2) * ybarn1
sex = trimse(elimna(x), tr = tr)
sey = trimse(elimna(y), tr = tr)
q1 <- (n - 1) * winvar(m[, 1], tr)
q2 <- (n - 1) * winvar(m[, 2], tr)
q3 <- (n - 1) * wincor(m[, 1], m[, 2], tr)$cov
sen = sqrt((lam1^2 * q1 + lam2^2 * q2 - 2 * lam1 * lam2 *
q3)/(h * (h - 1)))
SE = sqrt(sen^2 + (1 - lam1)^2 * sex^2 + (1 - lam2)^2 * sey^2)
test = est/SE
list(estimate = est, test = test, se = SE)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.