# DGB
## Linear Contrast of Proportions (Between Subjects)
ci.lc.prop.bs <- function(alpha, f, n, c) {
# Computes adjusted Wald confidence interval for a linear contrast
# of population proportions in a between-subjects design
# Arguments:
# alpha: alpha level for 1-alpha confidence
# f: vector of sample frequency counts
# n: vector of sample sizes
# c: vector of contrast coefficients
# Values:
# estimate, standard error, lower limit, upper limit
z <- qnorm(1 - alpha/2)
m <- length(c) - length(which(c==0))
p <- (f + 2/m)/(n + 4/m)
est <- t(c)%*%p
se <- sqrt(t(c)%*%diag(p*(1 - p))%*%solve(diag(n + 4/m))%*%c)
t <- est/se
pval <- 2*(1 - pnorm(abs(t)))
LL <- est - z*se
UL <- est + z*se
CI <- c(LL, UL)
out <- t(c(est, se, LL, UL))
colnames(out) <- c("Estimate", "SE", "LL", "UL")
return(out)
}
size.ci.lc.prop.bs <- function(alpha, p, c, w) {
# Computes sample size per group required to estimate a linear contrast
# of proportions in between-subjects design with desired precision
# Arguments:
# alpha: alpha level for 1-alpha confidence
# p: vector of proportion planning values
# c: vector of contrast coefficients
# w: desired confidence interval width
# Values:
# required sample size
z <- qnorm(1 - alpha/2)
n <- ceiling((4*t(c)%*%diag(p*(1 - p))%*%c)*(z/w)^2)
return(n)
}
size.test.lc.prop.bs <- function(alpha, power, p, c, es) {
# Computes sample size per group required to test a linear contrast
# of proportions in between-subjects design with desired power
# Arguments:
# alpha: alpha level for 1-alpha confidence
# power: desired power of test
# p: vector of proportion planning values
# c: vector of contrast coefficients
# es: expected effect size
# Values:
# required sample size
za <- qnorm(1 - alpha/2)
zb <- qnorm(power)
n <- ceiling((t(c)%*%diag(p*(1 - p))%*%c)*(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.