Builds a Bayes factor from natural-logarithm BF10 values without passing them through exp(). Output on the logarithmic scale (logBF = TRUE) and in the inverse orientation (BF01 = TRUE) is computed in log space, so Bayes factors beyond the double range (an exp(log_BF) equal to 0 or Inf) keep finite logarithms and representable reciprocals. format_BF() cannot recover them from the natural-scale numbers.

format_BF_from_log(
  log_BF,
  logBF = FALSE,
  BF01 = FALSE,
  inclusion = FALSE,
  bound_operator = NULL,
  diagnostics = NULL
)

Arguments

log_BF

numeric vector of natural-logarithm BF10 values (the Bayes factor in favor of the alternative hypothesis). Names are kept. Missing values (NA, NaN) are propagated.

logBF

whether the logarithm of the Bayes factor is returned.

BF01

whether the inverse Bayes factor (the BF01 orientation) is returned.

inclusion

whether the Bayes factor is an inclusion Bayes factor (for naming purposes).

bound_operator

NULL (all values exact), or a character vector with one element per value of log_BF: NA for an exact value, "<" or ">" when the value is an upper or lower bound of the Bayes factor. A logical vector of NA with one element per value (all values exact) is accepted as well. The operators refer to the BF10 values in log_BF and are stored in the orientation of the output (inverted when BF01 = TRUE, see invert_BF_bound_operator()).

diagnostics

NULL, or a list with one element per value of log_BF (elements can be NULL) holding numerical diagnostics of the individual Bayes factors, stored with the carrier.

Value

format_BF_from_log() returns a numeric vector of class c("BayesTools_BF", "numeric") with the names of log_BF. Its public attributes are name (for example "BF", "1/BF", "Inclusion BF", "Exclusion BF", wrapped in log() when logBF = TRUE), logBF, BF01, and bound_operator.

Details

The result is the Bayes-factor carrier that format_BF() returns when it receives such a carrier: reformatting it with format_BF() keeps the canonical logarithms. A plain numeric vector given to format_BF() returns an unclassed vector (it has the class BayesTools_BF only while a non-missing bound operator is present). The carrier stores the logarithms in private attributes; BF_carrier_drop() removes them. Subsetting keeps the logarithms of the selected values, arithmetic on the carrier returns ordinary numbers, and replacing values removes the carrier attributes.

Examples

# a Bayes factor beyond the double range keeps its finite logarithm
BF <- format_BF_from_log(c(a = 2, b = 800))
format_BF(BF, logBF = TRUE)
#>   a   b 
#>   2 800 
#> attr(,"name")
#> [1] "log(BF)"
#> attr(,"logBF")
#> [1] TRUE
#> attr(,"BF01")
#> [1] FALSE
format_BF(BF, BF01 = TRUE, logBF = TRUE)
#>    a    b 
#>   -2 -800 
#> attr(,"name")
#> [1] "log(1/BF)"
#> attr(,"logBF")
#> [1] TRUE
#> attr(,"BF01")
#> [1] TRUE