Bain
Bain
URL https://informative-hypotheses.sites.uu.nl/software/bain/
BugReports https://github.com/cjvanlissa/bain/
NeedsCompilation yes
RoxygenNote 7.3.1
Depends R (>= 3.0.0), stats
Imports lavaan
Suggests MASS, testthat, knitr, rmarkdown
VignetteBuilder knitr
Author Xin Gu [aut],
Herbert Hoijtink [aut],
Joris Mulder [aut],
Caspar J van Lissa [aut, cre],
Van Zundert Camiel [ctb],
Jeff Jones [ctb],
Niels Waller [ctb]
1
2 bain
Contents
bain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
bain_sensitivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
kuiper2013 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
pbf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
seBeta . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
sesamesim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
synthetic_dk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
synthetic_nl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
synthetic_us . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
t_test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Index 16
Description
bain is an acronym for "Bayesian informative hypotheses evaluation". It uses the Bayes fac-
tor to evaluate hypotheses specified using equality and inequality constraints among (linear com-
binations of) parameters in a wide range of statistical models. A tutorial by Hoijtink, Mul-
der, van Lissa, and Gu (2018), was published in Psychological Methods. The preprint of that
tutorial is available on PsyArxiv (doi:10.31234/osf.io/v3shc) or on the bain website at https:
//informative-hypotheses.sites.uu.nl/software/bain/ Users are advised to read the tu-
torial AND the vignette that is provided with this package before using bain.
Usage
bain(x, hypothesis, fraction = 1, ...)
Arguments
x An R object containing the outcome of a statistical analysis. Currently, the fol-
lowing objects can be processed: lm(), t_test(), lavaan objects created with
the sem(), cfa(), and growth() functions, and named vector objects. See the
vignette for elaborations.
hypothesis A character string containing the informative hypotheses to evaluate. See the
vignette for elaborations.
fraction A number representing the fraction of information in the data used to construct
the prior distribution. The default value 1 denotes the minimal fraction, 2 de-
notes twice the minimal fraction, etc. See the vignette for elaborations.
bain 3
Value
The main output resulting from analyses with bain are Bayes factors and posterior model probabil-
ities associated with the hypotheses that are evaluated. See the tutorial and the vignette for further
elaborations.
Author(s)
The main authors of the bain package are Xin Gu, Caspar van Lissa, Herbert Hoijtink and Joris
Mulder with smaller contributions by Marlyne Bosman, Camiel van Zundert, and Fayette Klaassen.
Contact information can be found on the bain website at https://informative-hypotheses.
sites.uu.nl/software/bain/
References
For a tutorial on this method, see:
Hoijtink, H., Mulder, J., van Lissa, C., & Gu, X. (2019). A tutorial on testing hypotheses using the
Bayes factor. Psychological methods, 24(5), 539. doi:10.1037/met0000201
For applications in structural equation modeling, see:
Van Lissa, C. J., Gu, X., Mulder, J., Rosseel, Y., Van Zundert, C., & Hoijtink, H. (2021). Teacher’s
corner: Evaluating informative hypotheses using the Bayes factor in structural equation mod-
els. Structural Equation Modeling: A Multidisciplinary Journal, 28(2), 292-301. doi:10.1080/
10705511.2020.1745644.
For the statistical underpinnings, see:
Gu, Mulder, and Hoijtink (2018). Approximated adjusted fractional Bayes factors: A general
method for testing informative hypotheses. British Journal of Mathematical and Statistical Psy-
chology, 71(2), 229-261. doi:10.1111/bmsp.12110.
Hoijtink, H., Gu, X., & Mulder, J. (2019). Bayesian evaluation of informative hypotheses for
multiple populations. British Journal of Mathematical and Statistical Psychology, 72(2), 219-243.
doi:10.1111/bmsp.12145.
Hoijtink, H., Gu, X., Mulder, J., & Rosseel, Y. (2019). Computing Bayes factors from data with
missing values. Psychological Methods, 24(2), 253. doi:10.31234/osf.io/q6h5w
Examples
# Evaluation of informative hypotheses for an ANOVA
# make a factor of variable site
sesamesim$site <- as.factor(sesamesim$site)
# execute an analysis of variance using lm() which, due to the -1, returns
# estimates of the means of postnumb per group
anov <- lm(postnumb~site-1,sesamesim)
# take a look at the estimated means and their names
coef(anov)
# set a seed value
set.seed(100)
# use the names to formulate and test hypotheses with bain
4 bain_sensitivity
Description
Conducts a sensitivity analysis for bain.
Usage
bain_sensitivity(x, hypothesis, fractions = 1, ...)
Arguments
x An R object containing the outcome of a statistical analysis. Currently, the fol-
lowing objects can be processed: lm(), t_test(), lavaan objects created with
the sem(), cfa(), and growth() functions, and named vector objects. See the
vignette for elaborations.
hypothesis A character string containing the informative hypotheses to evaluate. See the
vignette for elaborations.
fractions A number representing the fraction of information in the data used to construct
the prior distribution. The default value 1 denotes the minimal fraction, 2 de-
notes twice the minimal fraction, etc. See the vignette for elaborations.
... Additional arguments passed to bain.
Details
The Bayes factor for equality constraints is sensitive to a scaling factor applied to the prior dis-
tribution. The argument fraction adjusts this scaling factor. The function bain_sensitivity
is a wrapper for bain, which accepts a vector for the fractions argument, and returns a list of
bain results objects. A table with a sensitivity analysis for specific statistics can be obtained using
the summary() function, which accepts the argument summary(which_stat = ...). The avail-
able statistics are elements of the $fit table (Fit_eq, Com_eq, Fit_in, Com_in, Fit, Com, BF,
PMPa, and PMPb), and elements of the BFmatrix, which can be accessed by matrix notation, e.g.:
summary(bain_sens, which_stat = "BFmatrix[1,2]").
Value
A data.frame of class "bain_sensitivity".
kuiper2013 5
Examples
sesamesim$site <- as.factor(sesamesim$site)
res <- lm(sesamesim$postnumb~sesamesim$site-1)
set.seed(4583)
bain_sens <- bain_sensitivity(res, "site1=site2;
site2>site5",
fractions = c(1,2,3))
summary(bain_sens, which_stat = "BF.c")
summary(bain_sens, which_stat = "BFmatrix[1,2]")
Description
These data were published in Kuiper and colleagues (2013), who set out to aggregate evidence for
the effect of prior interactions between partners on trust in (economic) exchange relations across
four heterogeneous replication studies. Batenburg et al. (2003) analyzed survey data using linear
regression with covariates; Buskens and Raub (2002) analyzed experimental data using linear re-
gression; Buskens and Weesie (2000) used an experimental design with a binary outcome, analyzed
using probit regression; and Buskens, Raub, and Van der Veer (2010) used a longitudinal experi-
mental design, analyzing the data with a three-level logistic regression. These studies each provide
a regression coefficient (beta) assessing the effect of past experience on trust, and its estimated
sampling variance (squared standard error). The sample sizes (n) were derived from the original
publications.
Usage
data(kuiper2013)
Format
Details
References
Kuiper, R. M., Buskens, V., Raub, W., & Hoijtink, H. (2013). Combining Statistical Evidence From
Several Studies: A Method Using Bayesian Updating and an Example From Research on Trust
Problems in Social and Economic Exchange. Sociological Methods & Research, 42(1), 60–81.
<doi:10.1177/0049124112464867>
Batenburg, R. S., W. Raub, and C. Snijders. 2003. Contacts and Contracts: Temporal Embedded-
ness and the Contractual Behavior of Firms. Research in the Sociology of Organizations 20:135-88.
Buskens, V. and W. Raub. 2002. Embedded Trust: Control and Learning. Advances in Group
Processes 19:167-202.
Buskens, V., W. Raub, and J. van der Veer. 2010. Trust in Triads: An Experimental Study. Social
Networks 32:301-12.
Buskens, V. and J. Weesie. 2000. An Experiment on the Effects of Embeddedness in Trust Situa-
tions: Buying a Used Car. Rationality and Society 12:227-53.
Description
The product Bayes factor (PBF) aggregates evidence for an informative hypothesis across concep-
tual replication studies without imposing assumptions about heterogeneity.
Usage
pbf(...)
## Default S3 method:
pbf(x, ...)
Arguments
... Additional arguments passed to ‘bain‘.
x An object for which a method exists, see Details.
yi Numeric vector with the observed effect sizes.
vi Numeric vector with the observed sampling variances.
ni Integer vector with the sample sizes.
hypothesis A character string containing the informative hypotheses to evaluate.
Details
Currently, the argument ‘x‘ accepts either: * A list of ‘bain‘ objects, resulting from a call to ‘bain‘.
* A list of model objects for which a ‘bain‘ method exists; in this case, ‘pbf‘ will call ‘bain‘ on
these model objects before aggregating the Bayes factors.
seBeta 7
Value
A ‘data.frame‘ of class ‘pbf‘.
References
Van Lissa, C. J., Kuiper, R. M., & Clapper, E. (2023, April 25). Aggregating evidence from con-
ceptual replication studies using the product Bayes factor. doi:10.31234/osf.io/nvqpw
Examples
pbf(yi = c(-.33, .32, .39, .31),
vi = c(.085, .034, .016, .071),
ni = c(7, 10, 13, 20))
Description
Computes Normal Theory and ADF Standard Errors and CIs for Standardized Regression Coeffi-
cients
Usage
seBeta(
X = NULL,
y = NULL,
cov.x = NULL,
cov.xy = NULL,
var.y = NULL,
Nobs = NULL,
alpha = 0.05,
estimator = "ADF"
)
Arguments
X Matrix of predictor scores.
y Vector of criterion scores.
cov.x Covariance or correlation matrix of predictors.
cov.xy Vector of covariances or correlations between predictors and criterion.
var.y Criterion variance.
Nobs Number of observations.
alpha Desired Type I error rate; default = .05.
estimator ’ADF’ or ’Normal’ confidence intervals - requires raw X and raw y; default =
’ADF’.
8 seBeta
Value
Author(s)
References
Jones, J. A, and Waller, N. G. (2015). The Normal-Theory and Asymptotic Distribution-Free (ADF)
covariance matrix of standardized regression coefficients: Theoretical extensions and finite sample
behavior. Psychometrika, 80, 365-378.
Examples
set.seed(123)
R <- matrix(.5, 3, 3)
diag(R) <- 1
X <- sesamesim[, c("peabody", "prenumb", "postnumb")]
y <- sesamesim$age
results <- seBeta(X, y, Nobs = nrow(sesamesim), alpha = .05, estimator = 'ADF')
print(results, digits = 3)
library(MASS)
set.seed(123)
R <- matrix(.5, 3, 3)
diag(R) <- 1
X <- mvrnorm(n = 200, mu = rep(0, 3), Sigma = R, empirical = TRUE)
Beta <- c(.2, .3, .4)
y <- X %*% Beta + .64 * scale(rnorm(200))
results <- seBeta(X, y, Nobs = 200, alpha = .05, estimator = 'ADF')
print(results, digits = 3)
sesamesim 9
Description
This is a simulated counterpart of part of the Sesame Street data presented by Stevens (1996, Ap-
pendix A) concerning the effect of the first year of the Sesame street series on the knowledge of 240
children in the age range 34 to 69 months. We will use the following variables: sex; site of child’s
origin; setting in which Sesame Street is watched; age; whether or not the child is encouraged to
watch; Peabody metal age score; score on numbers test before, after and in a follow up measure-
ment; and scores on knowledge of body parts, letters, forms, numbers, relations, and classifications,
both before and after watching Sesame Street for a year.
Usage
data(sesamesim)
Format
A data frame with 240 rows and 21 variables.
Details
References
Stevens, J. (1996). Applied Multivariate Statistics for the Social Sciences. Mahwah NJ: Lawrence
Erlbaum.
Description
This is a simulated counterpart of data presented by Van Leeuwen and colleagues (2022) concern-
ing associations between moral dispositions (measured using the Morality As Cooperation ques-
tionnaire, MAC; see Curry et al., 2019) and political orientation.
Usage
data(synthetic_dk)
Format
A data frame with 552 rows and 31 variables.
Details
References
Van Leeuwen, F., Van Lissa, C. J., Papakonstantinou, T., Petersen, M., & Curry, O. S. (2022, May
25). Morality as Cooperation, Politics as Conflict. <doi:10.31234/osf.io/wm6rk>
Curry, O. S., Chesters, M. J., & Van Lissa, C. J. (2019). Mapping morality with a compass: Testing
the theory of ’morality-as-cooperation’ with a new questionnaire. Journal of Research in Personal-
ity, 78, 106-124.
Description
This is a simulated counterpart of data presented by Van Leeuwen and colleagues (2022) concern-
ing associations between moral dispositions (measured using the Morality As Cooperation ques-
tionnaire, MAC; see Curry et al., 2019) and political orientation.
Usage
data(synthetic_nl)
Format
A data frame with 401 rows and 38 variables.
Details
References
Van Leeuwen, F., Van Lissa, C. J., Papakonstantinou, T., Petersen, M., & Curry, O. S. (2022, May
25). Morality as Cooperation, Politics as Conflict. <doi:10.31234/osf.io/wm6rk>
Curry, O. S., Chesters, M. J., & Van Lissa, C. J. (2019). Mapping morality with a compass: Testing
the theory of ‘morality-as-cooperation’with a new questionnaire. Journal of Research in Personality,
78, 106-124.
Description
This is a simulated counterpart of data presented by Van Leeuwen and colleagues (2022) concern-
ing associations between moral dispositions (measured using the Morality As Cooperation ques-
tionnaire, MAC; see Curry et al., 2019) and political orientation.
Usage
data(synthetic_us)
Format
A data frame with 518 rows and 33 variables.
Details
secs_soc_1 numeric Item 1 of the Social and Economic Conservatism Scale (social subscale) scale.
secs_soc_2 numeric Item 2 of the Social and Economic Conservatism Scale (social subscale) scale.
secs_soc_3 numeric Item 3 of the Social and Economic Conservatism Scale (social subscale) scale.
secs_soc_4 numeric Item 4 of the Social and Economic Conservatism Scale (social subscale) scale.
secs_soc_5 numeric Item 5 of the Social and Economic Conservatism Scale (social subscale) scale.
secs_soc_6 numeric Item 6 of the Social and Economic Conservatism Scale (social subscale) scale.
secs_soc_7 numeric Item 7 of the Social and Economic Conservatism Scale (social subscale) scale.
secs_eco_1 numeric Item 1 of the Social and Economic Conservatism Scale (economic subscale) scale.
secs_eco_2 numeric Item 2 of the Social and Economic Conservatism Scale (economic subscale) scale.
secs_eco_3 numeric Item 3 of the Social and Economic Conservatism Scale (economic subscale) scale.
secs_eco_4 numeric Item 4 of the Social and Economic Conservatism Scale (economic subscale) scale.
secs_eco_5 numeric Item 5 of the Social and Economic Conservatism Scale (economic subscale) scale.
fam_1 numeric Item 1 of the MAC (family subscale) scale.
fam_2 numeric Item 2 of the MAC (family subscale) scale.
fam_3 numeric Item 3 of the MAC (family subscale) scale.
grp_1 numeric Item 1 of the MAC (group subscale) scale.
grp_2 numeric Item 2 of the MAC (group subscale) scale.
grp_3 numeric Item 3 of the MAC (group subscale) scale.
rec_1 numeric Item 1 of the MAC (reciprocity subscale) scale.
rec_2 numeric Item 2 of the MAC (reciprocity subscale) scale.
rec_3 numeric Item 3 of the MAC (reciprocity subscale) scale.
her_1 numeric Item 1 of the MAC (heroism subscale) scale.
her_2 numeric Item 2 of the MAC (heroism subscale) scale.
her_3 numeric Item 3 of the MAC (heroism subscale) scale.
def_1 numeric Item 1 of the MAC (deference subscale) scale.
def_2 numeric Item 2 of the MAC (deference subscale) scale.
def_3 numeric Item 3 of the MAC (deference subscale) scale.
fai_1 numeric Item 1 of the MAC (fairness subscale) scale.
fai_2 numeric Item 2 of the MAC (fairness subscale) scale.
fai_3 numeric Item 3 of the MAC (fairness subscale) scale.
pro_1 numeric Item 1 of the MAC (property subscale) scale.
pro_2 numeric Item 2 of the MAC (property subscale) scale.
pro_3 numeric Item 3 of the MAC (property subscale) scale.
14 t_test
References
Van Leeuwen, F., Van Lissa, C. J., Papakonstantinou, T., Petersen, M., & Curry, O. S. (2022, May
25). Morality as Cooperation, Politics as Conflict. <doi:10.31234/osf.io/wm6rk>
Curry, O. S., Chesters, M. J., & Van Lissa, C. J. (2019). Mapping morality with a compass: Testing
the theory of ‘morality-as-cooperation’with a new questionnaire. Journal of Research in Personality,
78, 106-124.
Description
This function is a wrapper for the function t.test, which returns group-specific sample sizes and
variances, in addition to the usual output of t.test.
Usage
t_test(x, ...)
Arguments
x An object for which an S3 method of t.test exists (vector or formula).
... arguments passed to t.test.
Details
This wrapper allows users to enjoy the functionality of bain with the familiar interface of the stats-
function t.test.
For more documentation, see t.test.
Value
A list with class "t_test" containing the following components:
statistic the value of the t-statistic.
parameter the degrees of freedom for the t-statistic.
p.value the p-value for the test.
conf.int a confidence interval for the mean appropriate to the specified alternative hy-
pothesis.
estimate the estimated mean or difference in means depending on whether it was a one-
sample test or a two-sample test.
null.value the specified hypothesized value of the mean or mean difference depending on
whether it was a one-sample test or a two-sample test.
t_test 15
See Also
t.test
Examples
tmp <- t_test(extra ~ group, data = sleep)
tmp$n
tmp$v
tmp2 <- t_test(extra ~ group, data = sleep)
tmp2$n
tmp2$v
tmp <- t_test(Pair(sleep$extra[sleep$group == 1], sleep$extra[sleep$group == 2]) ~ 1)
tmp$n
tmp$v
t_test(sesamesim$postnumb)
tmp <- t_test(sesamesim$prenumb)
tmp$n
tmp$v
tmp2 <- t_test(sesamesim$prenumb)
tmp2$n
tmp2$v
tmp <- t_test(sesamesim$prenumb, sesamesim$postnumb)
tmp$n
tmp$v
tmp2 <- t_test(sesamesim$prenumb, sesamesim$postnumb)
tmp2$n
tmp2$v
tmp <- t_test(sesamesim$prenumb, sesamesim$postnumb, paired = TRUE)
tmp$n
tmp$v
tmp2 <- t_test(sesamesim$prenumb, sesamesim$postnumb, paired = TRUE)
tmp2$n
tmp2$v
Index
∗ Statistics
seBeta, 7
∗ datasets
kuiper2013, 5
sesamesim, 9
synthetic_dk, 10
synthetic_nl, 11
synthetic_us, 12
∗ htest
t_test, 14
bain, 2, 4
bain_sensitivity, 4
kuiper2013, 5
pbf, 6
seBeta, 7
sesamesim, 9
synthetic_dk, 10
synthetic_nl, 11
synthetic_us, 12
t.test, 14, 15
t_test, 14
16