# DGB
## Ratio of Proportions from Two (Independent) Samples
ci.ratio.prop.is <- function(alpha, f1, f2, n1, n2) {
# Computes adjusted Wald confidence interval for ratio of
# population proportions in 2-group design
# Arguments:
# alpha: alpha level for 1-alpha confidence
# f1: number of participants in group 1 with attribute
# f2: number of participants in group 2 with attribute
# n1: sample size of group 1
# n2: sample size of group 2
# Values:
# proportions, lower limit, upper limit
z <- qnorm(1 - alpha/2)
mle1 <- f1/n1
mle2 <- f2/n2
p1 <- (f1 + 1/4)/(n1 + 7/4)
p2 <- (f2 + 1/4)/(n2 + 7/4)
v1 <- 1/(f1 + 1/4 + (f1 + 1/4)^2/(n1 - f1 + 3/2))
v2 <- 1/(f2 + 1/4 + (f2 + 1/4)^2/(n2 - f2 + 3/2))
se <- sqrt(v1 + v2)
LL <- exp(log(p1/p2) - z*se)
UL <- exp(log(p1/p2) + z*se)
out <- t(c(mle1, mle2, LL, UL))
colnames(out) <- c("prop1", "prop2", "LL", "UL")
return(out)
}
size.ci.ratio.prop.is <- function(alpha, p1, p2, r) {
# Computes sample size per group required to estimate a ratio
# of proportions in 2-group design with desired precision
# Arguments:
# alpha: alpha level for 1-alpha confidence
# p1: planning value of proportion for group 1
# p2: planning value of proportion for group 2
# r: desired upper to lower interval endpoint ratio
# Values:
# required sample size
z <- qnorm(1 - alpha/2)
n <- ceiling(4*((1 - p1)/p1 + (1 - p2)/p2)*(z/log(r))^2)
return(n)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.