is_prob: Verify that input is a probability (numeric value from 0 to...

Description Usage Arguments Value See Also Examples

View source: R/comp_util.R

Description

is_prob is a function that checks whether its argument prob is a probability (i.e., a numeric value in the range from 0 to 1).

Usage

1
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_perc, is_suff_prob_set, is_valid_prob_pair, is_valid_prob_set, is_valid_prob_triple

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# ways to succeed:
is_prob(1/2)                  # => TRUE
p.seq <- seq(0, 1, by = .1)   # Vector of probabilities
is_prob(p.seq)                # => TRUE (for vector)

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

riskyr documentation built on Jan. 3, 2019, 1:06 a.m.