R/inspect_par_.R
inspect_par_multinomial.Rd
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.
inspect_par_multinomial(x)
x | An arbitrary object. |
---|
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.
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
is NULL
or empty.
x
is an atomic vector
x
is numeric
x
has NA
or NaN
values.
All elements of x
are in the (0, 1) interval.
x
sums to 1.
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
and
inspect_data_cat_as_dichotom
to validate categorical
data.
inspect_prob
to check if an object is a numeric
vector of valid probability values.
# 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]]))
#> Error in inspect_par_multinomial(mylist[[1]]) :
#> Invalid argument: mylist[[1]] is NULL.
try(inspect_par_multinomial(mylist[[2]]))
#> Error in inspect_par_multinomial(mylist[[2]]) :
#> Invalid argument: mylist[[2]] must be numeric.
try(inspect_par_multinomial(mylist[[3]]))
#> Error in inspect_par_multinomial(mylist[[3]]) :
#> Invalid argument: mylist[[3]] must be an atomic vector.
try(inspect_par_multinomial(mylist[[4]]))
#> Error in inspect_par_multinomial(mylist[[4]]) :
#> Invalid argument: mylist[[4]] must be an atomic vector.
try(inspect_par_multinomial(mylist[[5]]))
#> Error in inspect_par_multinomial(mylist[[5]]) :
#> Invalid argument: mylist[[5]] must be numeric.
try(inspect_par_multinomial(mylist[[6]]))
#> Error in inspect_par_multinomial(mylist[[6]]) :
#> Invalid argument: mylist[[6]] must be an atomic vector.
try(inspect_par_multinomial(mylist[[7]]))
#> Error in inspect_par_multinomial(mylist[[7]]) :
#> Invalid argument: there are NA or NaN values in mylist[[7]].
try(inspect_par_multinomial(mylist[[8]]))
#> Error in inspect_par_multinomial(mylist[[8]]) :
#> Invalid argument: there are NA or NaN values in mylist[[8]].
try(inspect_par_multinomial(mylist[[9]]))
#> Error in inspect_par_multinomial(mylist[[9]]) :
#> Invalid argument: mylist[[9]] is empty.
try(inspect_par_multinomial(mylist[[10]]))
#> Error in inspect_par_multinomial(mylist[[10]]) :
#> Invalid argument: there are NA or NaN values in mylist[[10]].
try(inspect_par_multinomial(mylist[[11]]))
#> Error in inspect_par_multinomial(mylist[[11]]) :
#> Invalid argument: mylist[[11]] must sum to 1.
try(inspect_par_multinomial(mylist[[12]]))
#> Error in inspect_par_multinomial(mylist[[12]]) :
#> Invalid argument: all elements of mylist[[12]] values must be in the (0, 1) interval.