is_valid_prob_pair: Verify that a pair of probability inputs can be a pair of...

View source: R/comp_util.R

is_valid_prob_pairR Documentation

Verify that a pair of probability inputs can be a pair of complementary probabilities.

Description

is_valid_prob_pair is a function that verifies that a pair of 2 numeric inputs p1 and p2 can be interpreted as a valid pair of probabilities.

Usage

is_valid_prob_pair(p1, p2, tol = 0.01)

Arguments

p1

A numeric argument (typically probability in range from 0 to 1).

p2

A numeric argument (typically probability in range from 0 to 1).

tol

A numeric tolerance value.

Details

is_valid_prob_pair is a wrapper function that combines is_prob and is_complement in one function.

Either p1 or p2 must be a probability (verified via is_prob). If both arguments are provided they must be probabilities and complements (verified via is_complement).

The argument tol is optional (with a default value of .01) Numeric near-complements that differ by less than this value are still considered to be complements.

Value

A Boolean value: TRUE if exactly one argument is a probability, if both arguments are probabilities and complements, otherwise FALSE.

See Also

is_valid_prob_set uses this function to verify sets of probability inputs; is_complement verifies numeric complements; is_prob verifies probabilities; 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; 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_prob(), is_suff_prob_set(), is_valid_prob_set(), is_valid_prob_triple()

Examples

# ways to succeed:
is_valid_prob_pair(1, 0)      # => TRUE
is_valid_prob_pair(0, 1)      # => TRUE
is_valid_prob_pair(1, NA)     # => TRUE + warning (NA)
is_valid_prob_pair(NA, 1)     # => TRUE + warning (NA)
is_valid_prob_pair(.50, .51)  # => TRUE (as within tol)

# ways to fail:
is_valid_prob_pair(.50, .52)  # => FALSE (as beyond tol)
is_valid_prob_pair(1, 2)      # => FALSE + warning (beyond range)
is_valid_prob_pair(NA, NA)    # => FALSE + warning (NA)


riskyr documentation built on Aug. 15, 2022, 9:09 a.m.