lmBF: Function to compute Bayes factors for specific linear models

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

Description

This function computes Bayes factors, or samples from the posterior, of specific linear models (either ANOVA or regression).

Usage

1
2
3
4
  lmBF(formula, data, whichRandom = NULL,
    rscaleFixed = "medium", rscaleRandom = "nuisance",
    rscaleCont = "medium", posterior = FALSE,
    progress = options()$BFprogress, ...)

Arguments

formula

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

data

a data frame containing data for all factors in the formula

whichRandom

a character vector specifying which factors are random

rscaleFixed

prior scale for standardized, reduced fixed effects. A number of preset values can be given as strings; see Details.

rscaleRandom

prior scale for standardized random effects

rscaleCont

prior scale for standardized slopes. A number of preset values can be given as strings; see Details.

posterior

if TRUE, return samples from the posterior distribution instead of the Bayes factor

progress

if TRUE, show progress with a text progress bar

...

further arguments to be passed to or from methods.

Details

This function provides an interface for computing Bayes factors for specific linear models against the intercept-only null; other tests may be obtained by computing two models and dividing their Bayes factors. Specifics about the priors for regression models – and possible settings for rscaleCont – can be found in the help for regressionBF; likewise, details for ANOVA models – and settings for rscaleFixed and rscaleRandom – can be found in the help for anovaBF.

Currently, the function does not allow for general linear models, containing both continuous and categorical predcitors, but this support will be added in the future.

Value

If posterior is FALSE, an object of class BFBayesFactor, containing the computed model comparisons is returned. Otherwise, an object of class BFmcmc, containing MCMC samples from the posterior is returned.

Author(s)

Richard D. Morey (richarddmorey@gmail.com)

See Also

regressionBF and anovaBF for testing many regression or ANOVA models simultaneously.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## Puzzles data; see ?puzzles for details
data(puzzles)
## Bayes factor of full model against null
bfFull = lmBF(RT ~ shape + color + shape:color + ID, data = puzzles, whichRandom = "ID")

## Bayes factor of main effects only against null
bfMain = lmBF(RT ~ shape + color + ID, data = puzzles, whichRandom = "ID")

## Compare the main-effects only model to the full model
bfMain / bfFull

## sample from the posterior of the full model
samples = lmBF(RT ~ shape + color + shape:color + ID, data = puzzles, whichRandom = "ID", posterior = TRUE, iterations = 1000)

## Aother way to sample from the posterior of the full model
samples2 = posterior(bfFull, iterations = 1000)

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.
************
Bayes factor analysis
--------------
[1] shape + color + ID : 2.617024 <U+00B1>3.26%

Against denominator:
  RT ~ shape + color + shape:color + ID 
---
Bayes factor type: BFlinearModel, JZS

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