3.6 Bayesian Statistics

Now, let’s repeat some of our previous analyses with Bayesian versions. First we’ll install and load the package which contains the Bayesian statistics functions we’ll use:

# Install and load the BayesFactor package
install.packages('BayesFactor')
library(BayesFactor)

Now that the packages is installed and loaded, we’re good to go! Let’s do a Bayesian version of our earlier t-test asking if pirates who wear a headband are older or younger than those who do not.

# Bayesian t-test comparing the age of pirates with and without headbands
ttestBF(formula = age ~ headband,
        data = pirates)
## Bayes factor analysis
## --------------
## [1] Alt., r=0.707 : 0.12 ±0%
## 
## Against denominator:
##   Null, mu1-mu2 = 0 
## ---
## Bayes factor type: BFindepSample, JZS

It looks like we got a Bayes factor of 0.12 which is strong evidence for the null hypothesis (that the mean age does not differ between pirates with and without headbands)