ancmg:

Usage Arguments Examples

Usage

1
ancmg(x, y, pool = TRUE, jcen = 1, fr = 1, depfun = fdepth, nmin = 8, op = 3, tr = 0.2, pts = NULL, SEED = TRUE, pr = TRUE, cop = 3, con = 0, nboot = NA, alpha = 0.05, bhop = FALSE)

Arguments

x
y
pool
jcen
fr
depfun
nmin
op
tr
pts
SEED
pr
cop
con
nboot
alpha
bhop

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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
##---- 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, pool = TRUE, jcen = 1, fr = 1, depfun = fdepth, 
    nmin = 8, op = 3, tr = 0.2, pts = NULL, SEED = TRUE, pr = TRUE, 
    cop = 3, con = 0, nboot = NA, alpha = 0.05, bhop = FALSE) 
{
    library(MASS)
    output <- NULL
    if (SEED) 
        set.seed(2)
    if (pr) {
        if (op == 1) 
            print("Trimmed means are to be compared. For medians, use op=2")
        if (op == 2) 
            print("Medians are to be compared. For trimmed means, use op=1")
        if (op == 3) 
            print("trimmed means are compared. For medians, use op=4")
        if (op == 4) 
            print("medians are compared. For trimmed means, use op=3")
    }
    nval <- NA
    if (is.matrix(y)) 
        J <- ncol(y)
    if (is.list(y)) 
        J <- length(y)
    if (is.list(x)) 
        pval <- ncol(x[[1]])
    if (J == 1) 
        stop("Only have one group stored in y")
    if (pval == 1) 
        stop("For one covariate only, using ancgm1")
    if (is.matrix(x)) {
        if (ncol(x)%%J != 0) 
            stop("Number of columns of x should be a multiple of ncol(y)")
    }
    if (is.matrix(x)) {
        pval <- ncol(x)/J
        if (pval == 1) 
            stop("For one covariate only, using ancgm1")
        temp <- seq(1, ncol(x), pval)
        js <- temp[jcen]
        jcenp <- js + pval - 1
        if (jcenp > ncol(x)) 
            stop("jcen has an invalid value")
        xcen <- x[, js:jcenp]
    }
    if (is.list(x)) 
        xcen <- x[[jcen]]
    if (pool) {
        if (is.matrix(x)) 
            xval <- stackit(x, pval)
        if (is.list(x)) 
            xval <- stacklist(x)
        mval <- cov.mve(xval)
        if (is.null(pts)) 
            pts <- ancdes(xval, depfun = depfun, cop = cop)
    }
    if (!pool) {
        if (is.null(pts)) 
            pts <- ancdes(xcen, depfun = depfun, cop = cop)
        mval <- cov.mve(xcen)
    }
    npts = 1
    if (is.matrix(pts)) 
        npts = nrow(pts)
    nval <- matrix(NA, ncol = J, nrow = npts)
    icl <- 0 - pval + 1
    icu <- 0
    for (j in 1:J) {
        icl <- icl + pval
        icu <- icu + pval
        for (i in 1:nrow(pts)) {
            if (is.matrix(x) && is.matrix(y)) {
                nval[i, j] <- length(y[near3d(x[, icl:icu], pts[i, 
                  ], fr, mval), j])
            }
            if (is.matrix(x) && is.list(y)) {
                tempy <- y[[j]]
                nval[i, j] <- length(tempy[near3d(x[, icl:icu], 
                  pts[i, ], fr, mval)])
            }
            if (is.list(x) && is.matrix(y)) {
                xm <- as.matrix(x[[j]])
                nval[i, j] <- length(y[near3d(xm, pts[i, ], fr, 
                  mval), j])
            }
            if (is.list(x) && is.list(y)) {
                tempy <- y[[j]]
                xm <- as.matrix(x[[j]])
                nval[i, j] <- length(tempy[near3d(xm, pts[i, 
                  ], fr, mval)])
            }
        }
    }
    flag <- rep(T, nrow(pts))
    for (i in 1:npts) {
        if (min(nval[i, ]) < nmin) 
            flag[i] <- F
    }
    nflag <- F
    if (sum(flag) == 0) {
        print("Warning: No design points found with large enough sample size")
        nflag <- T
    }
    flag = as.logical(flag)
    if (!nflag) {
        pts <- pts[flag, ]
        nval <- nval[flag, ]
        if (!is.matrix(pts)) 
            pts <- t(as.matrix(pts))
        output <- matrix(NA, nrow = nrow(pts), ncol = 3)
        dimnames(output) <- list(NULL, c("point", "test.stat", 
            "p-value"))
        if (op == 3 || op == 4) 
            output <- list()
    }
    for (i in 1:nrow(pts)) {
        if (op == 1 || op == 2) 
            output[i, 1] <- i
        icl <- 0 - pval + 1
        icu <- 0
        yval <- list()
        for (j in 1:J) {
            icl <- icl + pval
            icu <- icu + pval
            if (is.matrix(x) && is.matrix(y)) {
                yval[[j]] <- y[near3d(x[, icl:icu], pts[i, ], 
                  fr, mval), j]
            }
            if (is.matrix(x) && is.list(y)) {
                tempy <- y[[j]]
                yval[[j]] <- tempy[near3d(x[, icl:icu], pts[i, 
                  ], fr, mval)]
            }
            if (is.list(x) && is.matrix(y)) {
                yval[[j]] <- y[near3d(x[[j]], pts[i, ], fr, mval), 
                  j]
            }
            if (is.list(x) && is.list(y)) {
                tempy <- y[[j]]
                yval[[j]] <- tempy[near3d(x[[j]], pts[i, ], fr, 
                  mval)]
            }
        }
        if (op == 1) 
            temp <- t1way(yval, tr = tr)
        if (op == 2) {
            print("WARNING: NOT RECOMMENDED FOR DISCRETE DATA WITH TIES")
            print("RECOMMENDATION: Set the argument op=4")
            temp <- med1way(yval, SEED = SEED, pr = FALSE)
        }
        if (op == 1 || op == 2) {
            conout = NULL
            output[i, 3] <- temp$p.value
            output[i, 2] <- temp$TEST
        }
        if (op == 3) {
            output[[i]] = linconpb(yval, alpha = alpha, SEED = SEED, 
                con = con, bhop = bhop, tr = tr, nboot = nboot)
        }
        if (op == 4) {
            output[[i]] <- medpb(yval, alpha = alpha, SEED = SEED, 
                con = con, bhop = bhop, nboot = nboot)
        }
    }
    if (nflag) 
        output <- NULL
    if (op == 1 || op == 2) 
        tempout = output
    if (op == 3 || op == 4) {
        tempout = list()
        conout = list()
        for (j in 1:length(output)) tempout[[j]] = output[[j]]$output
        for (j in 1:length(output)) conout[[j]] = output[[j]]$con
    }
    list(points.chosen = pts, sample.sizes = nval, point = tempout, 
        contrast.coef = conout[[1]])
  }

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