Title: | Flexible Bayes Factor Testing of Scientific Expectations |
---|---|
Description: | Implementation of default Bayes factors for testing statistical hypotheses under various statistical models. 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, correlation analysis, generalized linear models, special cases of linear mixed models, survival models, relational event models. Parameters that can be tested are location parameters (e.g., group means, regression coefficients), variances (e.g., group variances), and measures of association (e.g,. polychoric/polyserial/biserial/tetrachoric/product moments correlations), among others. The statistical underpinnings are described in Mulder and Xin (2022) <DOI:10.1080/00273171.2021.1904809>, Mulder and Gelissen (2019) <DOI:10.1080/02664763.2021.1992360>, Mulder (2016) <DOI:10.1016/j.jmp.2014.09.004>, 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 (2017) <DOI:10.1037/met0000116>, Hoijtink, Mulder, van Lissa, and Gu (2018) <DOI:10.1037/met0000201>, 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>. When using the packages, please refer to Mulder et al. (2021) <DOI:10.18637/jss.v100.i18>. |
Authors: | Joris Mulder [aut, cre], Caspar van Lissa [aut, ctb], Donald R. Williams [aut, ctb], Xin Gu [aut, ctb], Anton Olsson-Collentine [aut, ctb], Florian Boeing-Messing [aut, ctb], Jean-Paul Fox [aut, ctb], Janosch Menke [ctb], Robbie van Aert [ctb], Barry Brown [ctb], James Lovato [ctb], Kathy Russell [ctb], Lapack 3.8 [ctb], Jack Dongarra [ctb], Jim Bunch [ctb], Cleve Moler [ctb], Gilbert Stewart [ctb], John Burkandt [ctb], Ashwith Rego [ctb], Alexander Godunov [ctb], Alan Miller [ctb], Jean-Pierre Moreau [ctb], The R Core Team [cph] |
Maintainer: | Joris Mulder <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.4.0 |
Built: | 2024-11-22 05:54:36 UTC |
Source: | https://github.com/jomulder/bfpack |
The R
package BFpack provides tools for exploratory and
confirmatory Bayesian hypothesis testing using Bayes factors and posterior probabilities
under common statistical models. The main function 'BF' needs a fitted model 'x' as input
argument. Depending on the class of the fitted model, a standard hypothesis test is
executed by default. For example, if 'x' is a
fitted regression model of class 'lm' then posterior probabilities are computed of whether
each separate coefficient is zero, negative, or positive (assuming equal prior probabilities).
If one has specific hypotheses with
equality and/or order constraints on the parameters under the fitted model 'x' then these
can be formulated using the 'hypothesis' argument (a character string), possibly together
prior probabilities for the hypotheses via the 'prior' argument (default all hypotheses are
equally likely a priori), and the 'complement' argument which is a logical stating whether
the complement hypotheses should be included in the case ('TRUE' by default).
Use compilation for Fortran functions
Maintainer: Joris Mulder [email protected]
Authors:
Caspar van Lissa [email protected] [contributor]
Donald R. Williams [email protected] [contributor]
Xin Gu [email protected] [contributor]
Anton Olsson-Collentine [email protected] [contributor]
Florian Boeing-Messing [email protected] [contributor]
Jean-Paul Fox [email protected] [contributor]
Other contributors:
Janosch Menke [email protected] [contributor]
Robbie van Aert [email protected] [contributor]
Barry Brown [contributor]
James Lovato [contributor]
Kathy Russell [contributor]
Lapack 3.8 [contributor]
Jack Dongarra [contributor]
Jim Bunch [contributor]
Cleve Moler [contributor]
Gilbert Stewart [contributor]
John Burkandt [contributor]
Ashwith Rego [contributor]
Alexander Godunov [contributor]
Alan Miller [contributor]
Jean-Pierre Moreau [contributor]
The R Core Team [copyright holder]
Mulder, J., D.R. Williams, Gu, X., A. Tomarken, F. Böing-Messing, J.A.O.C. Olsson-Collentine, Marlyne Meyerink, J. Menke, J.-P. Fox, Y. Rosseel, E.J. Wagenmakers, H. Hoijtink., and van Lissa, C. (submitted). BFpack: Flexible Bayes Factor Testing of Scientific Theories in R. https://arxiv.org/abs/1911.07728
Mulder, J., van Lissa, C., Gu, X., Olsson-Collentine, A., Boeing-Messing, F., Williams, D. R., Fox, J.-P., Menke, J., et al. (2019). BFpack: Flexible Bayes Factor Testing of Scientific Expectations. (Version 0.2.1) https://CRAN.R-project.org/package=BFpack
Useful links:
## Not run: # EXAMPLE 1. One-sample t test ttest1 <- t_test(therapeutic, mu = 5) print(ttest1) # confirmatory Bayesian one sample t test BF1 <- BF(ttest1, hypothesis = "mu = 5") summary(BF1) # exploratory Bayesian one sample t test BF(ttest1) # EXAMPLE 2. ANOVA aov1 <- aov(price ~ anchor * motivation,data = tvprices) BF1 <- BF(aov1, hypothesis = "anchorrounded = motivationlow; anchorrounded < motivationlow") summary(BF1) # EXAMPLE 3. Logistic regression fit <- glm(sent ~ ztrust + zfWHR + zAfro + glasses + attract + maturity + tattoos, family = binomial(), data = wilson) BF1 <- BF(fit, hypothesis = "ztrust > zfWHR > 0; ztrust > 0 & zfWHR = 0") summary(BF1) # EXAMPLE 4. Correlation analysis set.seed(123) cor1 <- cor_test(memory[1:20,1:3]) BF1 <- BF(cor1) summary(BF1) BF2 <- BF(cor1, hypothesis = "Wmn_with_Im > Wmn_with_Del > 0; Wmn_with_Im = Wmn_with_Del = 0") summary(BF2) ## End(Not run)
## Not run: # EXAMPLE 1. One-sample t test ttest1 <- t_test(therapeutic, mu = 5) print(ttest1) # confirmatory Bayesian one sample t test BF1 <- BF(ttest1, hypothesis = "mu = 5") summary(BF1) # exploratory Bayesian one sample t test BF(ttest1) # EXAMPLE 2. ANOVA aov1 <- aov(price ~ anchor * motivation,data = tvprices) BF1 <- BF(aov1, hypothesis = "anchorrounded = motivationlow; anchorrounded < motivationlow") summary(BF1) # EXAMPLE 3. Logistic regression fit <- glm(sent ~ ztrust + zfWHR + zAfro + glasses + attract + maturity + tattoos, family = binomial(), data = wilson) BF1 <- BF(fit, hypothesis = "ztrust > zfWHR > 0; ztrust > 0 & zfWHR = 0") summary(BF1) # EXAMPLE 4. Correlation analysis set.seed(123) cor1 <- cor_test(memory[1:20,1:3]) BF1 <- BF(cor1) summary(BF1) BF2 <- BF(cor1, hypothesis = "Wmn_with_Im > Wmn_with_Del > 0; Wmn_with_Im = Wmn_with_Del = 0") summary(BF2) ## End(Not run)
The related data files 'events', 'same_location', 'same_culture' contain information on the event sequence and the two event statistics respectively.
data(actors)
data(actors)
dataframe (25 rows, 4 columns)
actors$id | integer |
ID of the employee, corresponding to the sender and receiver IDs in the events dataframe |
actors$location | numeric |
Location of the actor, ranging from 1-4 |
actors$culture | character |
Categorical variable, indicating the culture of the employee |
Data from a psychological study comparing attentional performances of Tourette's syndrome (TS) patients, ADHD patients, and controls. These data were simulated using the sufficient statistics from Silverstein, Como, Palumbo, West, and Osborn (1995).
data(attention)
data(attention)
A data.frame with 51 rows and 2 columns.
accuracy | numeric |
Participant's accuracy in the attentional task |
group | factor |
Participant's group membership (TS patient, ADHD patient, or control) |
Silverstein, S. M., Como, P. G., Palumbo, D. R., West, L. L., & Osborn, L. M. (1995). Multiple sources of attentional dysfunction in adults with Tourette's syndrome: Comparison with attention deficit-hyperactivity disorder. Neuropsychology, 9(2), 157-164. doi:10.1037/0894-4105.9.2.157
Performs Bartlett's test of the null that the variances in each of the groups (samples) are the same.
bartlett_test(x, g, ...) ## Default S3 method: bartlett_test(x, g, ...)
bartlett_test(x, g, ...) ## Default S3 method: bartlett_test(x, g, ...)
x |
a numeric vector of data values, or a list of numeric data vectors representing the respective samples, or fitted linear model objects (inheriting from class "lm"). |
g |
a vector or factor object giving the group for the corresponding elements of x. Ignored if x is a list. |
... |
further arguments to be passed to or from methods. |
x
must be a numeric data vector, and g
must be a vector or factor object of the same length as x
giving the group for the corresponding elements of x
.
A list with class "bartlett_htest"
containing the following
components:
statistic |
Bartlett's K-squared test statistic. |
parameter |
the degrees of freedom of the approximate chi-squared distribution of the test statistic. |
p.value |
the p-value of the test. |
conf.int |
a confidence interval for the mean appropriate to the specified alternative hypothesis. |
method |
the character string "Bartlett test of homogeneity of variances". |
data.name |
a character string giving the names of the data. |
vars |
the sample variances across groups (samples). |
n |
the number of observations per group (sample) |
In order to allow users to enjoy the functionality of bain with the familiar
stats-function bartlett.test
, we have had to make minor changes to the
function bartlett.test.default
. All rights to, and credit for, the
function bartlett.test.default
belong to the R Core Team, as indicated in the original license below.
We make no claims to copyright and incur no liability with regard to the
changes implemented in bartlett_test
.
This the original copyright notice by the R core team: File src/library/stats/R/bartlett_test.R Part of the R package, https://www.R-project.org
Copyright (C) 1995-2015 The R Core Team
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
A copy of the GNU General Public License is available at https://www.R-project.org/Licenses/
Bartlett, M. S. (1937). Properties of sufficiency and statistical tests. Proceedings of the Royal Society of London Series A 160, 268–282. DOI: 10.1098/rspa.1937.0109.
require(graphics) plot(count ~ spray, data = InsectSprays) bartlett_test(InsectSprays$count, InsectSprays$spray)
require(graphics) plot(count ~ spray, data = InsectSprays) bartlett_test(InsectSprays$count, InsectSprays$spray)
The BF
function can be used for hypothesis testing and
model selection using the Bayes factor. By default exploratory hypothesis tests are
performed of whether each model parameter equals zero, is negative, or is
positive. Confirmatory hypothesis tests can be executed by specifying hypotheses with
equality and/or order constraints on the parameters of interest. Depending on the
class of the fitted model different Bayes factors are used as described in the output.
## Default S3 method: BF( x, hypothesis = NULL, prior.hyp.explo = NULL, prior.hyp.conf = NULL, prior.hyp = NULL, complement = TRUE, log = FALSE, cov.prob = 0.95, Sigma, n, ... ) ## S3 method for class 'lm' BF( x, hypothesis = NULL, prior.hyp.explo = NULL, prior.hyp.conf = NULL, prior.hyp = NULL, complement = TRUE, log = FALSE, cov.prob = 0.95, BF.type = NULL, iter = 10000, ... ) ## S3 method for class 'rma.uni' BF( x, hypothesis = NULL, prior.hyp.explo = NULL, prior.hyp.conf = NULL, prior.hyp = NULL, complement = TRUE, log = FALSE, cov.prob = 0.95, BF.type, iter = 20000, ... ) ## S3 method for class 't_test' BF( x, hypothesis = NULL, prior.hyp.explo = NULL, prior.hyp.conf = NULL, prior.hyp = NULL, complement = TRUE, log = FALSE, cov.prob = 0.95, BF.type = NULL, iter = 1e+06, ... )
## Default S3 method: BF( x, hypothesis = NULL, prior.hyp.explo = NULL, prior.hyp.conf = NULL, prior.hyp = NULL, complement = TRUE, log = FALSE, cov.prob = 0.95, Sigma, n, ... ) ## S3 method for class 'lm' BF( x, hypothesis = NULL, prior.hyp.explo = NULL, prior.hyp.conf = NULL, prior.hyp = NULL, complement = TRUE, log = FALSE, cov.prob = 0.95, BF.type = NULL, iter = 10000, ... ) ## S3 method for class 'rma.uni' BF( x, hypothesis = NULL, prior.hyp.explo = NULL, prior.hyp.conf = NULL, prior.hyp = NULL, complement = TRUE, log = FALSE, cov.prob = 0.95, BF.type, iter = 20000, ... ) ## S3 method for class 't_test' BF( x, hypothesis = NULL, prior.hyp.explo = NULL, prior.hyp.conf = NULL, prior.hyp = NULL, complement = TRUE, log = FALSE, cov.prob = 0.95, BF.type = NULL, iter = 1e+06, ... )
x |
An R object containing the outcome of a statistical analysis.
An R object containing the outcome of a statistical analysis. Currently, the
following objects can be processed: t_test(), bartlett_test(), lm(), aov(),
manova(), cor_test(), lmer() (only for testing random intercep variances),
glm(), coxph(), survreg(), polr(), zeroinfl(), rma(), ergm(), bergm(), or named
vector objects. In the case |
hypothesis |
A character string containing the constrained (informative) hypotheses to
evaluate in a confirmatory test. The default is NULL, which will result in standard exploratory testing
under the model |
prior.hyp.explo |
The prior probabilities of the hypotheses in the exploratory tests. Except for
objects of class |
prior.hyp.conf |
The prior probabilities of the constrained hypotheses in the confirmatory test. |
prior.hyp |
Deprecated. Please use the argument |
complement |
a logical specifying whether the complement should be added
to the tested hypothesis under |
log |
a logical specifying whether the Bayes factors should be computed on a log scale.
Default is |
cov.prob |
coverage probability of the Bayesian credibility interval in the |
Sigma |
An approximate posterior covariance matrix (e.g,. error covariance
matrix) of the parameters of interest. This argument is only required when |
n |
The (effective) sample size that was used to acquire the estimates in the named vector
|
... |
Parameters passed to and from other functions. |
BF.type |
For certain object classes of |
iter |
Number of iterations that are used to compute the Monte Carlo estimates
(only used for certain hypothesis tests of class |
The function requires a fitted modeling object. Current analyses
that are supported: t_test
,
bartlett_test
,
aov
, manova
,
lm
, mlm
,
glm
, hetcor
,
lmer
, coxph
,
survreg
, ergm
,
bergm
,
zeroinfl
, rma
and polr
.
For testing parameters from the results of t_test(), lm(), aov(),
manova(), and bartlett_test(), hypothesis testing is done using
adjusted fractional Bayes factors are computed (using minimal fractions).
For testing measures of association (e.g., correlations) via cor_test()
,
Bayes factors are computed using joint uniform priors under the correlation
matrices. For testing intraclass correlations (random intercept variances) via
lmer()
, Bayes factors are computed using uniform priors for the intraclass
correlations. For all other tests, approximate adjusted fractional Bayes factors
(with minimal fractions) are computed using Gaussian approximations, similar as
a classical Wald test.
The output is an object of class BF
. The object has elements:
BFtu_exploratory
: The Bayes factors of the constrained hypotheses against
the unconstrained hypothesis in the exploratory test.
BFtu_main
(only for aov
objects with predictors of class factor
):
The Bayes factors of a constrained model where all levels of a factor
are assumed
to have the same effect on the outcome variable versus an unconstrained (full) model with
no constraints.
BFtu_interaction
(only for aov
objects with interaction effects with
predictors of class factor
): The Bayes factors of a constrained model where the effect
of the dummy variables corresponding to an interaction effects are assumed to be zero versus
an unconstrained (full) model with no constraints.
PHP_exploratory:
The posterior probabilities of the constrained hypotheses
in the exploratory test.
PHP_main
(only for aov
objects with predictors of class factor
):
The posterior probabilities a constrained model where all levels of a factor
are assumed
to have the same effect on the outcome variable versus an unconstrained (full) model with
no constraints.
PHP_interaction
(only for aov
objects with interaction effects with
predictors of class factor
): The posterior probabilities of a constrained model where the
effect of the dummy variables corresponding to an interaction effects are assumed to be zero versus
an unconstrained (full) model with no constraints.
BFtu_confirmatory
: The Bayes factors of the constrained hypotheses against
the unconstrained hypothesis in the confirmatory test using the hypothesis
argument.
PHP_confirmatory
: The posterior probabilities of the constrained hypotheses
in the confirmatory test using the hypothesis
argument.
BFmatrix_confirmatory
: The evidence matrix which contains the Bayes factors
between all possible pairs of hypotheses in the confirmatory test.
BFtable_confirmatory
: The Specification table
(output when printing the
summary
of a BF
for a confirmatory test) which contains the different
elements of the extended Savage Dickey density ratio where
The first column 'complex=
' quantifies the relative complexity of the
equality constraints of a hypothesis (the prior density at the equality constraints in the
extended Savage Dickey density ratio).
The second column 'complex>
' quantifies the relative complexity of the
order constraints of a hypothesis (the prior probability of the order constraints in the extended
Savage Dickey density ratio).
The third column 'fit=
' quantifies the relative fit of the equality
constraints of a hypothesis (the posterior density at the equality constraints in the extended
Savage Dickey density ratio).
The fourth column 'fit>
' quantifies the relative fit of the order
constraints of a hypothesis (the posterior probability of the order constraints in the extended
Savage Dickey density ratio)
The fifth column 'BF=
' contains the Bayes factor of the equality constraints
against the unconstrained hypothesis.
The sixth column 'BF>
' contains the Bayes factor of the order constraints
against the unconstrained hypothesis.
The seventh column 'BF
' contains the Bayes factor of the constrained hypothesis
against the unconstrained hypothesis.
The eighth column 'PHP
' contains the posterior probabilities of the hypotheses.
prior.hyp.explo
: The prior probabilities of the constrained hypotheses in the exploratory tests.
prior.hyp.conf
: The prior probabilities of the constrained hypotheses in the confirmatory test.
hypotheses
: The tested constrained hypotheses in a confirmatory test.
estimates
: Descriptives of unconstrained estimates based on flat priors (also for rma.uni
objects for
Bayesian meta-analyses).
model
: The input model x
.
bayesfactor
: The type of Bayes factor that is used for this model.
parameter
: The type of parameter that is tested.
log
: logical
whether the Bayes factors were reported on a log scale.
fraction_number_groupIDs
(only for objects of class lm
): The number of
'group identifiers' that were identified based on the number of unique combinations of level
s
of predictor variables of class factor
in the data. These group identifiers are used to automatically
specify the minimal fractions that are used to compute (adjusted) fractional Bayes factors.
fraction_groupID_observations
(only for objects of class lm
): A vector that
specifies to which 'group identifier' an observation belongs. The group identifiers are constructed
based on the unique combination of the levels
based on the predictor variables of class factor
of the observations.
call
: The call of the BF
function.
BF(default)
: S3 method for a named vector 'x'
BF(lm)
: S3 method for an object of class 'lm'
BF(rma.uni)
: BF S3 method for an object of class 'rma.uni'
BF(t_test)
: BF S3 method for an object of class 't_test'
Mulder, Williams, Gu, Tomarken, Böing-Messing, Olsson-Collentine, Meyerink, Menke, Fox, Rosseel, Wagenmakers, Hoijtink, and van Lissa (2021). BFpack: Flexible Bayes Factor Testing of Scientific Theories in R. Journal of Statistical Software, 100. <https://doi.org/10.18637/jss.v100.i18>
Mulder and Xin (2022). Bayesian Testing of Scientific Expectations under Multivariate Normal Linear Models. <https://doi.org/10.1080/00273171.2021.1904809>
Mulder and Gelissen (2021). Bayes factor testing of equality and order constraints on measures of association in social research. Journal of Applied Statistics, 50. <https://doi.org/10.1080/02664763.2021.1992360>
Mulder and Fox (2019). Bayes Factor Testing of Multiple Intraclass Correlations. Bayesian Analysis, 14. <http://doi.org/10.1214/18-BA1115>
Hoijtink, Mulder, van Lissa, and Gu (2018). A tutorial on testing hypotheses using the Bayes factor. Psychological Methods, 24(5), 539–556. <http://doi.org/10.1037/met0000201>
Boeing-Messing, van Assen, Hofman, Hoijtink, and Mulder (2017). Bayesian evaluation of constrained hypotheses on variances of multiple independent groups. Psycholological Methods, 22(2), 262-287. <https://doi.org/10.1037/met0000116>
van Aert and Mulder (2021). Bayesian hypothesis testing and estimation under the marginalized random-effects meta-analysis model. Psychonomic Bulletin and Review, 29, 55–69. <https://doi.org/10.3758/s13423-021-01918-9>
# EXAMPLE 1. One-sample t test ttest1 <- t_test(therapeutic, mu = 5) print(ttest1) # confirmatory Bayesian one sample t test BF1 <- BF(ttest1, hypothesis = "mu = 5") summary(BF1) # exploratory Bayesian one sample t test BF(ttest1) # EXAMPLE 2. ANOVA aov1 <- aov(price ~ anchor * motivation,data = tvprices) BF1 <- BF(aov1, hypothesis = "anchorrounded = motivationlow; anchorrounded < motivationlow") summary(BF1) # EXAMPLE 3. linear regression lm1 <- lm(mpg ~ cyl + hp + wt, data = mtcars) BF(lm1, hypothesis = "wt < cyl < hp = 0") # EXAMPLE 4. Logistic regression fit <- glm(sent ~ ztrust + zfWHR + zAfro + glasses + attract + maturity + tattoos, family = binomial(), data = wilson) BF1 <- BF(fit, hypothesis = "ztrust > zfWHR > 0; ztrust > 0 & zfWHR = 0") summary(BF1) # EXAMPLE 5. Correlation analysis set.seed(123) cor1 <- cor_test(memory[1:20,c(1,2,6)]) BF1 <- BF(cor1) summary(BF1) BF2 <- BF(cor1, hypothesis = "Rat_with_Im > Rat_with_Del > 0; Rat_with_Im = Rat_with_Del = 0") summary(BF2) # correlations can also be computed between continuous/ordinal variables memory_test <- memory[1:20,c(1,2,6)] memory_test[,3] <- as.ordered(memory_test[,3]) cor2 <- cor_test(memory_test) BF(cor2) # EXAMPLE 6. Bayes factor testing on a named vector # A Poisson regression model is used to illustrate the computation # of Bayes factors with a named vector as input poisson1 <- glm(formula = breaks ~ wool + tension, data = datasets::warpbreaks, family = poisson) # extract estimates, error covariance matrix, and sample size: estimates <- poisson1$coefficients covmatrix <- vcov(poisson1) samplesize <- nobs(poisson1) # compute Bayes factors on equal/order constrained hypotheses on coefficients BF1 <- BF(estimates, Sigma = covmatrix, n = samplesize, hypothesis = "woolB > tensionM > tensionH; woolB = tensionM = tensionH") summary(BF1)
# EXAMPLE 1. One-sample t test ttest1 <- t_test(therapeutic, mu = 5) print(ttest1) # confirmatory Bayesian one sample t test BF1 <- BF(ttest1, hypothesis = "mu = 5") summary(BF1) # exploratory Bayesian one sample t test BF(ttest1) # EXAMPLE 2. ANOVA aov1 <- aov(price ~ anchor * motivation,data = tvprices) BF1 <- BF(aov1, hypothesis = "anchorrounded = motivationlow; anchorrounded < motivationlow") summary(BF1) # EXAMPLE 3. linear regression lm1 <- lm(mpg ~ cyl + hp + wt, data = mtcars) BF(lm1, hypothesis = "wt < cyl < hp = 0") # EXAMPLE 4. Logistic regression fit <- glm(sent ~ ztrust + zfWHR + zAfro + glasses + attract + maturity + tattoos, family = binomial(), data = wilson) BF1 <- BF(fit, hypothesis = "ztrust > zfWHR > 0; ztrust > 0 & zfWHR = 0") summary(BF1) # EXAMPLE 5. Correlation analysis set.seed(123) cor1 <- cor_test(memory[1:20,c(1,2,6)]) BF1 <- BF(cor1) summary(BF1) BF2 <- BF(cor1, hypothesis = "Rat_with_Im > Rat_with_Del > 0; Rat_with_Im = Rat_with_Del = 0") summary(BF2) # correlations can also be computed between continuous/ordinal variables memory_test <- memory[1:20,c(1,2,6)] memory_test[,3] <- as.ordered(memory_test[,3]) cor2 <- cor_test(memory_test) BF(cor2) # EXAMPLE 6. Bayes factor testing on a named vector # A Poisson regression model is used to illustrate the computation # of Bayes factors with a named vector as input poisson1 <- glm(formula = breaks ~ wool + tension, data = datasets::warpbreaks, family = poisson) # extract estimates, error covariance matrix, and sample size: estimates <- poisson1$coefficients covmatrix <- vcov(poisson1) samplesize <- nobs(poisson1) # compute Bayes factors on equal/order constrained hypotheses on coefficients BF1 <- BF(estimates, Sigma = covmatrix, n = samplesize, hypothesis = "woolB > tensionM > tensionH; woolB = tensionM = tensionH") summary(BF1)
Estimate the unconstrained posterior for the correlations using a joint uniform prior (Mulder and Gelissen, 2023) or a marginally uniform prior (Barnard et al., 2000, Mulder, 2016).
cor_test( ..., formula = NULL, iter = 5000, burnin = 3000, nugget.scale = 0.995, prior.cor = "joint.unif" )
cor_test( ..., formula = NULL, iter = 5000, burnin = 3000, nugget.scale = 0.995, prior.cor = "joint.unif" )
... |
matrices (or data frames) of dimensions n (observations) by p (variables) for different groups (in case of multiple matrices or data frames). |
formula |
an object of class |
iter |
number of iterations from posterior (default is 5000). |
burnin |
number of iterations for burnin (default is 3000). |
nugget.scale |
a scalar to avoid computational issues due to posterior draws for the corralations
too close to 1 in absolute value. Posterior draws for the correlations are multiplied with this nugget.scale.
So |
prior.cor |
setting this argument to |
list of class cor_test
:
meanF
posterior means of Fisher transform correlations
covmF
posterior covariance matrix of Fisher transformed correlations
correstimates
posterior estimates of correlation coefficients
corrdraws
list of posterior draws of correlation matrices per group
corrnames
names of all correlations
Mulder, J., & Gelissen, J. P. (2023). Bayes factor testing of equality and order constraints on measures of association in social research. Journal of Applied Statistics, 50(2), 315-351. <https://doi.org/10.1080/02664763.2021.1992360>
Mulder, J. (2016). Bayes factors for testing order-constrained hypotheses on correlations. Journal of Mathematical Psychology, 72, 104-115. <https://doi.org/10.1016/j.jmp.2014.09.004>
Barnard, J., McCulloch, R., & Meng, X. L. (2000). Modeling covariance matrices in terms of standard deviations and correlations, with application to shrinkage. Statistica Sinica, 1281-1311. <https://www.jstor.org/stable/24306780>
Joe. Generating random correlation matrices based on partial correlations, Journal of Multivariate Analysis, 97(10), 2177-2189. <https://doi.org/10.1016/j.jmva.2005.05.010>
# Bayesian correlation analysis of the 6 variables in 'memory' object # we consider a correlation analysis of the first three variable of the memory data. fit <- cor_test(BFpack::memory[,1:3]) # Bayesian correlation of variables in memory object in BFpack while controlling # for the Cat variable fit <- cor_test(BFpack::memory[,c(1:4)],formula = ~ Cat) # Example of Bayesian estimation of polyserial correlations memory_example <- memory[,c("Im","Rat")] memory_example$Rat <- as.ordered(memory_example$Rat) fit <- cor_test(memory_example) # Bayesian correlation analysis of first three variables in memory data # for two different groups HC <- subset(BFpack::memory[,c(1:3,7)], Group == "HC")[,-4] SZ <- subset(BFpack::memory[,c(1:3,7)], Group == "SZ")[,-4] fit <- cor_test(HC,SZ)
# Bayesian correlation analysis of the 6 variables in 'memory' object # we consider a correlation analysis of the first three variable of the memory data. fit <- cor_test(BFpack::memory[,1:3]) # Bayesian correlation of variables in memory object in BFpack while controlling # for the Cat variable fit <- cor_test(BFpack::memory[,c(1:4)],formula = ~ Cat) # Example of Bayesian estimation of polyserial correlations memory_example <- memory[,c("Im","Rat")] memory_example$Rat <- as.ordered(memory_example$Rat) fit <- cor_test(memory_example) # Bayesian correlation analysis of first three variables in memory data # for two different groups HC <- subset(BFpack::memory[,c(1:3,7)], Group == "HC")[,-4] SZ <- subset(BFpack::memory[,c(1:3,7)], Group == "SZ")[,-4] fit <- cor_test(HC,SZ)
Approximated degrees of freedom and approximated scale of the Fisher transformed correlations depending on the dimension of the vector of dependent variables P based on a joint uniform prior.
data(Fcor)
data(Fcor)
A data.frame with 3 columns.
nu | numeric |
Approximated degrees of freedom |
sigma | numeric |
Approximated scale |
P | integer |
Dimension of vector of dependent variables |
fMRI data assessing relation between individual differences in the ability to recognize faces and cars and thickness of the superficial, middle, and deep layers of the fusiform face area, as assessed by high-resolution fMRI recognition (Williams et al, 2019, under review)
data(fmri)
data(fmri)
A data.frame with 13 rows and 6 columns.
Subject | numeric |
Particicpant ID number |
Face | numeric |
Standardized score on face recognition battery |
Vehicle | numeric |
Standardized score on vehicle recognition battery |
Superficial | numeric |
Depth in mm of superficial layer of FFA |
Middle | numeric |
Depth in mm of middle layer of FFA |
Bform | numeric |
Depth in mm of deep layer of FFA |
McGuigin, R.W., Newton, A.T., Tamber-Rosenau, B., Tomarken, A.J, & Gauthier, I. (under review). Thickness of deep layers in the fusiform face area predicts face recognition.
Data set from study assessing differences between schizophrenic patients and healthy control participants in patterns of correlations among 6 verbal memory tasks (Ichinose et al., 2019).
Im | numeric |
Percent correct on immediate recall of 3 word lists |
Del | numeric |
Percent correct on delayed recall of 3 word lists |
Wmn | numeric |
Number correct on letter-number span test of auditory working memory |
Cat | numeric |
Number correct on category fluency task |
Fas | numeric |
Number correct on letter fluency task |
Rat | numeric |
Number correct on remote associates task |
Group | factor |
Participant Group (HC = Healthy Control; SZ = Schizophrenia) |
data(memory)
data(memory)
A data.frame with 40 rows and 8 columns.
Ichinose, M.C., Han, G., Polyn, S., Park, S., & Tomarken, A.J. (2019). Verbal memory performance discordance in schizophrenia: A reflection of cognitive dysconnectivity. Unpublished manuscript.
First step to performs a Bayesian multivariate one sample Student t test using the
(adjusted) fractional Bayes factor using the BF()
function.
mvt_test(X, Y, null = NULL, paired = FALSE, ...)
mvt_test(X, Y, null = NULL, paired = FALSE, ...)
X |
a data matrix with the variables in the columns. |
Y |
an optional data matrix with the variables in the columns. |
null |
a vector of the null values of the variables. |
paired |
a logical indicating whether you want a multivariate paired t-test. |
... |
further arguments to be passed to or from methods. |
X
must be a data matrix and null
must be a vector of the assumed null values of the variables.
An object that can be applied to the BF()
.
Mulder, J. and Gu, X. (2023). Bayesian Testing of Scientific Expectations under Multivariate Normal Linear Models. Multivariate Behavioral Research, 57, 767-783. DOI: 10.1080/00273171.2021.1904809.
mvt_fmri <- mvt_test(fmri[,1:2],null = c(0,0)) BF(mvt_fmri) # the same test can be executed via the lm() function intercept <- rep(1,nrow(fmri)) lm1 <- lm(cbind(Face,Vehicle) ~ -1 + intercept, data=fmri) BF(lm1,hypothesis="intercept_on_Face=intercept_on_Vehicle=0")
mvt_fmri <- mvt_test(fmri[,1:2],null = c(0,0)) BF(mvt_fmri) # the same test can be executed via the lm() function intercept <- rep(1,nrow(fmri)) lm1 <- lm(cbind(Face,Vehicle) ~ -1 + intercept, data=fmri) BF(lm1,hypothesis="intercept_on_Face=intercept_on_Vehicle=0")
A time-ordered sequence of 247 communication messages between 25 actors.
data(relevents)
data(relevents)
dataframe (247 rows, 3 columns)
relevents$time | numeric |
Time of the e-mail message, in seconds since onset of the observation |
relevents$sender | integer |
ID of the sender, corresponding to the employee IDs in the actors dataframe |
relevents$receiver | integer |
ID of the receiver |
The related data files 'actors', 'same_location', 'same_culture' contain information on the actors and three event statistics respectively.
A matrix coding whether senders of events (in the rows) and receivers of events (in the column) have the background culture. Related to the 'events' data object, that contains a relational event sequence, and the 'actors' object, that contains information on the 25 actors involved in the relational event sequence.
data(same_culture)
data(same_culture)
dataframe (25 rows, 4 columns)
same_culture | integer |
Event statistic. Matrix with senders in the rows and receivers in the columns. The event statistic is 1 if sender and receiver have the same culture and 0 otherwise. |
A matrix coding whether senders of events (in the rows) and receivers of events (in the column) have the same location. Related to the 'events' data object, that contains a relational event sequence, and the 'actors' object, that contains information on the 25 actors involved in the relational event sequence.
data(same_location)
data(same_location)
dataframe (25 rows, 4 columns)
same_location | integer |
Event statistic. Matrix with senders in the rows and receivers in the columns. The event statistic is 1 if sender and receiver have the same location and 0 otherwise. |
Data from an experimental study, using the Wason selection task (Wason 1968)
to examine whether humans have cognitive adaptations for detecting violations
of rules in multiple moral domains. Moral domains are operationalized in
terms of the five domains of the Moral Foundations Questionnaire
(Graham et al. 2011).
These data were simulated using the
R-package synthpop
, based on the characteristics of the original data.
data(sivan)
data(sivan)
A data.frame with 887 rows and 12 columns.
sex | factor |
Participant sex |
age | integer |
Participant age |
nationality | factor |
Participant nationality |
politics | integer |
How would you define your political opinions? Likert type scale, from 1 (Liberal) to 6 (Conservative) |
WasonOrder | factor |
Was the Wason task presented before, or after the MFQ? |
Harm | numeric |
MFQ harm domain. |
Fairness | numeric |
MFQ fairness domain. |
Loyalty | numeric |
MFQ loyalty domain. |
Purity | numeric |
MFQ purity domain. |
Tasktype | ordered |
How was the Wason task framed? |
GotRight | factor |
Did the participant give the correct answer to the Wason task? |
Sivan, J., Curry, O. S., & Van Lissa, C. J. (2018). Excavating the Foundations: Cognitive Adaptations for Multiple Moral Domains. Evolutionary Psychological Science, 4(4), 408–419. doi:10.1007/s40806-018-0154-8
correct | integer |
How many correct answers are from each practitioner) |
data(therapeutic)
data(therapeutic)
A data.frame with 22 rows and 1 column.
Howell, D. (2012). Statistical methods for psychology (8th ed.). Belmont, CA: Cengage Learning.
A stratified sample was drawn by country and school to obtain a balanced sample of p = 15 grade-4 students per school for each of four countries (The Netherlands (NL), Croatia (HR), Germany (DE), and Denmark (DK)) and two measurement occasions (2011, 2015). Achievement scores (first plausible value) of overall mathematics were considered. Performances of fourth and eight graders from more than 50 participating countries around the world can be found at (https://www.iea.nl/timss) The TIMSS achievement scale is centered at 500 and the standard deviation is equal to 100 scale score points. The TIMSS data set has a three-level structure, where students are nested within classrooms/schools, and the classrooms/schools are nested within countries. Only one classroom was sampled per school. Changes in the mathematics achievement can be investigated by examining the grouping of students in schools across countries. Changes in country-specific intraclass correlation coefficient from 2011 to 2015, representing heterogeneity in mathematic achievements within and between schools across years, can be tested. When detecting a decrease in average performance together with an increase of the intraclass correlation, a subset of schools performed worse. For a constant intraclass correlation across years the drop in performance applied to the entire population of schools. For different countries, changes in the intraclass correlation across years can be tested concurrently to examine also differences across countries.
data(timssICC)
data(timssICC)
A data.frame with 16770 rows and 15 columns.
math | numeric |
math score child |
groupNL11 | numeric |
Indicator for child from NL in 2011 |
groupNL15 | numeric |
Indicator for child from NL in 2015 |
groupHR11 | numeric |
Indicator for child from HR in 2011 |
groupHR15 | numeric |
Indicator for child from HR in 2015 |
groupDE11 | numeric |
Indicator for child from DE in 2011 |
groupDE15 | numeric |
Indicator for child from DE in 2015 |
groupDR11 | numeric |
Indicator for child from DK in 2011 |
groupDR15 | numeric |
Indicator for child from DK in 2015 |
gender | numeric |
Female=0,Male=1 |
weight | numeric |
Child sampling weight |
yeargender | numeric |
Interaction for occassion and gender |
lln | numeric |
total number of children in school-class |
groupschool | factor |
Nested indicator for school in country |
schoolID | factor |
Unique indicator for school |
Mulder, J. & Fox, J.-P. (2019). Bayes factor testing of multiple intraclass correlations. Bayesian Analysis. 14, 2, p. 521-552.
Data from an experimental study where participants have to guess the price of a plasma tv. There were two experimental conditions. These data were simulated using the sufficient statistics from Janiszewski & Uy (2008).
data(tvprices)
data(tvprices)
A data.frame with 59 rows and 3 columns.
price | numeric |
Participant z-scores of price |
anchor | factor |
Participant anchor |
motivation | factor |
motivation to change |
Janiszewski, C., & Uy, D. (2008). Precision of the anchor influences the amount of adjustment. Psychological Science, 19(2), 121–127. doi:10.1111/j.1467-9280.2008.02057.x
Data from a correlational study in which the correlation between ratings of
facial trustworthiness of inmates was correlated with whether they had
received the death penalty or not (wilson and Rule, 2015). These data were
simulated using the R-package synthpop
, based on the characteristics
of the original data.
data(wilson)
data(wilson)
A data.frame with 742 rows and 13 columns.
stim | integer |
Stimulus Number |
sent | integer |
Sentence: 1 = Death, 0 = Life |
race | integer |
Race: 1 = White, -1 = Black |
glasses | integer |
Glasses: 1 = Yes, 0 = No |
tattoos | integer |
Tattoos: 1 = Yes, 0 = No |
ztrust | numeric |
Trustworthiness |
trust_2nd | numeric |
Trustworthiness ratings with 2nd control group; Death targets are same as in primary analysis, Life targets are different. |
afro | numeric |
raw Afrocentricity ratings. |
zAfro | numeric |
Afrocentricity ratings normalized within target race. Analyses in paper were done with this variable. |
attract | numeric |
Attractiveness |
fWHR | numeric |
facial width-to-height |
afWHR | numeric |
fWHR normalized within target race. Analyses in paper were done with this variable |
maturity | numeric |
Maturity |
Wilson, J. P., & Rule, N. O. (2015). Facial Trustworthiness Predicts Extreme Criminal-Sentencing Outcomes. Psychological Science, 26(8), 1325–1331. doi: 10.1177/0956797615590992