inspect_par_multinomial {inspector} | R Documentation |
Validate parameters for the Multinomial distribution
Description
inspect_par_multinomial
checks if an object is an eligible
vector of Multinomial proportions. This can be useful to validate inputs,
intermediate calculations or outputs in user-defined functions.
Usage
inspect_par_multinomial(x)
Arguments
x |
An arbitrary object. |
Details
inspect_par_multinomial
conducts a series of tests to check if
x
is an eligible vector of Multinomial proportions. Namely,
inspect_par_multinomial
checks if:
-
x
isNULL
or empty. -
x
is an atomic vector -
x
is numeric -
x
hasNA
orNaN
values. All elements of
x
are in the (0, 1) interval.-
x
sums to 1.
Value
inspect_par_multinomial
does not return any output.
There are two possible outcomes:
The call is silent if
x
is an eligible vector of Multinomial proportions.An informative error message is thrown otherwise.
See Also
-
inspect_par_bernoulli
to validate parameters for the Bernoulli/Binomial distribution. -
inspect_par_beta
to validate parameters for the Beta distribution. -
inspect_par_dirichlet
to validate parameters for the Dirichlet distribution. -
inspect_par_haldane
to validate parameters for the Haldane distribution. -
inspect_data_categorical
andinspect_data_cat_as_dichotom
to validate categorical data. -
inspect_prob
to check if an object is a numeric vector of valid probability values.
Examples
# Calls that pass silently:
x1 <- c(0.5, 0.5)
x2 <- rep(1 / 5, 5)
inspect_par_multinomial(x1)
inspect_par_multinomial(x2)
# Calls that throw an informative error message:
mylist <- list(
NULL, TRUE, factor(0.5, 0.5),
matrix(c(0.5, 0.5)), c("0.5", "0.5"), list(0.5, 0.5),
c(0.9, NA), c(0.9, NaN), numeric(0), NA, c(0.9, 0.6), c(-0.1, 0.9)
)
try(inspect_par_multinomial(mylist[[1]]))
try(inspect_par_multinomial(mylist[[2]]))
try(inspect_par_multinomial(mylist[[3]]))
try(inspect_par_multinomial(mylist[[4]]))
try(inspect_par_multinomial(mylist[[5]]))
try(inspect_par_multinomial(mylist[[6]]))
try(inspect_par_multinomial(mylist[[7]]))
try(inspect_par_multinomial(mylist[[8]]))
try(inspect_par_multinomial(mylist[[9]]))
try(inspect_par_multinomial(mylist[[10]]))
try(inspect_par_multinomial(mylist[[11]]))
try(inspect_par_multinomial(mylist[[12]]))