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.

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.

Value

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

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.

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
#> [1] TRUE
is_valid_prob_pair(0, 1)      # => TRUE
#> [1] TRUE
is_valid_prob_pair(1, NA)     # => TRUE + warning (NA)
#> [1] TRUE
is_valid_prob_pair(NA, 1)     # => TRUE + warning (NA)
#> [1] TRUE
is_valid_prob_pair(.50, .51)  # => TRUE (as within tol)
#> [1] TRUE

# ways to fail:
is_valid_prob_pair(.50, .52)  # => FALSE (as beyond tol)
#> Warning: Probabilities (p1 and p2) are not complements (in tolerated range).
#> [1] FALSE
is_valid_prob_pair(1, 2)      # => FALSE + warning (beyond range)
#> [1] FALSE
is_valid_prob_pair(NA, NA)    # => FALSE + warning (NA)
#> [1] FALSE