# DGB
## Standardized Mean Difference from Paired Samples
ci.stdmean.ps <- function(alpha, m1, m2, sd1, sd2, n, cor) {
# Computes confidence interval for a population standardized mean
# difference in a paired-samples design
# Arguments:
# alpha: alpha level for 1-alpha confidence
# mj: sample mean in condition j
# sdj: sample standard deviation in condition j
# n: sample size
# cor: sample correlation
# Values:
# estimate, SE, lower limit, and upper limit for equal variance and
# unequal variance methods plus single condition standardizer
z <- qnorm(1 - alpha/2)
s <- sqrt((sd1^2 + sd2^2)/2)
df <- n - 1
v1 <- sd1^2
v2 <- sd2^2
vd <- v1 + v2 - 2*cor*sd1*sd2
est1 <- (m1 - m2)/s
se1 <- sqrt(est1^2*(v1^2 + v2^2 + 2*cor^2*v1*v2)/(8*df*s^4) + vd/(df*s^2))
ll1 <- est1 - z*se1
ul1 <- est1 + z*se1
se2 <- sqrt(est1^2*(1 + cor^2)/(4*df) + 2*(1 - cor)/n)
ll2 <- est1 - z*se2
ul2 <- est1 + z*se2
est3 <- (m1 - m2)/sd1
se3 <- sqrt(est3^2/(2*df) + vd/(df*v1))
ll3 <- est3 - z*se3
ul3 <- est3 + z*se3
est4 <- (m1 - m2)/sd2
se4 <- sqrt(est4^2/(2*df) + vd/(df*v2))
ll4 <- est4 - z*se4
ul4 <- est4 + z*se4
out1 <- t(c(est1, se1, ll1, ul1))
out2 <- t(c(est1, se2, ll2, ul2))
out3 <- t(c(est3, se3, ll3, ul3))
out4 <- t(c(est4, se4, ll4, ul4))
out <- rbind(out1, out2, out3, out4)
colnames(out) <- c("Estimate", "SE", "LL", "UL")
rownames1 <- c("Equal Variances Not Assumed:", "Equal Variances Assumed:")
rownames2 <- c("Condition 1 Standardizer:", "Condition 2 Standardizer:")
rownames(out) <- c(rownames1, rownames2)
return(out)
}
size.ci.stdmean.ps <- function(alpha, d, cor, w) {
# Computes sample size required to estimate a population standardized
# mean difference with desired precision in a paired-samples design
# Arguments:
# alpha: alpha level for 1-alpha confidence
# d: planning value of standardized mean difference
# cor: planning value of correlation
# w: desired confidence interval width
# Values:
# required sample size
z <- qnorm(1 - alpha/2)
n <- ceiling(4*(d^2*(1 + cor^2)/4 + 2*(1 - cor))*(z/w)^2)
return(n)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.