Last data update: 2014.03.03

R: Compute Bayes Factors
computeBayesFactorsR Documentation

Compute Bayes Factors

Description

Computes pairwise Bayes factors for a set of macroevolutionary models sampled using BAMM, using MCMC simulation output.

Usage

computeBayesFactors(postdata, expectedNumberOfShifts, burnin = 0.1, ...)

Arguments

postdata

Filename for the MCMC output file from a BAMM run. Alternatively, a dataframe containing this information.

expectedNumberOfShifts

Expected number of shifts under the prior.

burnin

What fraction of samples to discard from postdata as burnin?

...

Additional arguments to computeBayesFactors.

Details

This function returns a matrix of pairwise Bayes factors, where the Bayes factor is the ratio of marginal likelihoods between two models M_i and M_j. Numerator models are given as rows, and denominator models as columns. Row names and column names give the number of shifts in the corresponding model. Suppose you have an output matrix with row and column names 0:3 (0, 1, 2, 3). Model 0 is a model with just a single process (starting at the root), and no among-lineage rate heterogeneity.

If computeBayesFactors gives a matrix mm, and mm[2,1] is 10.0, this implies Bayes factor evidence of 10 in favor of the 2nd row model (a model with 1 process; e.g., rownames(mm)[2]) over the first column model (a model with a single process).

This function will only compute Bayes factors between models which were actually sampled during simulation of the posterior. Hence, if a model has such low probability that it is never visited by BAMM during the simulation of the posterior, it will be impossible to estimate its posterior probability (and thus, you will get no Bayes factors involving this particular model). This is likely to change in the future with more robust methods for estimating posterior probabilities in the tails of the distribution.

Value

A matrix of pairwise Bayes factors between models.

Author(s)

Dan Rabosky

Examples

data(mcmc.whales)
computeBayesFactors(mcmc.whales, expectedNumberOfShifts = 1, burnin = 0.1)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(BAMMtools)
Loading required package: ape
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/BAMMtools/computeBayesFactors.Rd_%03d_medium.png", width=480, height=480)
> ### Name: computeBayesFactors
> ### Title: Compute Bayes Factors
> ### Aliases: computeBayesFactors
> ### Keywords: models
> 
> ### ** Examples
> 
> data(mcmc.whales)
> computeBayesFactors(mcmc.whales, expectedNumberOfShifts = 1, burnin = 0.1)
           0          1          2         3       4         5
0  1.0000000 0.05822785 0.09175532 0.2211538 0.43125  1.078125
1 17.1739130 1.00000000 1.57579787 3.7980769 7.40625 18.515625
2 10.8985507 0.63459916 1.00000000 2.4102564 4.70000 11.750000
3  4.5217391 0.26329114 0.41489362 1.0000000 1.95000  4.875000
4  2.3188406 0.13502110 0.21276596 0.5128205 1.00000  2.500000
5  0.9275362 0.05400844 0.08510638 0.2051282 0.40000  1.000000
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>