Hi all,
Attached are some data that I am trying to do a Bayes factor analysis on using brms.
Reproducible code is below. I set pretty reasonable priors for the fixed effects factors. I am testing the null hypothesis that the parameter for the factor dat is 0, against the alternative prior that the parameter for dat is Normal(0,1). After fitting the full and null models, i.e., models with and without dat as a fixed factor, I computed bayes factor using the function bayes_factor in brms 100 times, and each time I get a new number:
summary(bf_values)
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.05725 0.12663 0.19257 0.23821 0.30977 0.85361
So the BF in favor of the alternative is between 1 and 17! Once the models are fitted, why does the bayes factor vary so much?
dat.txt (16.2 KB)
# load data:
dat<-read.table("dat.txt",header=T)
library(brms)
#- Null: Effect of Dat = 0
#- Alternative: Normal(0,1) for all the fixed effects factors
priors_logrt_normal<-c(set_prior("normal(0,10)", class = "b"),
set_prior("normal(0,1)", class = "b",coef="dat"),
set_prior("normal(0,1)", class = "b",coef="adj"),
set_prior("normal(0,1)", class = "b",coef="int"),
set_prior("normal(0,1)", class = "sd"),
set_prior("normal(0,1)", class = "sigma"),
set_prior("lkj(2)", class = "cor"))
full1 <-brm(formula = log(region7) ~ dat + adj + int +
(1 +
dat + adj + int
| subj)+ (1 +
dat + adj + int
| item),
data = reading_time_nozeros,
family = gaussian(),
prior = priors_logrt_normal,
warmup = 1000,
iter = 2000,
chains = 4,
save_all_pars= TRUE,
control = list(adapt_delta = 0.99,max_treedepth=15))
## null model:
NULLpriors_logrt_normal<-c(set_prior("normal(0,10)", class = "b"),
set_prior("normal(0,1)", class = "b",coef="adj"),
set_prior("normal(0,1)", class = "b",coef="int"),
set_prior("normal(0,1)", class = "sd"),
set_prior("normal(0,1)", class = "sigma"),
set_prior("lkj(2)", class = "cor"))
null1 <- brm(formula = log(region7) ~ adj + int +
(1 + dat+ adj + int
| subj)+ (1 +
dat + adj + int
| item),
data = reading_time_nozeros,
family = gaussian(),
prior = NULLpriors_logrt_normal,
warmup = 1000,
iter = 2000,
chains = 4,
save_all_pars= TRUE,
control = list(adapt_delta = 0.99,max_treedepth=15))
set.seed(4321)
bf_values<-rep(NA,100)
for(i in 1:100){
bf01<-bayes_factor(null1,full1)
bf_values[i]<-bf01$bf
}
summary(bf_values)
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.05725 0.12663 0.19257 0.23821 0.30977 0.85361
sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets
[6] methods base
other attached packages:
[1] rlist_0.4.6.1 HDInterval_0.1.3 lattice_0.20-35
[4] magrittr_1.5 dplyr_0.7.4 tidyr_0.8.0
[7] gdata_2.18.0 brms_2.1.9 ggplot2_2.2.1
[10] Rcpp_0.12.16 devtools_1.13.5
loaded via a namespace (and not attached):
[1] Brobdingnag_1.2-5 httr_1.3.1
[3] gtools_3.5.0 StanHeaders_2.17.2
[5] threejs_0.3.1 shiny_1.0.5
[7] assertthat_0.2.0 stats4_3.4.4
[9] yaml_2.1.19 pillar_1.2.1
[11] backports_1.1.2 glue_1.2.0
[13] digest_0.6.15 colorspace_1.3-2
[15] htmltools_0.3.6 httpuv_1.3.6.2
[17] Matrix_1.2-12 plyr_1.8.4
[19] dygraphs_1.1.1.4 pkgconfig_2.0.1
[21] rstan_2.17.3 purrr_0.2.4
[23] xtable_1.8-2 mvtnorm_1.0-7
[25] scales_0.5.0 git2r_0.21.0
[27] tibble_1.4.2 bayesplot_1.4.0
[29] DT_0.4 withr_2.1.2
[31] shinyjs_1.0 lazyeval_0.2.1
[33] mime_0.5 memoise_1.1.0
[35] evaluate_0.10.1 papaja_0.1.0.9735
[37] nlme_3.1-131.1 xts_0.10-2
[39] colourpicker_1.0 data.table_1.10.4-3
[41] rsconnect_0.8.8 tools_3.4.4
[43] loo_1.1.0 matrixStats_0.53.1
[45] stringr_1.3.1 munsell_0.4.3
[47] bindrcpp_0.2 compiler_3.4.4
[49] rlang_0.2.0 grid_3.4.4
[51] htmlwidgets_1.0 crosstalk_1.0.0
[53] igraph_1.2.1 miniUI_0.1.1
[55] base64enc_0.1-3 rmarkdown_1.9.8
[57] gtable_0.2.0 codetools_0.2-15
[59] inline_0.3.14 abind_1.4-5
[61] curl_3.1 markdown_0.8
[63] reshape2_1.4.3 R6_2.2.2
[65] gridExtra_2.3 rstantools_1.4.0
[67] zoo_1.8-1 knitr_1.20
[69] bridgesampling_0.4-0 bindr_0.1.1
[71] shinystan_2.4.0 shinythemes_1.1.1
[73] rprojroot_1.3-2 stringi_1.2.2
[75] parallel_3.4.4 coda_0.19-1