Learn R Programming

inspector (version 1.0.3)

inspect_par_dirichlet: Validate parameters for the Dirichlet distribution

Description

inspect_par_dirichlet checks if an object is an eligible vector of parameters for the Dirichlet distribution. This can be useful to validate inputs, intermediate calculations or outputs in user-defined functions.

Usage

inspect_par_dirichlet(x)

Arguments

x

An arbitrary object.

Value

inspect_par_dirichlet does not return any output. There are two possible outcomes:

  • The call is silent if x is an eligible vector of parameters for the Dirichlet distribution.

  • An informative error message is thrown otherwise.

Details

inspect_par_dirichlet conducts a series of tests to check if x is an eligible vector of parameters for the Dirichlet distribution. Namely, inspect_par_dirichlet 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 positive.

See Also

Examples

Run this code
# NOT RUN {
# Calls that pass silently:
x1 <- c(1, 1, 1)
x2 <- c(2, 5)
inspect_par_dirichlet(x1)
inspect_par_dirichlet(x2)

# Calls that throw an informative error message:
mylist <- list(
  NULL, factor(1, 1, 1),
  matrix(c(1, 1, 1)), c("1", "1", "1"), list(1, 1, 1), c(1, NA),
  c(1, NaN, 1), c(TRUE, FALSE), numeric(0), c(-1, 1, 1)
)
try(inspect_par_dirichlet(mylist[[1]]))
try(inspect_par_dirichlet(mylist[[2]]))
try(inspect_par_dirichlet(mylist[[3]]))
try(inspect_par_dirichlet(mylist[[4]]))
try(inspect_par_dirichlet(mylist[[5]]))
try(inspect_par_dirichlet(mylist[[6]]))
try(inspect_par_dirichlet(mylist[[7]]))
try(inspect_par_dirichlet(mylist[[8]]))
try(inspect_par_dirichlet(mylist[[9]]))
try(inspect_par_dirichlet(mylist[[10]]))
# }

Run the code above in your browser using DataLab