Last data update: 2014.03.03

R: Bayes factor of the two models
Bayes.factorR Documentation

Bayes factor of the two models

Description

Compares two models by evaluating their Bayes factor

Usage

Bayes.factor(model1, model2, inter=TRUE)

Arguments

model1

object of the class model "Bayesthresh"

model2

object of the class model "Bayesthresh"

inter

If TRUE, print to scale for interpretation of the Bayes factor

Details

At each step during the Markov chains, the marginal likelihood for a model is evaluated, conditioning on actual values for the parameters in that step. Bayes factor is then estimated by the ratios of the arithmetic means of marginal likelihoods from both models. Details of the implementation can be found in Sorensen and Gianola (2004). For a discussion of the possible interpretation of Bayes factors, see Jeffreys(1961)

References

SORENSEN, D.; GIANOLA, D. Likelihood, bayesian and MCMC methods in quantitative genetics. United States of America: Springer, 2004. 740 p.

JEFFREYS, H. Theory of probability. Oxford: Claredon Press, 1961. 470 p.

Examples

data(sensory)

Consumer <- factor(sensory$consumer)
Sacarose <- factor(sensory$sacarose)

# Not run

#### Model 1

# Model with Gaussian link

dex1 <- Bayesthresh(flavor ~ (1|Consumer) + Sacarose, burn = 0, jump = 1,
        ef.iter = 10, data=sensory) 
summary(dex1)

#### Model 2

# Model with t-Student link

dex2 <- Bayesthresh(flavor ~ (1|Consumer) + Sacarose, burn = 0, jump = 1,
        ef.iter = 10, algor=list(algorithm="NC", link="t"),data=sensory) 
summary(dex2)

Bayes.factor(dex1,dex2)

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(Bayesthresh)
Loading required package: lme4
Loading required package: Matrix
Loading required package: MASS
Loading required package: VGAM
Loading required package: stats4
Loading required package: splines
Loading required package: mvtnorm
Loading required package: matrixcalc
Loading required package: coda

Attaching package: 'coda'

The following object is masked from 'package:VGAM':

    nvar

> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Bayesthresh/Bayes.factor.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Bayes.factor
> ### Title: Bayes factor of the two models
> ### Aliases: Bayes.factor
> 
> ### ** Examples
> 
> data(sensory)
> 
> Consumer <- factor(sensory$consumer)
> Sacarose <- factor(sensory$sacarose)
> 
> # Not run
> 
> #### Model 1
> 
> # Model with Gaussian link
> 
> dex1 <- Bayesthresh(flavor ~ (1|Consumer) + Sacarose, burn = 0, jump = 1,
+         ef.iter = 10, data=sensory) 
> summary(dex1)
Threshold model with algorithm NC and link Gaussian 
Formula: flavor ~ (1 | Consumer) + Sacarose 

Deviance: 327.5067 

Marginal Log-likelihood:
  Post. mean Post.std.dev
   -163.7533     7.456134

Random effects:
          Post.variance Post.std.dev
Consumer      0.1758407   0.05570589
Residuals     0.3958872   0.04558618

Fixed effects:
              Estimate  Std. Dev
(Intercept)  0.8252476 0.1889901
Sacarose40  -0.1184004 0.1567156
Sacarose50  -0.1526394 0.1234530

Iteraction Control:
Burn = 0 , Jump = 1 , Iteraction = 10
Time elapsed 0.028 seconds 
> 
> #### Model 2
> 
> # Model with t-Student link
> 
> dex2 <- Bayesthresh(flavor ~ (1|Consumer) + Sacarose, burn = 0, jump = 1,
+         ef.iter = 10, algor=list(algorithm="NC", link="t"),data=sensory) 
> summary(dex2)
Threshold model with algorithm NC and link t 
Formula: flavor ~ (1 | Consumer) + Sacarose 

Deviance: 329.0357 

Marginal Log-likelihood:
  Post. mean Post.std.dev
   -164.5179     4.749043

Random effects:
          Post.variance Post.std.dev
Consumer      0.2022182   0.08191428
Residuals     0.4227307   0.06547137

Fixed effects:
              Estimate  Std. Dev
(Intercept)  1.0036404 0.3024412
Sacarose40  -0.1578893 0.1212921
Sacarose50  -0.2290554 0.1899861

Iteraction Control:
Burn = 0 , Jump = 1 , Iteraction = 10
Time elapsed 0.035 seconds 
> 
> Bayes.factor(dex1,dex2)

Bayes factor for comparison two models

 
Model 1: flavor ~ (1 | Consumer) + Sacarose
Model 2: flavor ~ (1 | Consumer) + Sacarose 

 
              Bayes factor
model1/model2     1.004669

 Scale for interpretation of the Bayes factor 
-------------------------------------------- 
B_ij                Evidence in favor of M_1 
-------------------------------------------- 
  <1                 negative (favor of M_2) 
1 to 3                             doubtfull 
3 to 10                          substantial 
10 to 30                              strong 
30 to 100                        very strong 
 >100                               decisive 
-------------------------------------------- 
Jeffreys(1961) 
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>