Reporting Bayes Factor in regression analysis
A quick function to extract and report large Bayes factors as a power of 10 when running a regression analysis. The function takes the output of regressionBF (Package BayesFactor: Morey & Rouder, 2018), extracts the BF and converts into a format for Rmarkdown.
# A function to extract and report Bayes Factors
BF_scirep_str <- function(model) {
output <- formatC(round(extractBF(model, onlybf = T)), digits = 3)
output <- sub("e", "x10<sup>", output) #Replace e with 10^
output <- sub("\\+0?", "", output) #Remove + symbol and leading zeros on expoent, if > 1
output <- sub("-0?", "-", output) #Leaves - symbol but removes leading zeros on expoent, if < 1
output
}
An example:# Library
library(BayesFactor)
# Regression model
model <- regressionBF(mpg ~ hp + wt, data = mtcars)
model
## Bayes factor analysis
## --------------
## [1] hp : 56963.84 ±0.01%
## [2] wt : 45657981 ±0.01%
## [3] hp + wt : 788547604 ±0%
##
## Against denominator:
## Intercept only
## ---
## Bayes factor type: BFlinearModel, JZS
# BF for the model with only hp
BF_scirep_str(model = model["hp"])
## [1] "5.7x10<sup>4"
# BF for the model with only wt
BF_scirep_str(model = model["wt"])
## [1] "4.57x10<sup>7"
# BF for the model with both hp and wt
bf_out <- BF_scirep_str(model = model["hp + wt"])
There was extreme evidence for the model including the effect of hp and wt, BF=7.89x108.
Comments
Post a Comment