Skip to contents

Checks that conf.level is a single number in \((0, 1)\), or NA. Intended for the confidence-interval functions across the suite, so that all of them accept the same values and refuse the rest with the same message.

Usage

checkConfLevel(conf.level)

Arguments

conf.level

the value to check.

Value

conf.level, invisibly,
so the check can be used in an assignment: conf.level <- checkConfLevel(conf.level).

Details

The order of the tests is the point of this function. NA is logical, so a check that leads with !is.numeric() rejects the very default most of these functions carry. And is.na() on a vector of length other than one turns the surrounding if into the error message, which then talks about the condition instead of the argument. Length first, then type, then range.

NaN is excluded explicitly: is.na(NaN) is TRUE, so without that test a NaN would be silently accepted as "no interval wanted".

Examples

checkConfLevel(0.95)
checkConfLevel(NA)

# all of these are rejected:
try(checkConfLevel(c(0.9, 0.95)))   # length
#> Error : 'conf.level' must be a single number in (0, 1), or NA
try(checkConfLevel(NULL))           # length
#> Error : 'conf.level' must be a single number in (0, 1), or NA
try(checkConfLevel(NaN))            # not a level, and not NA either
#> Error : 'conf.level' must be a single number in (0, 1), or NA
try(checkConfLevel(0))              # range is open
#> Error : 'conf.level' must be a single number in (0, 1), or NA