# DGB
## Correlations
ci.corr.os <- function(alpha, corr, n) {
# Computes a confidence interval for a Pearson correlation
# Arguments:
# alpha: alpha level for 1-alpha confidence
# corr: sample value of correlation
# n: sample size
# Values:
# lower limit, upper limit
z <- qnorm(1 - alpha/2)
se <- sqrt(1/((n - 3)))
zr <- log((1 + corr)/(1 - corr))/2
LL0 <- zr - z*se
UL0 <- zr + z*se
LL <- (exp(2*LL0) - 1)/(exp(2*LL0) + 1)
UL <- (exp(2*UL0) - 1)/(exp(2*UL0) + 1)
CI <- c(LL, UL)
return(CI)
}
size.ci.corr.os <- function(alpha, corr, w) {
# Computes sample size required to estimate a correlation with desired precision
# Arguments:
# alpha: alpha level for 1-alpha confidence
# corr: planning value of correlation
# w: desired confidence interval width
# Values:
# required sample size
z <- qnorm(1 - alpha/2)
n1 <- ceiling(4*(1 - corr^2)^2*(z/w)^2 + 3)
zr <- log((1 + corr)/(1 - corr))/2
se <- sqrt(1/(n1 - 3))
LL0 <- zr - z*se
UL0 <- zr + z*se
LL <- (exp(2*LL0) - 1)/(exp(2*LL0) + 1)
UL <- (exp(2*UL0) - 1)/(exp(2*UL0) + 1)
n <- ceiling((n1 - 3)*((UL - LL)/w)^2 + 3)
return(n)
}
size.test.corr.os <- function(alpha, power, s, cor, b) {
# Computes sample size required to test a (partial) correlation with desired power
# Arguments:
# alpha: alpha value for test
# power: desired power of test
# s: number of control variables
# cor: planning value of (partial) correlation
# b: hypothesized value of correlation
# Values:
# required sample size
za <- qnorm(1 - alpha/2)
zb <- qnorm(power)
zr <- log((1 + cor)/(1 - cor))/2
zo <- log((1 + b)/(1 - b))/2
es <- zr - zo
n <- ceiling((za + zb)^2/es^2 + s + 3)
return(n)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.