Readme.md

simplebf is a package of convenience functions for Bayes Factor analysis of two samples. The package is developed as a teaching aid for those new to Bayesian Inference and working with R.

The functions are thin wrappers around functions in BayesFactor on CRAN here and project webpage http://bayesfactor.blogspot.com/. Please use that in preference.

Installation

devtoolls::install_github("danmaclean/simplebf")

Using simplebf for a t-test

To carry out Bayes Factor analysis on two named groups in a tidy dataframe use named_pair_ttestbf(), pass it the column names for the group and data measurements, the name of the group to be considered as the test group, and the name of the group to be considere the control group.

library(simplebf)
result <- named_pair_ttestbf(PlantGrowth, 
                             group_col = "group", data_col = "weight",
                             control = "ctrl", test = "trt2"
                             )

The function returns a one row dataframe, the columns are as follows:

1. `control_group` - the name of the group considered control
2. `test_group` - the group considered test
3. `h_0` - statement of the $H_0$ hypothesis
4. `h_1` - statement of the $H_1$ hypothesis
5. `BayesFactor` - the resulting Bayes Factor from $\frac{H_{1}/H_{0}}$
6. `odds_h_1` - statement of the Bayes Factor in terms of odds $H_0:H_1$
7. `summary` - summary statement of relative evidence for the hypothesis
result %>% knitr::kable()
control_group test_group h_0 h_1 BayesFactor odds_h_1 summary ctrl trt2 trt2 equal to ctrl trt2 greater than ctrl 3.387166 1:3.38716599374275 Substantial evidence for H_1 compared to H_0

Changing the scale of the prior and the nature H1

Only one option for the BayesFactor::ttestBF() function can be changed. The value of rscale for the prior distribution can be set to one of medium, wide or ultrawide. The hypothesis to test as H1 can be set to one of test_greater_than_control, test_smaller_than_control,test_not_equal_to_control.

result <- named_pair_ttestbf(PlantGrowth, 
                             group_col = "group", data_col = "weight",
                             control = "ctrl", test = "trt2",
                             rscale = "medium",
                             h_1 = "test_greater_than_control"
                             )

Comparing all groups in a dataframe

All levels of the group column can be compared pairwise using the allpairs_ttestbf() function. This is called similarly to the named_pair_ttestbf() but without the need to specify control and test groups as all pairs are done automatically. A dataframe with the same columns as above and one row for each pair (in A:B and B:A order) is returned. rscale and h_1 can be used here too.

result <- allpairs_ttestbf(PlantGrowth, group_col = "group", data_col = "weight")
result %>% knitr::kable()
control_group test_group h_0 h_1 BayesFactor odds_h_1 summary trt1 ctrl ctrl equal to trt1 ctrl greater than trt1 1.0833663 1:1.08336631965942 Anecdotal evidence for H_1 compared to H_0 trt2 ctrl ctrl equal to trt2 ctrl greater than trt2 0.1622109 1:0.162210898064748 Substantial evidence for H_0 compared to H_1 ctrl trt1 trt1 equal to ctrl trt1 greater than ctrl 0.2167156 1:0.216715621920709 Substantial evidence for H_0 compared to H_1 trt2 trt1 trt1 equal to trt2 trt1 greater than trt2 0.1363151 1:0.13631506044811 Substantial evidence for H_0 compared to H_1 ctrl trt2 trt2 equal to ctrl trt2 greater than ctrl 3.3871660 1:3.38716599374275 Substantial evidence for H_1 compared to H_0 trt1 trt2 trt2 equal to trt1 trt2 greater than trt1 12.6444900 1:12.6444900067635 Strong evidence for H_1 compared to H_0

danmaclean/simplebf documentation built on Sept. 22, 2023, 11:59 p.m.