Check if every element in a given numerical vector or matrix represents a probability, that is a number within (0, 1) interval, that can optionally be closed at any side.
check_probabilities(
x,
bounds_closed = TRUE,
len = NULL,
unique = FALSE,
sorted = FALSE
)assert_probabilities(
x,
bounds_closed = TRUE,
len = NULL,
unique = FALSE,
sorted = FALSE,
.var.name = checkmate::vname(x),
add = NULL
)
test_probabilities(
x,
bounds_closed = TRUE,
len = NULL,
unique = FALSE,
sorted = FALSE
)
expect_probabilities(
x,
bounds_closed = TRUE,
len = NULL,
unique = FALSE,
sorted = FALSE,
info = NULL,
label = vname(x)
)
TRUE if successful, otherwise a string with the error message.
(numeric)
vector or matrix with numerical values to check.
(logical)
should bounds be closed? This can be a
scalar or vector of length two. If it is a scalar, then its value applies
equally to lower bound \(0\) and upper bound \(1\). If this is a vector
with two flags, the first flag corresponds to the lower bound \(0\)
only, and the second to the upper bound \(1\) only.
[integer(1)]
Exact expected length of x.
[logical(1)]
Must all values be unique? Default is FALSE.
[logical(1)]
Elements must be sorted in ascending order. Missing values are ignored.
[character(1)]
Name of the checked object to print in assertions. Defaults to
the heuristic implemented in vname.
[AssertCollection]
Collection to store assertion messages. See AssertCollection.
[character(1)]
Extra information to be included in the message for the testthat reporter.
See expect_that.
[character(1)]
Name of the checked object to print in messages. Defaults to
the heuristic implemented in vname.
assertions for more details.
x <- c(0, 0.2, 0.1, 0.3, 1)
check_probabilities(x)
check_probabilities(x, bounds_closed = FALSE)
check_probabilities(x, bounds_closed = c(FALSE, TRUE))
Run the code above in your browser using DataLab