Verify that two numbers are complements.

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)

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


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


A numeric tolerance value. Default: tol = .01.


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.


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.

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

  • is_complement
# Basics:
is_complement(0, 1)           # => TRUE
is_complement(1/3, 2/3)       # => TRUE
is_complement(.33, .66)       # => TRUE  (as within default tol = .01)
is_complement(.33, .65)       # => FALSE (as beyond default tol = .01)

# watch out for:
is_complement(NA, NA)            # => NA (but not FALSE)
is_complement(1, NA)             # => NA (but not FALSE)
is_complement(2, -1)             # => TRUE + warnings (p1 and p2 beyond range)
is_complement(8, -7)             # => TRUE + warnings (p1 and p2 beyond range)
is_complement(.3, .6)            # => FALSE + warning (beyond tolerance)
is_complement(.3, .6, tol = .1)  # => TRUE (due to increased tolerance)

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

# }
Documentation reproduced from package riskyr, version 0.2.0, License: GPL-2 | GPL-3

Community examples

Looks like there are no examples yet.