inspect_bfactor_log
checks if an object is a numeric vector
of valid logarithmic Bayes factor values. This can be useful to validate
inputs, intermediate calculations or outputs in user-defined functions.
inspect_bfactor_log(x, allow_nas = TRUE, warning_nas = TRUE)
x | An arbitrary object. |
---|---|
allow_nas | Logical value. If |
warning_nas | Logical value. If |
inspect_bfactor_log
does not return any output. There are three
possible outcomes:
The call is silent if:
x
is a numeric vector of valid logarithmic Bayes factor values and
there are no NA
or NaN
values in x
.
x
is a numeric vector of valid logarithmic Bayes factor values, there
are some NA
or NaN
values in x
, allow_nas
is set to TRUE
and
warning_nas
is set to FALSE
.
An informative warning message is given if x
is a numeric vector of valid
logarithmic Bayes factor values, there are some NA
or NaN
values in x
and both allow_nas
and warning_nas
are set to TRUE
.
An informative error message is thrown and the execution is stopped if:
x
is not a numeric vector of valid logarithmic Bayes factor values.
x
is a numeric vector of valid logarithmic Bayes factor values, there
are some NA
or NaN
values in x
and allow_nas
is set to FALSE
.
inspect_bfactor_log
conducts a series of tests to check if x
is
a numeric vector of valid logarithmic Bayes factor values. Namely,
inspect_bfactor_log
checks if:
x
is NULL
or empty.
x
is an atomic vector.
x
is numeric.
x
has NA
or NaN
values.
inspect_bfactor
to check if an object is a numeric
vector of valid Bayes factor values.
bfactor_log_interpret
for the interpretation of the
logarithms of Bayes factors.
inspect_bfactor_scale
to check if an object is a
Bayes factor interpretation scale.
inspect_log_base
to check if an object is an
eligible logarithmic base.
# Calls that pass silently:
x1 <- c(0, 0.5, 1, 10, 50, 100)
x2 <- c(NA, 0.5, 1, 10, 50, 100)
inspect_bfactor_log(x1)
inspect_bfactor_log(x2, warning_nas = FALSE)
inspect_bfactor_log(x2, allow_nas = TRUE, warning_nas = FALSE)
# Call that throws an informative warning message:
y <- c(0.1, 0.2, NA, 0.4, 0.5)
try(inspect_bfactor_log(y))
#> Warning: There are NA or NaN values in y.
try(inspect_bfactor_log(y, warning_nas = TRUE))
#> Warning: There are NA or NaN values in y.
try(inspect_bfactor_log(y, allow_nas = TRUE, warning_nas = TRUE))
#> Warning: There are NA or NaN values in y.
# Calls that throw informative error messages:
mylist <- list(
NULL, TRUE, factor(.5), matrix(0.5),
"0.5", list(0.5), numeric(0), NA, NaN
)
try(inspect_bfactor_log(mylist[[1]]))
#> Error in inspect_bfactor_log(mylist[[1]]) :
#> Invalid argument: mylist[[1]] is NULL.
try(inspect_bfactor_log(mylist[[2]]))
#> Error in inspect_bfactor_log(mylist[[2]]) :
#> Invalid argument: the type of mylist[[2]] must be numeric.
try(inspect_bfactor_log(mylist[[3]]))
#> Error in inspect_bfactor_log(mylist[[3]]) :
#> Invalid argument: mylist[[3]] must be an atomic vector.
try(inspect_bfactor_log(mylist[[4]]))
#> Error in inspect_bfactor_log(mylist[[4]]) :
#> Invalid argument: mylist[[4]] must be an atomic vector.
try(inspect_bfactor_log(mylist[[5]]))
#> Error in inspect_bfactor_log(mylist[[5]]) :
#> Invalid argument: the type of mylist[[5]] must be numeric.
try(inspect_bfactor_log(mylist[[6]]))
#> Error in inspect_bfactor_log(mylist[[6]]) :
#> Invalid argument: mylist[[6]] must be an atomic vector.
try(inspect_bfactor_log(mylist[[7]]))
#> Error in inspect_bfactor_log(mylist[[7]]) :
#> Invalid argument: mylist[[7]] is empty.
try(inspect_bfactor_log(mylist[[8]]))
#> Error in inspect_bfactor_log(mylist[[8]]) :
#> Invalid argument: all elements of mylist[[8]] are NA or NaN.
try(inspect_bfactor_log(mylist[[9]]))
#> Error in inspect_bfactor_log(mylist[[9]]) :
#> Invalid argument: all elements of mylist[[9]] are NA or NaN.