1 |
r1 |
|
n1 |
|
r2 |
|
n2 |
|
x |
|
y |
|
alpha |
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 (r1 = sum(x), n1 = length(x), r2 = sum(y), n2 = length(y),
x = NA, y = NA, alpha = 0.05)
{
if (length(r1) > 1)
stop("r1 must be a single number, not a vector")
if (length(n1) > 1)
stop("n1 must be a single number, not a vector")
if (length(r2) > 1)
stop("r2 must be a single number, not a vector")
if (!is.na(sum(r1)) || !is.na(sum(n1)) || !is.na(sum(r2)) ||
!is.na(sum(n2))) {
if (r1 < 0 || n1 < 0)
stop("Both r1 and n1 must be greater than 0")
if (r1 > n1)
stop("r1 can't be greater than n1")
if (r2 < 0 || n2 < 0)
stop("Both r2 and n2 must be greater than 0")
if (r2 > n2)
stop("r2 can't be greater than n2")
}
if (!is.na(sum(x))) {
r1 <- sum(x)
n1 <- length(x)
}
if (!is.na(sum(y))) {
r2 <- sum(y)
n2 <- length(y)
}
a <- (r1/n1) + (r2/n2)
b <- (r1/n1) - (r2/n2)
u <- 0.25 * ((1/n1) + (1/n2))
v <- 0.25 * ((1/n1) - (1/n2))
V <- u * ((2 - a) * a - b^2) + 2 * v * (1 - a) * b
crit <- qchisq(1 - alpha/2, 1)
A <- sqrt(crit * (V + crit * u^2 * (2 - a) * a + crit * v^2 *
(1 - a)^2))
B <- (b + crit * v * (1 - a))/(1 + crit * u)
ci <- NA
ci[1] <- B - A/(1 + crit * u)
ci[2] <- B + A/(1 + crit * u)
p1 <- r1/n1
p2 <- r2/n2
list(ci = ci, p1 = p1, p2 = p2)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.