BFpack v0.2.1


Monthly downloads



Flexible Bayes Factor Testing of Scientific Expectations

Implementation of various default Bayes factors for testing statistical hypotheses. The package is intended for applied quantitative researchers in the social and behavioral sciences, medical research, and related fields. The Bayes factor tests can be executed for statistical models such as univariate and multivariate normal linear models, generalized linear models, special cases of linear mixed models, survival models, relational event models. Parameters that can be tested are location parameters (e.g., regression coefficients), variances (e.g., group variances), and measures of association (e.g,. bivariate correlations). The statistical underpinnings are described in Mulder, Hoijtink, and Xin (2019) <arXiv:1904.00679>, Mulder and Gelissen (2019) <arXiv:1807.05819>, Mulder (2016) <DOI:10.1016/>, Mulder and Fox (2019) <DOI:10.1214/18-BA1115>, Mulder and Fox (2013) <DOI:10.1007/s11222-011-9295-3>, Boeing-Messing, van Assen, Hofman, Hoijtink, and Mulder <DOI:10.1037/met0000116>, Hoijtink, Mulder, van Lissa, and Gu, (2018) <DOI:10.31234/>, Gu, Mulder, and Hoijtink, (2018) <DOI:10.1111/bmsp.12110>, Hoijtink, Gu, and Mulder, (2018) <DOI:10.1111/bmsp.12145>, and Hoijtink, Gu, Mulder, and Rosseel, (2018) <DOI:10.1037/met0000187>.



R-functions for Bayesian exploratory (equal vs negative vs postive) and confirmatory (equality and/or order constraints) hypothesis testing for commonly used statistical models, including (but not limited to) univariate/multivariate t testing, (M)AN(C)OVA, multivariate/univariate regression, random intercept models. The functions need fitted models (e.g., lm) as input as well as a string that specifies a set of order constraints on the regression coefficients.

Developers and collaborators: Joris Mulder, Caspar van Lissa, Donald R. Williams, Xin Gu, Anton Olsson-Collentine, Florian Böing-Messing, Andrew Tomarken, Marlyne Bosman-Meijerink, Eric-Jan Wagenmakers, Yves Rosseel, Jean-Paul Fox, Janosch Menke, and Herbert Hoijtink.

Licensed under the GNU General Public License version 2 (June, 1991)


You can install BFpack from GitHub with:

