1 |
x |
|
y |
|
grp |
|
iv |
|
xout |
|
outfun |
|
STAND |
|
alpha |
|
pr |
|
BLO |
|
HC3 |
|
... |
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 | ##---- 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, grp = c(1, 2), iv = 1, xout = FALSE, outfun = outpro,
STAND = TRUE, alpha = 0.05, pr = TRUE, BLO = FALSE, HC3 = FALSE,
...)
{
if (!is.list(x))
stop("Argument x should have list mode")
iv1 = iv + 1
J = length(x)
x = lapply(x, as.matrix)
pchk = lapply(x, ncol)
temp = matl(pchk)
if (var(as.vector(temp)) != 0)
stop("Something is wrong. Number of covariates differs among the groups being compared")
nv = NULL
p = ncol(x[[1]])
p1 = p + 1
for (j in 1:J) {
xy = elimna(cbind(x[[j]], y[[j]]))
x[[j]] = xy[, 1:p]
y[[j]] = xy[, p1]
x[[j]] = as.matrix(x[[j]])
nv = c(nv, nrow(x[[j]]))
}
nv.keep = nv
critrad = NULL
if (xout) {
temp = lapply(x, outfun, plotit = FALSE, STAND = STAND,
...)
for (j in 1:J) {
x[[j]] = x[[j]][temp[[j]]$keep, ]
y[[j]] = y[[j]][temp[[j]]$keep]
}
if (BLO) {
for (j in 1:J) {
temp = reglev(x[[j]], y[[j]], plotit = FALSE)
ad1 = c(temp1[[j]]$out.id, temp$regout)
flag1 = duplicated(ad1)
if (sum(flag1) > 0) {
flag1 = ad1[flag1]
x[[j]] = as.matrix(x[[j]])
x[[j]] = x[[j]][-flag1, ]
y[[j]] = y[[j]][-flag1]
}
}
}
}
x = lapply(x, as.matrix)
K = p1
est = matrix(NA, nrow = J, ncol = p1)
grpnum = NULL
for (j in 1:J) grpnum[j] = paste("Group", j)
vlabs = "Intercept"
for (j in 2:p1) vlabs[j] = paste("Slope", j - 1)
dimnames(est) = list(grpnum, vlabs)
ecov = list()
ecovinv = list()
W = rep(0, p1)
for (j in 1:J) {
est[j, ] = ols(x[[j]], y[[j]], xout = FALSE, plotit = FALSE,
...)$coef
nv.keep[j] = nrow(x[[j]])
ecov[[j]] = olshc4(x[[j]], y[[j]], HC3 = HC3)$cov
}
q1 = ecov[[grp[1]]][iv1, iv1]
q2 = ecov[[grp[2]]][iv1, iv1]
top = est[grp[1]] - est[grp[2]]
F = (est[grp[1], iv1] - est[grp[2], iv1])/sqrt(q1 + q2)
df = (q1 + q2)^2/(q1^2/(nv[grp[1]] - 1) + q2^2/(nv[grp[2]] -
1))
pv = 2 * (1 - pt(abs(F), df))
crit = qt(1 - alpha/2, df)
ci = est[grp[1], iv1] - est[grp[2], iv1] - crit * sqrt(q1 +
q2)
ci[2] = est[grp[1], iv1] - est[grp[2], iv1] + crit * sqrt(q1 +
q2)
list(n = nv, n.keep = nv.keep, test.stat = F, conf.interval = ci,
est = c(est[grp[1], iv1], est[grp[2], iv1]), est.dif = est[grp[1],
iv1] - est[grp[2], iv1], p.value = pv)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.