1 | disc2comSK(x, y, alpha = 0.05, nboot = 500, SEED = TRUE)
|
x |
|
y |
|
alpha |
|
nboot |
|
SEED |
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 | ##---- 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, alpha = 0.05, nboot = 500, SEED = TRUE)
{
library(mc2d)
x = elimna(x)
y = elimna(y)
if (SEED)
set.seed(2)
x = elimna(x)
y = elimna(y)
vals = sort(unique(c(x, y)))
n1 = length(x)
n2 = length(y)
K = length(vals)
C1 = NULL
C2 = NULL
HT = NULL
for (i in 1:K) {
C1[i] = sum(x == vals[i])
C2[i] = sum(y == vals[i])
HT[i] = (C1[i] + C2[i])/(n1 + n2)
}
p1hat = C1/n1
p2hat = C2/n2
test = sum((p1hat - p2hat)^2)
tv = NULL
TB = NA
VP = NA
for (ib in 1:nboot) {
xx = rmultinomial(n1, 1, HT)
yy = rmultinomial(n2, 1, HT)
B1 = NA
B2 = NA
BP = NA
for (i in 1:K) {
B1[i] = sum(xx[, i])
B2[i] = sum(yy[, i])
}
B1hat = B1/n1
B2hat = B2/n2
TB[ib] = sum((B1hat - B2hat)^2)
}
pv = 1 - mean(test > TB) - 0.5 * mean(test == TB)
list(test = test, p.value = pv)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.