# DGB
## Proportions from Paired Samples
ci.prop.ps <- function(alpha, f12, f21, n) {
# Computes adjusted Wald confidence interval for difference of
# population proportions in 2-level within-subjects design
# Arguments:
# alpha: alpha level for 1-alpha confidence
# f12: number of participants who have attribute
# in condition 1 but not condition 2
# f21: number of participants who have attribute
# in condition 2 but not in condition 1
# n: sample size
# Values:
# lower limit, upper limit
z <- qnorm(1 - alpha/2)
p12 <- (f12 + 1)/(n + 2)
p21 <- (f21 + 1)/(n + 2)
se <- sqrt(((p12 + p21) - (p12 - p21)^2)/(n + 2))
LL <- p12 - p21 - z*se
UL <- p12 - p21 + z*se
CI <- c(LL, UL)
return(CI)
}
size.ci.prop.ps <- function(alpha, p1, p2, phi, w) {
# Computes sample size required to estimate a difference of proportions
# in 2-level within-subjects 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
# phi: planning value of phi coefficient
# w: desired confidence interval width
# Values:
# required sample size
z <- qnorm(1 - alpha/2)
cov <- phi*sqrt(p1*p2*(1 - p1)*(1 - p2))
n <- ceiling(4*(p1*(1 - p1) + p2*(1 - p2) - 2*cov)*(z/w)^2)
return(n)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.