# R – Functions for a manuscript-ready output for t-tests, BayesFactors and ezANOVAs

### 1 Response

1. Nice, thanks! I copy pasted portions of Lakens’ Perfect t-test (https://github.com/Lakens/Perfect-t-test) to accomplish something similar, currently just for paired-samples t-test, and crucially, without the output formatting, but maybe could be useful:

pairedTtestStats <- function(x, y){
diff<-x-y #difference scores
r<-cor(x, y) #correlation between dependent measures
m_diff<-mean(diff) #mean of difference scores
s_diff<-sd(diff) #standard deviation of difference scores
sd1<-sd(x) #standard deviation of group 1
sd2<-sd(y) #standard deviation of group 2
N <- length(x) #number of pairs

ttestresult<-t.test(x, y, paired = TRUE, var.equal = TRUE)
tvalue<-ttestresult\$statistic #store t-value from dependent t-test
pvalue<-ttestresult\$p.value #store p-value from dependent t-test
CI_diff<-ttestresult\$conf.int #store confidence interval of mean difference
s_av <- sqrt((sd1^2+sd2^2)/2) #calculate average standard deviation for effect size calculation

#Effect sizes and 95% CI
#Cohen's d_av, using s_av as standardizer

require(MBESS) # to calculate non-central t limits

d_av <- m_diff/s_av
d_unb <- (1-(3/(4*(N-1)-1)))*d_av #note this is approximation of correction for Hedges'g – ESCI uses accurate correction, so should we.
nct_limits <- conf.limits.nct(t.value = tvalue, df=N-1)
ci_l_d_av <- nct_limits\$Lower.Limit*s_diff/(s_av*sqrt(N))
ci_u_d_av <- nct_limits\$Upper.Limit*s_diff/(s_av*sqrt(N))

#Cohen's d_z, using s_diff as standardizer
d_z <- tvalue/sqrt(N)