# DGB
## Ratio of Means from Two (Independent) Samples
ci.ratio.mean.is.data <- function(alpha, y1, y2){
# Compute confidence interval for a ratio of population means
# of ratio-scale measurements in a 2-group design. Equality of
# variances is not assumed.
# Arguments:
# alpha: alpha level for 1-alpha confidence
# y1 vector of scores for group 1
# y2: vector of scores for group 2
# Values:
# means, mean ratio, lower limit, upper limit
n1 <- length(y1)
n2 <- length(y2)
m1 <- mean(y1)
m2 <- mean(y2)
v1 <- var(y1)
v2 <- var(y2)
var <- v1/(n2*m1^2) + v2/(n2*m2^2)
df <- var^2/(v1^2/(m1^4*(n1^3 - n1^2)) + v2^2/(m2^4*(n2^3 - n2^2)))
tcrit <- qt(1 - alpha/2, df)
est <- log(m1/m2)
se <- sqrt(var)
ll <- exp(est - tcrit*se)
ul <- exp(est + tcrit*se)
out <- t(c(m1, m2, exp(est), ll, ul))
colnames(out) <- c("Mean1", "Mean2", "Mean1/Mean2", "LL", "UL")
return(out)
}
size.ci.ratio.mean.is <- function(alpha, var, m1, m2, r) {
# Computes sample size required to estimate a ratio of
# population means with desired precision in a 2-group design
# Arguments:
# alpha: alpha level for 1-alpha confidence
# var: planning value of average within-group DV variance
# m1: planning value of mean for group 1
# m2: planning value of mean for group 2
# r: desired upper to lower confidence interval endpoint ratio
# Values:
# required sample size per group
z <- qnorm(1 - alpha/2)
n <- ceiling(8*var*(1/m1^2 + 1/m2^2)*(z/log(r))^2 + z^2/4)
return(n)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.