posterior-methods: Sample from the posterior distribution of one of several...

Description Usage Arguments Details Value Examples

Description

This function samples from the posterior distribution of a BFmodel, which can be obtained from a BFBayesFactor object. If there is more than one numerator in the BFBayesFactor object, the index argument can be passed to select one numerator.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
posterior(model, index, data, iterations, ...)

## S4 method for signature 'BFmodel,missing,data.frame,missing'
posterior(model, index, data,
  iterations, ...)

## S4 method for signature 'BFBayesFactor,missing,missing,missing'
posterior(model, index, data,
  iterations, ...)

## S4 method for signature 'BFBayesFactor,numeric,missing,numeric'
posterior(model, index, data,
  iterations, ...)

## S4 method for signature 'BFBayesFactor,missing,missing,numeric'
posterior(model,
  index = NULL, data, iterations, ...)

## S4 method for signature 'BFlinearModel,missing,data.frame,numeric'
posterior(model,
  index = NULL, data, iterations, ...)

## S4 method for signature 'BFindepSample,missing,data.frame,numeric'
posterior(model,
  index = NULL, data, iterations, ...)

## S4 method for signature 'BFcontingencyTable,missing,data.frame,numeric'
posterior(model,
  index = NULL, data, iterations, ...)

## S4 method for signature 'BFoneSample,missing,data.frame,numeric'
posterior(model,
  index = NULL, data, iterations, ...)

## S4 method for signature 'BFmetat,missing,data.frame,numeric'
posterior(model, index = NULL,
  data, iterations, ...)

## S4 method for signature 'BFproportion,missing,data.frame,numeric'
posterior(model,
  index = NULL, data, iterations, ...)

## S4 method for signature 'BFcorrelation,missing,data.frame,numeric'
posterior(model,
  index = NULL, data, iterations, ...)

Arguments

model

or set of models from which to sample

index

the index within the set of models giving the desired model

data

the data to be conditioned on

iterations

the number of iterations to sample

...

arguments passed to and from related methods

Details

The data argument is used internally, and will y not be needed by end-users.

Note that if there are fixed effects in the model, the reduced parameterzation used internally (see help for anovaBF) is unreduced. For a factor with two levels, the chain will contain two effect estimates that sum to 0.

Two useful arguments that can be passed to related methods are thin and columnFilter, currently implemented for methods using nWayAOV (models with more than one categorical covariate, or a mix of categorical and continuous covariates). thin, an integer, will keep only every thin iterations. The default is thin=1, which keeps all iterations. Argument columnFilter is either NULL (for no filtering) or a character vector of extended regular expressions (see regex help for details). Any column from an effect that matches one of the filters will not be saved.

Value

Returns an object containing samples from the posterior distribution of the specified model

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## Sample from the posteriors for two models
data(sleep)

bf = lmBF(extra ~ group + ID, data = sleep, whichRandom="ID", progress=FALSE)

## sample from the posterior of the numerator model
## data argument not needed - it is included in the Bayes factor object
chains = posterior(bf, iterations = 1000, progress = FALSE)

plot(chains)

## demonstrate column filtering by filtering out participant effects
data(puzzles)
bf = lmBF(RT ~ shape + color + shape:color + ID, data=puzzles)
chains = posterior(bf, iterations = 1000, progress = FALSE, columnFilter="^ID$")
colnames(chains) # Contains no participant effects

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.
************
 [1] "mu"                                 "shape-round"                       
 [3] "shape-square"                       "color-color"                       
 [5] "color-monochromatic"                "shape:color-round.&.color"         
 [7] "shape:color-round.&.monochromatic"  "shape:color-square.&.color"        
 [9] "shape:color-square.&.monochromatic" "sig2"                              
[11] "g_shape"                            "g_color"                           
[13] "g_ID"                               "g_shape:color"                     

BayesFactor documentation built on May 2, 2019, 7 a.m.