# DGB
## Proportions from Two (Independent) Samples
ci.prop.is <- function(alpha, f1, f2, n1, n2) {
# Computes adjusted Wald confidence interval for difference 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:
# MLEs, SE, lower limit, upper limit
z <- qnorm(1 - alpha/2)
mle1 <- f1/n1
mle2 <- f2/n2
p1 <- (f1 + 1)/(n1 + 2)
p2 <- (f2 + 1)/(n2 + 2)
se <- sqrt(p1*(1 - p1)/(n1 + 2) + p2*(1 - p2)/(n2 + 2))
LL <- p1 - p2 - z*se
UL <- p1 - p2 + z*se
out <- t(c(mle1, mle2, se, LL, UL))
colnames(out) <- c("prop1", "prop2", "SE", "LL", "UL")
return(out)
}
size.ci.prop.is <- function(alpha, p1, p2, w) {
# Computes sample size per group required to estimate a difference
# 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
# w: desired confidence interval width
# Values:
# required sample size
z <- qnorm(1 - alpha/2)
n <- ceiling(4*(p1*(1 - p1) + p2*(1 - p2))*(z/w)^2)
return(n)
}
size.test.prop.is <- function(alpha, power, p1, p2, es) {
# Computes sample size per group required to test equality
# of proportions in 2-group design with desired power
# Arguments:
# alpha: alpha level for 1-alpha confidence
# power: desired power of hypothesis test
# p1: planning value of proportion for group 1
# p2: planning value of proportion for group 2
# es: expected effect size
# Values:
# required sample size
za <- qnorm(1 - alpha/2)
zb <- qnorm(power)
n <- ceiling((p1*(1 - p1) + p2*(1 - p2))*(za + zb)^2/es^2)
return(n)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.