is_prob {riskyr}R Documentation

Verify that input is a probability (numeric value from 0 to 1).

Description

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).

Usage

is_prob(prob, NA_warn = FALSE)

Arguments

prob

A numeric argument (scalar or vector) that is to be checked.

NA_warn

Boolean value determining whether a warning is shown for NA values. Default: NA_warn = FALSE.

Value

A Boolean value: TRUE if prob is a probability, otherwise FALSE.

See Also

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()

Examples

is_prob(1/2)                  # TRUE
is_prob(2)                    # FALSE

# vectors:
p_seq <- seq(0, 1, by = .1)   # Vector of probabilities
is_prob(p_seq)                # TRUE (as scalar, not: TRUE TRUE etc.)
is_prob(c(.1, 2, .9))         # FALSE (as scalar, not: TRUE FALSE etc.)

## 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)


[Package riskyr version 0.4.0 Index]