``` r



Example analyses

Aapplication 1

load R package BFpack and bain

library(BFpack) library(bain)

Frequentist one sample t test at the null point mu=5 on the therapeutic data

ttest1 <- t_test(therapeutic,mu=5) print(ttest1)

confirmatory Bayesian one sample t test

BF1 <- BF(ttest1,"mu=5") summary(BF1)

Application 2

Fit an anova model on the tvprices data

aov1 <- aov(price ~ anchor*motivation,data=tvprices)

Perform exploratory Bayes factor tests for ANOVA design


Application 3

Perform classical Bartlett test for homogeneity of group varianceson the accuracy data

bartlett <- bartlett_test(x = attention$accuracy, g = attention$group)

Specify informative hypotheses on the group variances based on substantive expectations

hypothesis <- c("Controls=TS<ADHD; Controls<TS=ADHD; Controls=TS=ADHD") set.seed(358)

Perform the Bayesian hypothesis tests

BF_var <- BF(bartlett, hypothesis) summary(BF_var)

Application 4

Fit the multivariate regression model on the fmri data

fmri.lm <- lm(cbind(Superficial,Middle,Deep) ~ Face + Vehicle, data=fmri)

Specify informative hypotheses on the coefficients across predictor and dependent variables

based on substantive expectations

constraints.fmri <- "Face_on_Deep = Face_on_Superficial = Face_on_Middle < 0 < Vehicle_on_Deep = Vehicle_on_Superficial = Vehicle_on_Middle; Face_on_Deep < Face_on_Superficial = Face_on_Middle < 0 < Vehicle_on_Deep = Vehicle_on_Superficial = Vehicle_on_Middle"

Perform the Bayesian hypothesis tests

set.seed(123) BF_fmri <- BF(fmri.lm, hypothesis = constraints.fmri) summary(BF_fmri)

Application 4b

constraints.fmri2 <- "Face_on_Deep = Face_on_Superficial = Face_on_Middle < 0; Face_on_Deep < Face_on_Superficial = Face_on_Middle < 0" fmri.lm2 <- lm(cbind(Superficial,Middle,Deep) ~ Face + Vehicle, data=fmri) BF.fmri2 <- BF(fmri.lm2, hypothesis=constraints.fmri2)

#Application 5

Fit logistic regression model

fit <- glm(sent ~ ztrust + zfWHR + zAfro + glasses + attract + maturity + tattoos, family = binomial(), data = wilson)

Perform the Bayesian hypothesis tests

set.seed(123) BF_glm <- BF(fit, hypothesis="ztrust > (zfWHR, zAfro) > 0; ztrust > (zfWHR, zAfro) = 0") summary(BF_glm)

Application 6: Correlation analysis

#Fit multivariate normal model lm6 <- lm(cbind(Im,Del,Wmn,Cat,Fas,Rat) ~ -1 + Group, data=memory) set.seed(123)

#Perform Bayes factor test of the order hypothesis against its compleplement BF6_cor <- BF(lm6,parameter="correlation", hypothesis= "Del_with_Im_in_GroupHC > Del_with_Im_in_GroupSZ & Del_with_Wmn_in_GroupHC > Del_with_Wmn_in_GroupSZ & Del_with_Cat_in_GroupHC > Del_with_Cat_in_GroupSZ & Del_with_Fas_in_GroupHC > Del_with_Fas_in_GroupSZ & Del_with_Rat_in_GroupHC > Del_with_Rat_in_GroupSZ & Im_with_Wmn_in_GroupHC > Im_with_Wmn_in_GroupSZ & Im_with_Cat_in_GroupHC > Im_with_Cat_in_GroupSZ & Im_with_Fas_in_GroupHC > Im_with_Fas_in_GroupSZ & Im_with_Rat_in_GroupHC > Im_with_Rat_in_GroupSZ & Wmn_with_Cat_in_GroupHC > Wmn_with_Cat_in_GroupSZ & Wmn_with_Fas_in_GroupHC > Wmn_with_Fas_in_GroupSZ & Wmn_with_Rat_in_GroupHC > Wmn_with_Rat_in_GroupSZ & Cat_with_Fas_in_GroupHC > Cat_with_Fas_in_GroupSZ & Cat_with_Rat_in_GroupHC > Cat_with_Rat_in_GroupSZ & Fas_with_Rat_in_GroupHC > Fas_with_Rat_in_GroupSZ") summary(BF6_cor)

Application 7. Testing intraclas correlations


#Only consider the timssICC data for the measurements of the four counteries in 2011 timssICC_subset <- timssICC[(timssICC$groupNL11==1)+(timssICC$groupHR11==1)+ (timssICC$groupDE11==1)+(timssICC$groupDK11==1)>0,]

#Fit a random intercept model with country specific random effect variances across schools outlme1 <- lmer(math ~ -1 + gender + weight + lln + groupNL11 + (0+groupNL11 | schoolID) + groupHR11 + (0+groupHR11 | schoolID) + groupDE11 + (0+groupDE11 | schoolID) + groupDK11 + (0+groupDK11 | schoolID), data=timssICC_subset)

#Perform Bayes factor test on intraclass correlations across countries in 2011 set.seed(123) BFout <- BF(outlme1,hypothesis= "groupNL11<groupHR11<groupDE11<groupDK11; groupNL11=groupHR11=groupDE11=groupDK11") summary(BFout)

Functions in BFpack

Name Description
BF Bayes factors for Bayesian exploratory and confirmatory hypothesis testing
actors Actors from a consultancy firm
therapeutic Data come from an experimental study (Rosa, Rosa, Sarner, and Barrett, 1998) that were also used in Howell (2012, p.196). An experiment was conducted to investigate if Therapeutic Touch practitioners who were blindfolded can effectively identify which of their hands is below the experimenter<U+00A1><U+00AF>s. Twenty-eight practitioners were involved and tested 10 times in the experiment. Researchers expected an average of 5 correct answers from each practitioner as it is the number by chance if they do not outperform others.
timssICC Trends in International Mathematics and Science Study (TIMSS) 2011-2015
attention Multiple Sources of Attentional Dysfunction in Adults With Tourette's Syndrome
bartlett_test Bartlett Test of Homogeneity of Variances
cor_test Bayesian correlation analysis
relevents A sequence of innovation-related e-mail messages
fmri fMRI data
memory Memory data on health and schizophrenic patients
tvprices Precision of the Anchor Influences the Amount of Adjustment
wilson Facial trustworthiness and criminal sentencing
sivan Wason task performance and morality
same_division Same division event statistic
same_hierarchy Same hierarchical position event statistic
same_building Same building event statistic
No Results!

Last month downloads


Type Package
Date 2020-05-11
License GPL (>= 3)
Encoding UTF-8
LazyData true
NeedsCompilation yes
RoxygenNote 6.1.1
Packaged 2020-05-11 16:04:12 UTC; jorismulder
Repository CRAN
Date/Publication 2020-05-11 17:50:02 UTC

Include our badge in your README