is_complement is a function that takes 2 numeric arguments (typically probabilities) as inputs and verifies that they are complements (i.e., add up to 1, within some tolerance range tol).

is_complement(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. Default: tol = .01.

Value

NA or a Boolean value: NA if one or both arguments are NA; TRUE if both arguments are provided and complements (in tol range); otherwise FALSE.

Details

Both p1 and p2 are necessary arguments. If one or both arguments are NA, is_complement returns NA (i.e., neither TRUE nor FALSE).

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.

This function does not verify the type, range, or sufficiency of the inputs provided. See is_prob and is_suff_prob_set for this purpose.

See also

comp_complement computes a probability's complement; comp_comp_pair computes pairs of complements; 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_extreme_prob_set, is_freq, is_perc, is_prob, is_suff_prob_set, is_valid_prob_pair, is_valid_prob_set, is_valid_prob_triple

Examples

# Basics: is_complement(0, 1) # => TRUE
#> [1] TRUE
is_complement(1/3, 2/3) # => TRUE
#> [1] TRUE
is_complement(.33, .66) # => TRUE (as within default tol = .01)
#> [1] TRUE
is_complement(.33, .65) # => FALSE (as beyond default tol = .01)
#> Warning: Probabilities (p1 and p2) are not complements (in tolerated range).
#> [1] FALSE
# watch out for: is_complement(NA, NA) # => NA (but not FALSE)
#> [1] NA
is_complement(1, NA) # => NA (but not FALSE)
#> [1] NA
is_complement(2, -1) # => TRUE + warnings (p1 and p2 beyond range)
#> [1] TRUE
is_complement(8, -7) # => TRUE + warnings (p1 and p2 beyond range)
#> [1] TRUE
is_complement(.3, .6) # => FALSE + warning (beyond tolerance)
#> Warning: Probabilities (p1 and p2) are not complements (in tolerated range).
#> [1] FALSE
is_complement(.3, .6, tol = .1) # => TRUE (due to increased tolerance)
#> [1] TRUE
# ways to fail: # is_complement(0, 0) # => FALSE + warning (beyond tolerance) # is_complement(1, 1) # => FALSE + warning (beyond tolerance) # is_complement(8, 8) # => FALSE + warning (beyond tolerance)