BayesFactor: R package

data

X1 <- c(3.3, 1, 2, 1.7, 3.7, 5.7, 3.7, 0.7, 4.7, 3.7, 7, 1.7, 6.3, 3.7, 3.3, 2.3, 4.7, 6.7)
N1 <- length(X1)
X2 <- c(6, 5.7, 6, 3.7, 5, 9, 6, 9, 2.3, 4.7, 5.7, 7.7, 6.7, 4.7, 5.7, 3.3, 6, 5, 6, 5, 5.3)
N2 <- length(X1)
data <- data.frame(C=factor(c(rep(1, N1), rep(2, N2))), X=c(X1, X2))

library(psych)
d <- describeBy(data$X, group=data$C)
print(d, digits=3)
v1 <- d$"1"$sd^2
v2 <- d$"2"$sd^2
dif <- (d$"2"$mean - d$"1"$mean)
cat("\n")
cat("difference:", dif, "\n")

Two Sample t-test

tt <- t.test(x=X1, y=X2, paired=F)
print(tt)

Bayes factor

library(BayesFactor)
cat("** BayesFactor **\n")

ttest.tstat()

cat("\n")
cat("Call: ttest.tstat\n \n")
ts <- ttest.tstat(t=tt$statistic, n1=N1, n2=N2, rscale="medium")
bf10 <- exp(ts$bf)
cat("bf10:", bf10, "\n")
cat("Posterior prob:", bf10/(bf10 + 1), "\n")

ttestBF()

cat("\n")
cat(""Call: ttestB\n \n")
ttBF <- ttestBF(X1, X2, rscale="medium")
print(ttBF)
BF10 <- extractBF(ttBF)$bf
cat("Posterior prob:", BF10/(BF10 + 1), "\n")


Output

Descriptive statistics by group

group: 1
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 18 3.661 1.911 3.7 3.638 2.298 0.7 7 6.3 0.217 -1.145 0.45
group: 2
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 21 5.643 1.614 5.7 5.582 1.038 2.3 9 6.7 0.291 0.119 0.352

difference: 1.981746

Two Sample t-test

data: X1 and X2
t = -3.5119, df = 37, p-value = 0.001191
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval: -3.1251199 -0.8383721
sample estimates:
mean of x mean of y
3.661111 5.642857

BayesFactor

Call: ttest.tstat
BF10: 26.98568
Posterior prob: 0.9642674

Call: ttestBF
Bayes factor analysis
[1] Alt., r=0.707 : 26.98568 ±0%
Against denominator:
Null, mu1-mu2 = 0
Bayes factor type: BFindepSample, JZS
Posterior prob: 0.9642674


Posterior probability distributions
Bridge sampling