Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
One-tailed testing with lmBF
## For the singer dataset
library(lattice)
data(singer)
## Get data ready (recode to two factors)
singer$female = factor(with(singer, grepl("S",voice.part) | grepl("A",voice.part)))
singer$high = factor(with(singer, grepl("S",voice.part) | grepl("T",voice.part)))
## We will test the hypothesis that the main effect
## of "high voice" is such that high voiced singers are shorter
## Compute BF10
library(BayesFactor)
bf = lmBF(height ~ female*high, data = singer)
## Convert to scalar
BF10 = as.vector(bf)
## Sample posterior
chains = posterior(bf, iterations = 10000)
## Compute posterior probability of the desired tail
## which is to test the that the main effect
## of "high voice" goes in one direction
## (low voice people are taller)
post.prob = mean(chains[,"high-FALSE"]>0)
## Compute the prior probability of this restriction
prior.prob = .5
## Compute BFp1 (the Bayes factor of the restriction)
## against the full, unrestricted model
BFp1 = post.prob / prior.prob
## Use the transitivity of the Bayes factor to
## compute the one-tailed BFp0
BFp0 = BFp1 * BF10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.