is_prob
is a function that checks whether its argument prob
(a scalar or a vector) is a probability
(i.e., a numeric value in the range from 0 to 1).
is_prob(prob, NA_warn = FALSE)
A numeric argument (scalar or vector) that is to be checked.
Boolean value determining whether a warning is shown
for NA
values.
Default: NA_warn = FALSE
.
A Boolean value:
TRUE
if prob
is a probability,
otherwise FALSE
.
num
contains basic numeric variables;
init_num
initializes basic numeric variables;
prob
contains current probability information;
comp_prob
computes current probability information;
freq
contains current frequency information;
comp_freq
computes current frequency information;
is_valid_prob_set
verifies the validity of probability inputs;
as_pc
displays a probability as a percentage;
as_pb
displays a percentage as probability.
Other verification functions:
is_complement()
,
is_extreme_prob_set()
,
is_freq()
,
is_integer()
,
is_matrix()
,
is_perc()
,
is_suff_prob_set()
,
is_valid_prob_pair()
,
is_valid_prob_set()
,
is_valid_prob_triple()
is_prob(1/2) # TRUE
#> [1] TRUE
is_prob(2) # FALSE
#> [1] FALSE
# vectors:
p_seq <- seq(0, 1, by = .1) # Vector of probabilities
is_prob(p_seq) # TRUE (as scalar, not: TRUE TRUE etc.)
#> [1] TRUE
is_prob(c(.1, 2, .9)) # FALSE (as scalar, not: TRUE FALSE etc.)
#> [1] FALSE
## watch out for:
# is_prob(NA) # => FALSE + NO warning!
# is_prob(0/0) # => FALSE + NO warning (NA + NaN values)
# is_prob(0/0, NA_warn = TRUE) # => FALSE + warning (NA values)
## ways to fail:
# is_prob(8, NA_warn = TRUE) # => FALSE + warning (outside range element)
# is_prob(c(.5, 8), NA_warn = TRUE) # => FALSE + warning (outside range vector element)
# is_prob("Laplace", NA_warn = TRUE) # => FALSE + warning (non-numeric values)