library(BayesFactor)
library(reshape)

#####################
##independent samples###
######################
B = matrix(
c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,
14,22,18,17,15,21,19,18,20,19,20,25,24,23,
21,26,25,24,26,27),
nrow=20,
ncol=2)
indepenT = as.data.frame(B)
colnames(indepenT) = c(“group”, “correct”)
##descriptives
summary(indepenT)
tapply(indepenT$correct, list(indepenT$group), mean)
tapply(indepenT$correct, list(indepenT$group), sd)
tapply(indepenT$correct, list(indepenT$group), length)

###NHST independent t-test
t.test(indepenT$correct ~ indepenT$group,
paired = F, var.equal = T)
#Bayes Factor independent t-test
ttestBF(formula = correct~group, data = indepenT)
######################
####paired samples####
######################
C = matrix(
c(3,5,9,6,7,5,4,5,7,6,8,6,8,7,
3,3,6,8,8,2,1,3,4,2,3,5,5,5),
nrow=14,
ncol=2)
depenT = as.data.frame(C)
colnames(depenT) = c(“pre”, “post”)
summary(depenT)
#NHST dependent t-test
depenT$partno = 1:nrow(depenT)
longdependent = melt(depenT,
id = “partno”,
measured = c(“pre”, “post”))
t.test(longdependent$value~longdependent$variable, paired = T)
#Bayes Factor dependent t-test
ttestBF(x = depenT$pre,
y = depenT$post,
paired = TRUE)

Advertisements