1 |
x |
|
nn |
|
y |
|
n |
|
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 50 | ##---- 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 = sum(y), nn = length(y), y = NULL, n = NA, alpha = 0.05)
{
if (!is.null(y)) {
y = elimna(y)
nn = length(y)
}
if (nn == 1)
stop("Something is wrong: number of observations is only 1")
n <- nn
if (x != n && x != 0) {
z <- qnorm(1 - alpha/2)
A <- ((x + 1)/(n - x))^2
B <- 81 * (x + 1) * (n - x) - 9 * n - 8
C <- (0 - 3) * z * sqrt(9 * (x + 1) * (n - x) * (9 *
n + 5 - z^2) + n + 1)
D <- 81 * (x + 1)^2 - 9 * (x + 1) * (2 + z^2) + 1
E <- 1 + A * ((B + C)/D)^3
upper <- 1/E
A <- (x/(n - x - 1))^2
B <- 81 * x * (n - x - 1) - 9 * n - 8
C <- 3 * z * sqrt(9 * x * (n - x - 1) * (9 * n + 5 -
z^2) + n + 1)
D <- 81 * x^2 - 9 * x * (2 + z^2) + 1
E <- 1 + A * ((B + C)/D)^3
lower <- 1/E
}
if (x == 0) {
lower <- 0
upper <- 1 - alpha^(1/n)
}
if (x == 1) {
upper <- 1 - (alpha/2)^(1/n)
lower <- 1 - (1 - alpha/2)^(1/n)
}
if (x == n - 1) {
lower <- (alpha/2)^(1/n)
upper <- (1 - alpha/2)^(1/n)
}
if (x == n) {
lower <- alpha^(1/n)
upper <- 1
}
phat <- x/n
list(phat = phat, ci = c(lower, upper), n = n)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.