medind:

Usage Arguments Examples

Usage

1
medind(x, y, qval = 0.5, nboot = 1000, com.pval = FALSE, SEED = TRUE, alpha = 0.05, pr = TRUE, xout = FALSE, outfun = out, ...)

Arguments

x
y
qval
nboot
com.pval
SEED
alpha
pr
xout
outfun
...

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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
##---- 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, qval = 0.5, nboot = 1000, com.pval = FALSE, SEED = TRUE, 
    alpha = 0.05, pr = TRUE, xout = FALSE, outfun = out, ...) 
{
    if (pr) {
        if (!com.pval) 
            print("To get a p-value, set com.pval=T")
        print("Reject if the test statistic exceeds the critical value")
        if (length(y) > 400) 
            print("If n>400, current version requires com.pval=TRUE, resulting in high execution time")
    }
    x <- as.matrix(x)
    p <- ncol(x)
    pp1 <- p + 1
    p.val <- NULL
    crit.val <- NULL
    yx <- elimna(cbind(y, x))
    y <- yx[, 1]
    x <- yx[, 2:pp1]
    x <- as.matrix(x)
    if (xout) {
        flag <- outfun(x, ...)$keep
        x <- x[flag, ]
        y <- y[flag]
    }
    n <- length(y)
    if (n > 400) 
        com.pval = T
    if (qval == 0.5) {
        resmat1 = matrix(c(0.033938458, 0.044080032, 0.050923441, 
            0.064172557, 0.0153224731, 0.021007108, 0.027687963, 
            0.032785044, 0.0106482053, 0.014777728, 0.018249546, 
            0.023638611, 0.0066190573, 0.009078091, 0.011690825, 
            0.014543009, 0.0031558563, 0.004374515, 0.005519069, 
            0.007212951, 0.0015448987, 0.002231473, 0.002748314, 
            0.003725916, 0.0007724197, 0.001021767, 0.001370776, 
            0.001818037), ncol = 4, nrow = 7, byrow = T)
        resmat2 = matrix(c(0.052847794, 0.061918744, 0.071346969, 
            0.079163419, 0.021103277, 0.027198076, 0.031926052, 
            0.03508361, 0.013720585, 0.018454145, 0.022177381, 
            0.026051716, 0.008389969, 0.010590374, 0.012169233, 
            0.015346065, 0.004261627, 0.00551406, 0.007132021, 
            0.008416836, 0.001894753, 0.002416311, 0.00308523, 
            0.003924706, 0.001045346, 0.001347837, 0.001579373, 
            0.001864344), ncol = 4, nrow = 7, byrow = T)
        resmat3 = matrix(c(0.071555715, 0.082937665, 0.089554679, 
            0.097538044, 0.031060795, 0.035798539, 0.043862556, 
            0.053712151, 0.019503635, 0.023776479, 0.027180121, 
            0.030991367, 0.011030001, 0.013419347, 0.015557409, 
            0.017979524, 0.005634478, 0.006804788, 0.007878358, 
            0.008807657, 0.002552182, 0.003603778, 0.004275965, 
            0.005021989, 0.001251044, 0.001531919, 0.001800608, 
            0.00203787), ncol = 4, nrow = 7, byrow = T)
        resmat4 = matrix(c(0.093267532, 0.101584002, 0.108733965, 
            0.118340448, 0.038677863, 0.045519806, 0.051402903, 
            0.060097046, 0.024205231, 0.029360145, 0.034267265, 
            0.039381482, 0.013739157, 0.015856343, 0.018065898, 
            0.019956084, 0.006467562, 0.00778103, 0.009037972, 
            0.010127143, 0.003197162, 0.003933525, 0.004656625, 
            0.005929469, 0.00165269, 0.00192606, 0.002363874, 
            0.002657071), ncol = 4, nrow = 7, byrow = T)
        resmat5 = matrix(c(0.117216934, 0.124714114, 0.129458602, 
            0.136456163, 0.04883863, 0.055608712, 0.060580045, 
            0.067943676, 0.030594644, 0.035003872, 0.040433885, 
            0.047648696, 0.01694024, 0.019527491, 0.022047442, 
            0.025313443, 0.008053039, 0.009778574, 0.011490394, 
            0.013383628, 0.003760567, 0.004376294, 0.00509789, 
            0.00586624, 0.001894616, 0.002253522, 0.002612405, 
            0.002938808), ncol = 4, nrow = 7, byrow = T)
        resmat6 = matrix(c(0.136961531, 0.144120225, 0.149003907, 
            0.152667432, 0.055909481, 0.062627211, 0.069978086, 
            0.081189957, 0.034634825, 0.040740587, 0.044161376, 
            0.047722045, 0.020165417, 0.023074738, 0.025881208, 
            0.028479913, 0.009436297, 0.011246968, 0.013220963, 
            0.015100546, 0.004644596, 0.005334418, 0.006040595, 
            0.007237195, 0.00227759, 0.002635712, 0.002997398, 
            0.003669488), ncol = 4, nrow = 7, byrow = T)
        resmat7 = matrix(c(0.156184672, 0.163226643, 0.171754686, 
            0.177142753, 0.070117003, 0.077052773, 0.082728047, 
            0.090410797, 0.041774517, 0.047379662, 0.053101833, 
            0.057674454, 0.023384451, 0.026014421, 0.029609042, 
            0.032619018, 0.010856382, 0.012567043, 0.01374787, 
            0.016257014, 0.005164004, 0.006131755, 0.006868101, 
            0.008351046, 0.002537642, 0.003044154, 0.003623654, 
            0.003974469), ncol = 4, nrow = 7, byrow = T)
        resmat8 = matrix(c(0.178399742, 0.180006714, 0.193799396, 
            0.199585892, 0.078032767, 0.085624186, 0.091511226, 
            0.102491785, 0.045997886, 0.052181615, 0.057362163, 
            0.062630424, 0.025895739, 0.029733034, 0.033764463, 
            0.037873655, 0.012195876, 0.013663248, 0.015487587, 
            0.017717864, 0.005892418, 0.006876488, 0.007893475, 
            0.008520783, 0.002839731, 0.003243909, 0.003738571, 
            0.004124057), ncol = 4, nrow = 7, byrow = T)
        crit5 = array(cbind(resmat1, resmat2, resmat3, resmat4, 
            resmat5, resmat6, resmat7, resmat8), c(7, 4, 8))
        flag = T
        crit.val = NULL
        if (p > 8) 
            flag = F
        if (n < 10 || n >= 400) 
            flag = F
        aval <- c(0.1, 0.05, 0.025, 0.01)
        aokay <- duplicated(c(alpha, aval))
        if (sum(aokay) == 0) 
            flag = F
        if (flag) {
            nalpha = c(0:4)
            asel = c(0, aval)
            ialpha = nalpha[aokay]
            critit = crit5[, ialpha, p]
            nvec <- c(10, 20, 30, 50, 100, 200, 400)
            nval <- duplicated(c(n, nvec))
            nval <- nval[2:8]
            if (sum(nval) > 0) 
                crit.val <- critit[nval]
            loc <- rank(c(n, nvec))
            xx <- c(1/nvec[loc[1] - 1]^1.5, 1/nvec[loc[1]]^1.5)
            yy <- c(critit[loc[1] - 1], critit[loc[1]])
            icoef <- tsp1reg(xx, yy)$coef
            crit.val <- icoef[1] + icoef[2]/n^1.5
        }
    }
    mqval <- min(c(qval, 1 - qval))
    if (mqval == 0.25) {
        resmat1 = matrix(c(0.029933486, 0.0395983678, 0.054087714, 
            0.062961453, 0.011122294, 0.0149893431, 0.018154062, 
            0.022685244, 0.0092072, 0.0113020766, 0.014872309, 
            0.01993073, 0.004824185, 0.0070402246, 0.010356886, 
            0.013176896, 0.002370379, 0.0033146605, 0.004428004, 
            0.005122988, 0.00110646, 0.0016110185, 0.00198445, 
            0.002650256, 0.000516646, 0.0006796144, 0.000868751, 
            0.001202042), ncol = 4, nrow = 7, byrow = T)
        resmat2 = matrix(c(0.0448417783, 0.0602598211, 0.066001091, 
            0.087040667, 0.0173410522, 0.0224713157, 0.027370822, 
            0.033435727, 0.0121205549, 0.0150409465, 0.018938516, 
            0.022643559, 0.0064894201, 0.0084611518, 0.01070032, 
            0.013232, 0.0029734778, 0.004064131, 0.004911086, 
            0.005769038, 0.0015149104, 0.0020584993, 0.002582982, 
            0.003114029, 0.0007984207, 0.0009929547, 0.001182739, 
            0.001398774), ncol = 4, nrow = 7, byrow = T)
        resmat3 = matrix(c(0.063653086, 0.072974943, 0.083840562, 
            0.097222407, 0.0216586978, 0.027436566, 0.031875356, 
            0.036830302, 0.0152898678, 0.018964066, 0.021728817, 
            0.028959751, 0.0083568493, 0.010071525, 0.012712862, 
            0.015254576, 0.0039033578, 0.00476414, 0.005577071, 
            0.006660322, 0.0019139215, 0.002343152, 0.002833612, 
            0.003465269, 0.0009598105, 0.001146689, 0.00135593, 
            0.001547572), ncol = 4, nrow = 7, byrow = T)
        resmat4 = matrix(c(0.085071252, 0.095947936, 0.104197413, 
            0.118449765, 0.029503024, 0.034198704, 0.03954341, 
            0.045043759, 0.019203266, 0.022768842, 0.026886843, 
            0.033481535, 0.011440493, 0.013555017, 0.01613897, 
            0.018297815, 0.004863139, 0.005756305, 0.007385239, 
            0.009114958, 0.002635144, 0.00311116, 0.003769051, 
            0.004215897, 0.001188837, 0.001435179, 0.001727871, 
            0.001956372), ncol = 4, nrow = 7, byrow = T)
        resmat5 = matrix(c(0.102893512, 0.114258558, 0.122545016, 
            0.130222265, 0.036733497, 0.042504996, 0.048663576, 
            0.055456582, 0.024192946, 0.028805967, 0.032924489, 
            0.038209545, 0.012663224, 0.014635216, 0.017275594, 
            0.01973641, 0.006105572, 0.007310803, 0.008960242, 
            0.00974532, 0.003067163, 0.003614637, 0.003997615, 
            0.004812373, 0.001441008, 0.001732819, 0.002078651, 
            0.002307551), ncol = 4, nrow = 7, byrow = T)
        resmat6 = matrix(c(0.117642769, 0.126566104, 0.133106804, 
            0.142280074, 0.04430942, 0.049731991, 0.053912739, 
            0.060512997, 0.028607224, 0.03382602, 0.038616476, 
            0.0435465, 0.01544512, 0.017557181, 0.02004072, 0.022747707, 
            0.007334749, 0.008406468, 0.009392098, 0.010919651, 
            0.0033522, 0.003814582, 0.004380562, 0.005252154, 
            0.001703698, 0.002001713, 0.002338651, 0.002772864), 
            ncol = 4, nrow = 7, byrow = T)
        resmat7 = matrix(c(0.106573121, 0.11305895, 0.117388191, 
            0.121286795, 0.052170054, 0.058363322, 0.064733684, 
            0.069749344, 0.030696897, 0.035506926, 0.039265698, 
            0.044437674, 0.016737307, 0.019605734, 0.02125361, 
            0.022922988, 0.007767232, 0.009231789, 0.010340874, 
            0.01147111, 0.003998261, 0.004590177, 0.005506926, 
            0.006217415, 0.001903372, 0.002174748, 0.002519055, 
            0.002858655), ncol = 4, nrow = 7, byrow = T)
        resmat8 = matrix(c(0.119571179, 0.126977461, 0.130120853, 
            0.133258294, 0.059499563, 0.067185338, 0.071283297, 
            0.079430577, 0.034310968, 0.03982713, 0.04445169, 
            0.048512464, 0.01859953, 0.021093909, 0.023273085, 
            0.027471116, 0.009135712, 0.010901687, 0.012288682, 
            0.013729545, 0.004382249, 0.00519181, 0.005598429, 
            0.006484433, 0.002196973, 0.002525918, 0.00281855, 
            0.003242426), ncol = 4, nrow = 7, byrow = T)
        crit5 = array(cbind(resmat1, resmat2, resmat3, resmat4, 
            resmat5, resmat6, resmat7, resmat8), c(7, 4, 8))
        flag = T
        crit.val = NULL
        if (p > 8) 
            flag = F
        if (n < 10 || n >= 400) 
            flag = F
        aval <- c(0.1, 0.05, 0.025, 0.01)
        aokay <- duplicated(c(alpha, aval))
        if (sum(aokay) == 0) 
            flag = F
        if (flag) {
            nalpha = c(0:4)
            asel = c(0, aval)
            ialpha = nalpha[aokay]
            critit = crit5[, ialpha, p]
            nvec <- c(10, 20, 30, 50, 100, 200, 400)
            nval <- duplicated(c(n, nvec))
            nval <- nval[2:8]
            if (sum(nval) > 0) 
                crit.val <- critit[nval, p]
            loc <- rank(c(n, nvec))
            xx <- c(1/nvec[loc[1] - 1]^1.5, 1/nvec[loc[1]]^1.5)
            yy <- c(critit[loc[1] - 1], critit[loc[1]])
            icoef <- tsp1reg(xx, yy)$coef
            crit.val <- icoef[1] + icoef[2]/n^1.5
        }
    }
    if (is.null(crit.val)) 
        com.pval = T
    gdot <- cbind(rep(1, n), x)
    gdot <- ortho(gdot)
    x <- gdot[, 2:pp1]
    x <- as.matrix(x)
    coef <- NULL
    if (qval == 0.5) 
        coef <- median(y)
    if (qval == 0.25) 
        coef <- idealf(y)$ql
    if (qval == 0.75) 
        coef <- idealf(y)$qu
    if (is.null(coef)) 
        coef <- qest(y, q = qval)
    res <- y - coef
    psi <- NA
    psi <- ifelse(res > 0, qval, qval - 1)
    rnmat <- matrix(0, nrow = n, ncol = pp1)
    ran.mat <- apply(x, 2, rank)
    flagvec <- apply(ran.mat, 1, max)
    for (j in 1:n) {
        flag <- ifelse(flagvec <= flagvec[j], T, F)
        flag <- as.numeric(flag)
        rnmat[j, ] <- apply(flag * psi * gdot, 2, sum)
    }
    rnmat <- rnmat/sqrt(n)
    temp <- matrix(0, pp1, pp1)
    for (i in 1:n) temp <- temp + rnmat[i, ] %*% t(rnmat[i, ])
    temp <- temp/n
    test <- max(eigen(temp)$values)
    if (com.pval) {
        if (SEED) 
            set.seed(2)
        p.val <- 0
        rem <- 0
        for (i in 1:nboot) {
            yboot <- rnorm(n)
            if (p == 1) 
                xboot <- rnorm(n)
            if (p > 1) 
                xboot <- rmul(n, p = p)
            temp3 <- medindsub(x, yboot, qval = qval)
            if (test >= temp3) 
                p.val <- p.val + 1
            rem[i] <- temp3
        }
        ic10 <- round(0.9 * nboot)
        ic05 <- round(0.95 * nboot)
        ic025 <- round(0.975 * nboot)
        ic001 <- round(0.99 * nboot)
        rem <- sort(rem)
        p.val <- 1 - p.val/nboot
        print("The .1, .05, .025 and .001 critical values are:")
        print(c(rem[ic10], rem[ic05], rem[ic025], rem[ic001]))
        crit.val <- rem[ic05]
    }
    names(crit.val) = ""
    Decision = "Fail To Reject"
    if (test >= crit.val) 
        Decision = "Reject"
    list(test.stat = test, crit.value = crit.val, p.value = p.val, 
        Decision = Decision)
  }

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