Written and maintained by CASRAI Editorial Board
Last updated
BayesFactor is a free R package that computes Bayes factors for the designs most researchers actually run: t tests, ANOVA, linear regression, correlations, proportions and contingency tables. This page is for analysts who already use R and need to know which function fits their design, how to run it, and how to read the printed output. It was checked against the CRAN package page and the package’s User’s manual (dated 7 March 2026) on 2026-11-08.
What the BayesFactor package is used for in research
The CRAN title is “Computation of Bayes Factors for Common Designs”. The package description lists the designs it covers: contingency tables, one- and two-sample designs, one-way designs, general ANOVA designs, and linear regression. The current CRAN release is 0.9.12-4.8 (published 2026-03-07), it requires R 3.2.0 or later, depends on coda and Matrix, is licensed GPL-2, and contains compiled code. Richard D. Morey is the maintainer, with Jeffrey N. Rouder among the authors. The package is free to use.
A Bayes factor compares how well two models predict the observed data. This page covers the software; for what the numbers mean and how to describe the strength of evidence, see interpreting Bayes factors. For the wider contrast with p-value-based testing, see Bayesian vs frequentist statistics.
Install and load BayesFactor
The package is distributed through CRAN. In an R session the generic CRAN route is:
install.packages("BayesFactor")
library(BayesFactor)
The User’s manual says installation can be done in several ways and does not cover it; it starts from library(BayesFactor). Because the package contains compiled code (NeedsCompilation: yes on CRAN), installing from source needs a working compiler toolchain, while binary builds from CRAN do not.
Which BayesFactor function for which design
The User’s manual names one main function per design. This mapping is the quickest way to choose a starting call.
| Design | Function | Notes from the manual |
|---|---|---|
| One- or two-sample t test | ttestBF |
Default prior scale r = √2/2 (about 0.707) |
| ANOVA, many candidate models | anovaBF |
Compares many ANOVA models against an intercept-only denominator |
| Linear regression, many candidate models | regressionBF |
With p predictors there are 2p − 1 models |
| One specific linear model | lmBF |
Use when you want a named model rather than every combination |
| General mixed models and mixed predictors | generalTestBF |
Available from version 0.9.4 |
| Correlation | correlationBF |
Listed in the manual’s function overview |
| Proportions | proportionBF |
Listed in the manual’s function overview |
| Contingency tables | contingencyTableBF |
Listed in the manual’s function overview |
| Posterior samples, re-estimation, model comparison | posterior, recompute, compare |
posterior returns a BFmcmc object that works with coda’s MCMC methods |
Worked example: a paired t test, then a two-way ANOVA
Step 1. One-sample Bayes factor on difference scores
The manual’s first example uses R’s built-in sleep data. It computes the difference between the two drug conditions and tests those differences against zero:
data(sleep)diffScores = sleep$extra[1:10] - sleep$extra[11:20]bf = ttestBF(x = diffScores)bfprints the result;1 / bfinverts it to favour the null.
The printed result in the manual is a Bayes factor of about 17.3 for the alternative “Alt., r=0.707” against “Null, mu = 0”, labelled “Bayes factor type: BFoneSample, JZS”. Inverting it with 1 / bf gives about 0.0579, the same evidence expressed as null over alternative.
Step 2. Draw posterior samples (optional)
chains = posterior(bf, iterations = 1000)summary(chains)chains2 = recompute(chains, iterations = 10000)to rerun with more iterations.
Step 3. A two-way ANOVA on ToothGrowth
ToothGrowth$dose = factor(ToothGrowth$dose)(the manual also relabels the levels Low, Medium and High). A numeric dose would otherwise be treated as a continuous covariate, not a factor.bf = anovaBF(len ~ supp*dose, data = ToothGrowth)bfprints one row per model.
Reading the BayesFactor output
For the ANOVA above, the manual shows four rows, each a model compared with the same denominator:
| Row | Model | Bayes factor vs intercept-only |
|---|---|---|
| [1] | supp | 1.2, ±0.01% |
| [2] | dose | 4.98e+12, ±0% |
| [3] | supp + dose | 2.92e+14, ±1.58% |
| [4] | supp + dose + supp:dose | 7.44e+14, ±1.01% |
- Numerator and denominator. Each value is the support for that row’s model over the line “Against denominator”. Here the denominator is “Intercept only”; in the t test it was “Null, mu = 0”.
- The ± percentage. It is the estimation error of the computed Bayes factor itself, not a confidence interval on the effect. Rows involving more terms carry visibly larger error (1.58% and 1.01% here).
- Comparing two rows. Bayes factors against the same denominator can be divided. The manual shows
plot(bf[3:4] / bf[2]), which compares models 3 and 4 against model 2. - Type label. “BFlinearModel, JZS” and “BFoneSample, JZS” name the model class and the JZS prior family used.
The manual does not attach verbal evidence labels to values. To describe strength of evidence, use an explicit scale such as those in interpreting Bayes factors and say which one you used.
Priors and how to change them
Defaults matter because a Bayes factor depends on the prior. In the manual, the t test default is r = 0.707 and the fixed-effect default in rscaleFixed is r = 0.5. A single effect can be given its own scale with rscaleEffects, for example rscaleEffects = c(color = 1) in lmBF, anovaBF or generalTestBF. Slopes in regression use the Liang et al. hyper-g priors. When you change a scale, report the value you used alongside the Bayes factor. For prior choice in planning, see Bayesian sample size determination.
Troubleshooting common BayesFactor problems
anovaBF or regressionBF returns far more models than expected
The default whichModels = "withmain" only includes an interaction together with its main effects. Setting whichModels = "all" multiplies the model count: the manual gives 127 models for a three-way design and 32,767 for four-way. Use "top" (top-down analysis) or "bottom" to restrict the search. For regression, regressionBF(rating ~ ., data = attitude) returns 63 models because 26 − 1 = 63.
A numeric grouping variable is treated as a covariate
Convert it with factor() before calling anovaBF, as in the ToothGrowth example.
Repeated measures or participant effects
Declare the participant variable as a random factor: anovaBF(RT ~ shape*color + ID, data = puzzles, whichRandom = "ID"). The manual notes random factors are not themselves tested and are assumed additive.
Selecting one model from many
Index the result by its model name string, for example bf["privileges + learning + raises + critical + advance"], which the manual shows returning a factor of about 51.
Large ± error
For posterior sampling, rerun with more iterations using recompute, as in the 1,000 to 10,000 iteration example above. Report bugs at the package’s GitHub issue tracker (github.com/richarddmorey/BayesFactor/issues).
Free alternatives and related tools
| Tool | Relationship to BayesFactor | Source |
|---|---|---|
| jamovi (via the jmv R package) | The CRAN page lists jmv among the packages that depend on BayesFactor, so jamovi analyses can use the same engine through a point-and-click interface | CRAN BayesFactor package page, read 2026-11-08 |
For hierarchical or multilevel models that go beyond the designs above, see Bayesian hierarchical models.
FAQ
What does the BayesFactor R package do?
It computes Bayes factors for t tests, ANOVA, linear regression, correlations, proportions and contingency tables, comparing a model of interest with a null or intercept-only model.
How do I install BayesFactor?
Run install.packages("BayesFactor") in R, then library(BayesFactor). The package is on CRAN under GPL-2.
Which function runs a Bayesian t test?
ttestBF, for one- and two-sample designs, with a default prior scale of about 0.707.
How do I turn a Bayes factor in favour of the alternative into one in favour of the null?
Take the reciprocal: 1 / bf. In the manual’s example, 17.3 becomes about 0.0579.
What does the percentage after a Bayes factor mean?
It is the estimation error of the Bayes factor calculation, shown as ±%.
Sources
- CRAN, “BayesFactor: Computation of Bayes Factors for Common Designs”, version 0.9.12-4.8: cran.r-project.org/web/packages/BayesFactor (read 2026-11-08).
- BayesFactor User’s manual vignette, dated 7 March 2026: cran.r-project.org/web/packages/BayesFactor/vignettes/manual.html (read 2026-11-08).
- Package site: richarddmorey.github.io/BayesFactor.







