# DGB
## Ratio of Means from Paired Samples
ci.ratio.mean.ps.data <- function(alpha, y1, y2){
# Compute confidence interval for a ratio of population
# means of ratio-scale measurements in a paired-samples
# design. Equality of variances is not assumed.
# Arguments:
# alpha: alpha level for 1-alpha confidence
# y1: vector of scores for condition 1
# y2: vector of scores for condition 2
# Values:
# means, mean ratio, lower limit, upper limit
n <- length(y1)
m1 <- mean(y1)
m2 <- mean(y2)
v1 <- var(y1)
v2 <- var(y2)
cor <- cor(y1,y2)
var <- (v1/m1^2 + v2/m2^2 - 2*cor*sqrt(v1*v2)/(m1*m2))/n
df <- n - 1
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.ps <- function(alpha, var, m1, m2, cor, r) {
# Computes sample size required to estimate a ratio of population
# means with desired precision in a paired-samples design
# Arguments:
# alpha: alpha level for 1-alpha confidence
# var: planning value of measurement variance
# m1: planning value of mean for measurement 1
# m2: planning value of mean for measurement 2
# cor: planning value for measurement correlation
# r: desired upper to lower confidence interval endpoint ratio
# Values:
# required sample size
z <- qnorm(1 - alpha/2)
n <- ceiling(8*var*(1/m1^2 + 1/m2^2 - 2*cor/(m1*m2))*(z/log(r))^2 + z^2/2)
return(n)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.