regressionBF: Function to compute Bayes factors for regression designs

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

This function simultaneously computes Bayes factors for groups of models in regression designs

Usage

1
2
3
  regressionBF(formula, data, whichModels = "all",
    progress = options()$BFprogress, rscaleCont = "medium",
    noSample = FALSE)

Arguments

formula

a formula containing all covariates to include in the analysis (see Examples)

data

a data frame containing data for all factors in the formula

whichModels

which set of models to compare; see Details

progress

if TRUE, show progress with a text progress bar

rscaleCont

prior scale on all standardized slopes

noSample

if TRUE, do not sample, instead returning NA.

Details

regressionBF computes Bayes factors to test the hypothesis that slopes are 0 against the alternative that all slopes are nonzero.

The vector of observations y is assumed to be distributed as

y ~ Normal(α 1 + Xβ, σ^2 I).

The joint prior on α,σ^2 is proportional to 1/σ^2, the prior on β is

β ~ Normal(0, N g σ^2(X'X)^{-1}).

where g ~ InverseGamma(1/2,r/2). See Liang et al. (2008) section 3 for details.

Possible values for whichModels are 'all', 'top', and 'bottom', where 'all' computes Bayes factors for all models, 'top' computes the Bayes factors for models that have one covariate missing from the full model, and 'bottom' computes the Bayes factors for all models containing a single covariate. Caution should be used when interpreting the results; when the results of 'top' testing is interpreted as a test of each covariate, the test is conditional on all other covariates being in the model (and likewise 'bottom' testing is conditional on no other covariates being in the model).

An option is included to prevent analyzing too many models at once: options('BFMaxModels'), which defaults to 50,000, is the maximum number of models that 'regressionBF' will analyze at once. This can be increased by increasing the option value.

For the rscaleCont argument, several named values are recongized: "medium", "wide", and "ultrawide", which correspond r scales of sqrt(2)/4, 1/2, and sqrt(2)/2, respectively. These values were chosen to yield consistent Bayes factors with anovaBF.

Value

An object of class BFBayesFactor, containing the computed model comparisons

Author(s)

Richard D. Morey (richarddmorey@gmail.com)

References

Liang, F. and Paulo, R. and Molina, G. and Clyde, M. A. and Berger, J. O. (2008). Mixtures of g-priors for Bayesian Variable Selection. Journal of the American Statistical Association, 103, pp. 410-423

Rouder, J. N. and Morey, R. D. (in press). Bayesian testing in regression. Multivariate Behavioral Research.

Zellner, A. and Siow, A., (1980) Posterior Odds Ratios for Selected Regression Hypotheses. In Bayesian Statistics: Proceedings of the First Interanational Meeting held in Valencia (Spain). Bernardo, J. M., Lindley, D. V., and Smith A. F. M. (eds), pp. 585-603. University of Valencia.

See Also

lmBF, for testing specific models, and anovaBF for the function similar to regressionBF for ANOVA models.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## See help(attitude) for details about the data set
data(attitude)

## Classical regression
summary(fm1 <- lm(rating ~ ., data = attitude))

## Compute Bayes factors for all regression models
output = regressionBF(rating ~ ., data = attitude, progress=FALSE)
head(output)
## Best model is 'complaints' only

## Compute all Bayes factors against the full model, and
## look again at best models
head(output / output[63])

Example output

Loading required package: coda
Loading required package: Matrix
************
Welcome to BayesFactor 0.9.12-4.2. If you have questions, please contact Richard Morey (richarddmorey@gmail.com).

Type BFManual() to open the manual.
************

Call:
lm(formula = rating ~ ., data = attitude)

Residuals:
     Min       1Q   Median       3Q      Max 
-10.9418  -4.3555   0.3158   5.5425  11.5990 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 10.78708   11.58926   0.931 0.361634    
complaints   0.61319    0.16098   3.809 0.000903 ***
privileges  -0.07305    0.13572  -0.538 0.595594    
learning     0.32033    0.16852   1.901 0.069925 .  
raises       0.08173    0.22148   0.369 0.715480    
critical     0.03838    0.14700   0.261 0.796334    
advance     -0.21706    0.17821  -1.218 0.235577    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 7.068 on 23 degrees of freedom
Multiple R-squared:  0.7326,	Adjusted R-squared:  0.6628 
F-statistic:  10.5 on 6 and 23 DF,  p-value: 1.24e-05

Bayes factor analysis
--------------
[1] complaints                      : 417938.6 <U+00B1>0.01%
[2] complaints + learning           : 207271.9 <U+00B1>0%
[3] complaints + learning + advance : 88041.54 <U+00B1>0%
[4] complaints + raises             : 77498.99 <U+00B1>0%
[5] complaints + privileges         : 75015.23 <U+00B1>0%
[6] complaints + advance            : 72759.76 <U+00B1>0%

Against denominator:
  Intercept only 
---
Bayes factor type: BFlinearModel, JZS

Bayes factor analysis
--------------
[1] complaints                      : 188.949  <U+00B1>0.01%
[2] complaints + learning           : 93.70711 <U+00B1>0%
[3] complaints + learning + advance : 39.80336 <U+00B1>0%
[4] complaints + raises             : 35.0371  <U+00B1>0%
[5] complaints + privileges         : 33.9142  <U+00B1>0%
[6] complaints + advance            : 32.89451 <U+00B1>0%

Against denominator:
  rating ~ complaints + privileges + learning + raises + critical + advance 
---
Bayes factor type: BFlinearModel, JZS

BayesFactor documentation built on May 2, 2019, 5:54 p.m.