inspect_data_dichotomous {inspector} | R Documentation |
Validate dichotomous data
Description
inspect_data_dichotomous
checks if an object contains data
that is eligible to have been generated by a series of Bernoulli trials. This
can be useful to validate inputs in user-defined functions.
Usage
inspect_data_dichotomous(data, success, allow_nas = TRUE, warning_nas = FALSE)
Arguments
data , success |
Arbitrary objects. |
allow_nas |
Logical value. If |
warning_nas |
Logical value. If |
Details
inspect_data_dichotomous
conducts a series of tests to check if
data
is eligible to have been generated by a series of Bernoulli trials.
Namely, inspect_data_dichotomous
checks if:
-
data
andsuccess
areNULL
or empty. -
data
andsuccess
are atomic and have an eligible data type (logical, integer, double, character). -
data
andsuccess
haveNA
orNaN
values. The number of unique values in
data
andsuccess
are adequate.-
success
haslength
1. -
success
is observed indata
.
Value
inspect_data_dichotomous
does not return any output. There are
three possible outcomes:
The call is silent if:
-
data
is eligible to have been generated by a series of Bernoulli trials and there are noNA
orNaN
values indata
. -
data
is eligible to have been generated by a series of Bernoulli trials, there are someNA
orNaN
values indata
,allow_nas
is set toTRUE
andwarning_nas
is set toFALSE
.
-
An informative warning message is thrown if:
-
data
is eligible to have been generated by a series of Bernoulli trials andsuccess
is not observed indata
. -
data
is eligible to have been generated by a series of Bernoulli trials, there areNA
orNaN
values indata
and bothallow_nas
andwarning_nas
are set toTRUE
.
-
An informative error message is thrown and the execution is stopped if:
-
data
is not eligible to have been generated by a series of Bernoulli trials. -
data
is eligible to have been generated by a series of Bernoulli trials, there are someNA
orNaN
values indata
andallow_nas
is set toFALSE
.
-
See Also
-
inspect_par_bernoulli
to validate Bernoulli/Binomial proportions. -
inspect_data_categorical
andinspect_data_cat_as_dichotom
to validate categorical data. -
inspect_par_multinomial
to validate vectors of Multinomial proportions.
Examples
# Calls that pass silently:
x1 <- c(1, 0, 0, 1, 0)
x2 <- c(FALSE, FALSE, TRUE)
x3 <- c("yes", "no", "yes")
x4 <- factor(c("yes", "no", "yes"))
x5 <- c(1, 0, 0, 1, 0, NA)
inspect_data_dichotomous(x1, success = 1)
inspect_data_dichotomous(x2, success = TRUE)
inspect_data_dichotomous(x3, success = "yes")
inspect_data_dichotomous(x4, success = "yes")
inspect_data_dichotomous(x5, success = 1)
# Calls that throw an informative warning message:
y1 <- c(1, 1, NA, 0, 0)
y2 <- c(0, 0)
success <- 1
try(inspect_data_dichotomous(y1, success = 1, warning_nas = TRUE))
try(inspect_data_dichotomous(y2, success = success))
# Calls that throw an informative error message:
try(inspect_data_dichotomous(NULL, 1))
try(inspect_data_dichotomous(c(1, 0), NULL))
try(inspect_data_dichotomous(list(1, 0), 1))
try(inspect_data_dichotomous(c(1, 0), list(1)))
try(inspect_data_dichotomous(numeric(0), 0))
try(inspect_data_dichotomous(1, numeric(0)))
try(inspect_data_dichotomous(NaN, 1))
try(inspect_data_dichotomous(NA, 1))
try(inspect_data_dichotomous(c(1, 0), NA))
try(inspect_data_dichotomous(c(1, 0), NaN))
try(inspect_data_dichotomous(c(1, 0), 2))