ols1way:

Usage Arguments Examples

Usage

1
ols1way(x, y, xout = FALSE, outfun = outpro, STAND = TRUE, alpha = 0.05, pr = TRUE, BLO = FALSE, HC3 = FALSE, ...)

Arguments

x
y
xout
outfun
STAND
alpha
pr
BLO
HC3
...

Examples

  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
##---- 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, 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")
    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) {
        temp1 = lapply(x, outfun, plotit = FALSE, STAND = STAND, 
            ...)
        for (j in 1:J) {
            x[[j]] = x[[j]][temp1[[j]]$keep, ]
            y[[j]] = y[[j]][temp1[[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)
    gmean = 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
        ecovinv[[j]] = solve(ecov[[j]])
        gmean = gmean + ecovinv[[j]] %*% est[j, ]
        W = W + ecovinv[[j]]
    }
    estall = solve(W) %*% gmean
    F = 0
    for (k in 1:K) {
        for (m in 1:K) {
            for (j in 1:J) {
                F = F + ecovinv[[j]][k, m] * (est[j, k] - estall[k]) * 
                  (est[j, m] - estall[m])
            }
        }
    }
    pvalad = NULL
    df = K * (J - 1)
    iden = diag(p1)
    Aw = 0
    for (j in 1:J) {
        temp = iden - solve(W) %*% ecovinv[[j]]
        tempsq = temp %*% temp
        Aw = Aw + (sum(diag(tempsq)) + (sum(diag(temp)))^2)/(nv[j] - 
            1)
    }
    Aw = Aw/2
    crit = qchisq(alpha, df)
    crit = crit + (crit/(2 * df)) * (Aw + 3 * Aw * crit/(df + 
        2))
    alval <- c(1:999)/1000
    for (i in 1:999) {
        irem <- i
        crit = qchisq(alval[i], df)
        critad = crit + (crit/(2 * df)) * (Aw + 3 * Aw * crit/(df + 
            2))
        if (F < critad) 
            break
        pvalad = 1 - irem/1000
    }
    pval = 1 - pchisq(F, df)
    crit = qchisq(1 - alpha, df)
    critad = NULL
    critad = crit + (crit/(2 * df)) * (Aw + 3 * Aw * crit/(df + 
        2))
    est = data.frame(est)
    list(n = nv, n.keep = nv.keep, test.stat = F, crit.value = crit, 
        adjusted.crit = critad, p.value = pval, adjusted.p.value = pvalad, 
        est = est)
  }

musto101/wilcox_R documentation built on May 23, 2019, 10:52 a.m.