# DGB
## Standardized Linear Contrast of Means (Within Subjects)
ci.lc.stdmean.ws <- function(alpha, m, sd, cor, n, h) {
# Computes confidence interval for a population standardized linear
# contrast of means in a within-subjects design (assumes equal
# correlations)
# Arguments:
# alpha: alpha level for 1-alpha confidence
# m: vector of sample means
# sd: vector of sample standard deviations
# cor: average of sample correlations
# n: sample size
# h: vector of contrast coefficients
# Values:
# estimate, SE, lower limit, upper limit
z <- qnorm(1 - alpha/2)
a <- length(m)
df <- n - 1
s <- sqrt(sum(sd^2)/a)
est <- (t(h)%*%m)/s
se1 <- sqrt(est^2*(1 + (a - 1)*cor^2)/(2*a*df) + (1 - cor)*t(h)%*%h/n)
v1 <- est^2/(2*a^2*s^4*df)
v2 <- sum(sd^4)
v3 <- cor^2*t(sd^2)%*%sd^2
v4 <- sum(h^2*sd^2)
v5 <- cor*t(h*sd)%*%(h*sd)
se2 <- sqrt(v1*(v2 + v3) + (v4 - v5)/(df*s^2))
ll1 <- est - z*se1
ul1 <- est + z*se1
ll2 <- est - z*se2
ul2 <- est + z*se2
out1 <- t(c(est, se1, ll1, ul1))
out2 <- t(c(est, se2, ll2, ul2))
out <- rbind(out1, out2)
colnames(out) <- c("Estimate", "SE", "LL", "UL")
rownames(out) <- c("Equal Var & Cor Assumed:", "Only Equal Cor Assumed:")
return(out)
}
size.ci.lc.stdmean.ws <- function(alpha, d, cor, w, h) {
# Computes sample size required to estimate a standardized linear contrast of
# population means with desired precision in a within-subjects design
# Arguments:
# alpha: alpha level for 1-alpha confidence
# d: planning value of standardized linear contrast
# cor: planning value of smallest correlation
# w: desired confidence interval width
# h: vector of contrast coefficients
# Values:
# required sample size
z <- qnorm(1 - alpha/2)
a <- length(h)
n <- ceiling(4*(d^2*(1 + (a - 1)*cor^2)/(2*a) + (1 - cor)*(t(h)%*%h))*(z/w)^2)
return(n)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.