#Noncentral t confidence interval generic calculator
#Hedges&Olkin (1985) method.
#Edit values between the rows of dotted lines
#..........................................................
#Enter the following control variables
#
Samples <- 1
#
# must be 1 for paired samples or 2 for independent samples, no error checking!
# For two samples, d is calculated as the mean difference divided by the pooled standard deviation.
# For one sample (paired, matched) the standard deviation of the difference scores is used.
#
alpha <- .05
#
# 1 minus confidence coefficient; e.g., for 95% interval alpha = 1 - .95.
#
Meandiff <- -0.6
#
#sample unstandardized mean difference used to form d; positive, negative, or 0
#
SD <- 2
#
# SD for independent samples is the pooled standard deviation of the two groups
# SD for paired, correlated, matched is the standard deviation of the difference scores
#
n <- 9
#
#equal n, sample size per group or number of differences
#.........................................................
#Do not change anything below here
Harmmean <- 2*(n*n)/(n+n)
if (Samples == 1) df <- n - 1
if (Samples == 2) df <- 2*(n - 1)
#Calculating A
if (Samples == 1) {
A <- n # if difference scores
} else A <- Harmmean/2 # if 2 samples
sqrtA <- sqrt(A)
J <- exp(lgamma(df/2)-(log(sqrt(df/2))+(lgamma((df-1)/2))))
d <- Meandiff/SD
varD <- (1/A)*(df/(df-2))*(1+A*d*d)-(d*d)/(J*J)
g <- d*J
varG <- varD*J*J
ncpD <- d * sqrtA #non-centrality parameters
ncpG <- g * sqrtA
lldt <- qt(alpha/2, df, ncpD) #lower limit biased, t-scaling
uldt <- qt(1-alpha/2, df, ncpD) #upper limit biased, t-scaling
lld <- lldt/sqrtA #lower limit biased, d-scaling
uld <- uldt/sqrtA #upper limit biased, d-scaling
llgt <- qt(alpha/2, df, ncpG) #lower limit unbiased, t-scaling
ulgt <- qt(1-alpha/2, df, ncpG) #upper limit unbiased, t-scaling
llg <- llgt/sqrtA #lower limit unbiased, g-scaling
ulg <- ulgt/sqrtA #upper limit unbiased, g-scaling
#Show calculated values
cat("Samples = ",Samples, " Mean difference =",Meandiff," SD =",SD, " n =",n,"\n")
if (Samples == 2) { cat("SD is pooled standard deviation of the two equal groups.\n")
} else { cat("SD is standard deviation of the differences between the paired scores.\n") }
cat("degrees of freedom = ",df, " A =",A," J =",J, "\n")
cat("Effect size\nBiased d", d, " Var(d)", varD,"\nUnbiased g", g, "Var(g)", varG, "\n")
cat (100*(1-alpha),"% noncentral t confidence interval\n")
cat("Standardized Biased scaling: d =",d," Interval [", lld,",", uld, "]","\n")
cat("Standardized Unbiased scaling: g =",g," Interval [", llg,",", ulg, "]\n")