1 |
x1 |
|
x2 |
|
alpha |
|
power |
|
delta |
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 | ##---- 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 (x1, x2 = NULL, alpha = 0.05, power = 0.9, delta)
{
if (is.null(x2[1])) {
stage1 = bdanova1(x1, alpha = alpha, power = power, delta = delta)
return(list(N = stage1$N, d = stage1$d, crit = stage1$crit))
}
if (!is.null(x2[1])) {
if (is.na(delta))
stop("A value for delta was not specified")
if (!is.list(x1)) {
if (!is.matrix(x1))
stop("Data must be stored in a matrix or in list mode")
y <- x1
x1 <- list()
for (j in 1:ncol(y)) x1[[j]] <- y[, j]
}
if (is.na(delta))
stop("A value for delta was not specified")
if (!is.list(x2)) {
if (!is.matrix(x2))
stop("Data must be stored in matrix or in list mode")
y <- x2
x2 <- list()
for (j in 1:ncol(y)) x2[[j]] <- y[, j]
}
if (length(x1) != length(x2))
stop("Length of x1 does not match the length of x2")
TT <- NA
U <- NA
J <- length(x1)
nvec <- NA
nvec2 <- NA
svec <- NA
for (j in 1:length(x1)) {
nvec[j] <- length(x1[[j]])
nvec2[j] <- length(x2[[j]])
svec[j] <- var(x1[[j]])
TT[j] <- sum(x1[[j]])
U[j] <- sum(x2[[j]])
}
temp <- bdanova1(x1, alpha = alpha, power = power, delta = delta)
need <- temp$N - nvec
for (j in 1:length(x1)) if (nvec2[j] < need[j]) {
print(paste("Warning: For Group", j))
print("The first stage analysis based on bdanova1 reports that a larger")
print(" sample is required than what was found in the argument x2")
}
b <- sqrt(nvec * ((nvec + nvec2) * temp$d - svec)/(nvec2 *
svec))
b <- (b + 1)/(nvec + nvec2)
xtil <- TT * (1 - nvec2 * b)/nvec + b * U
ftil <- sum((xtil - mean(xtil))^2)/temp$d
return(list(test.stat = ftil, crit = temp$crit))
}
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.