Learn R Programming

BayesFactor (version 0.9.12-4.7)

posterior: Sample from the posterior distribution of one of several models.

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

posterior(model, index, data, iterations, ...)

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

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

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

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

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

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

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

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

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

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

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

Value

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

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.

Examples

Run this code
## 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

Run the code above in your browser using DataLab