Bf test r example

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.

Usage

## Default S3 method: BF( x, hypothesis = NULL, prior.hyp.explo = NULL, prior.hyp.conf = NULL, prior.hyp = NULL, complement = TRUE, log = FALSE, 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, BF.type = 2, iter = 10000, . ) ## 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, BF.type = 2, iter = 1e+06, . ) 

Arguments

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 x is a named vector, the arguments Sigma and n are also needed. See vignettes for elaborations.

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 x .

The prior probabilities of the hypotheses in the exploratory tests. Except for objects of class aov (for (M)ANOVA, etc.), this argument should be a vector with three elements reflecting the prior probability of a zero effect, a negative effect, and a positive effect, respectively. For objects of class aov , the argument should be a list where the first element should be a vector of length 3 specifying the prior probabilities of each parameter being zero, negative, or positive, the second element should be a vector of length 2 specifying the prior probabilities of a model where is no main effect for a factor and the full model, and the third element should be a vector of length 2 specifying the prior probabilities of a model where is no interaction effect (if present) for two factors and the full model. The default ( NULL ) specifies equal prior probabilities for each hypothesis per exploratory test.

The prior probabilities of the constrained hypotheses in the confirmatory test.

Deprecated. Please use the argument prior.hyp.conf .

a logical specifying whether the complement should be added to the tested hypothesis under hypothesis .

a logical specifying whether the Bayes factors should be computed on a log scale. Default is FALSE .

An approximate posterior covariance matrix (e.g,. error covariance matrix) of the parameters of interest. This argument is only required when x is a named vector.

The (effective) sample size that was used to acquire the estimates in the named vector x and the error covariance matrix Sigma . This argument is only required when x is a named vector.

Parameters passed to and from other functions.

An integer that specified the type of Bayes factor (or prior) that is used for the test. Currently, this argument is only used for models of class 'lm' and 't_test', where BF.type=2 implies an adjusted fractional Bayes factor with a 'fractional prior mean' at the null value (Mulder, 2014), and BF.type=1 implies a regular fractional Bayes factor (based on O'Hagan (1995)) with a 'fractional prior mean' at the MLE.

Number of iterations that are used to compute the Monte Carlo estimates (only used for certain hypotheses under multivariate models and when testing group variances).

Details

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.

Value

The output is an object of class BF . The object has elements: