Usage
assert_list_of_variables(x, .var.name = checkmate::vname(x), add = NULL)
assert_df_with_variables(
df,
variables,
na_level = NULL,
.var.name = checkmate::vname(df),
add = NULL
)
assert_valid_factor(
x,
min.levels = 1,
max.levels = NULL,
null.ok = TRUE,
any.missing = TRUE,
n.levels = NULL,
len = NULL,
.var.name = checkmate::vname(x),
add = NULL
)
assert_df_with_factors(
df,
variables,
min.levels = 1,
max.levels = NULL,
any.missing = TRUE,
na_level = NULL,
.var.name = checkmate::vname(df),
add = NULL
)
assert_proportion_value(x, include_boundaries = FALSE)
assert_proportion_data(rsp, grp, strata = NULL)
assert_stratification_compatibility(method, stratified_methods, strata_vars)Arguments
- x
(
any)
object to test.- .var.name
[
character(1)]
Name of the checked object to print in assertions. Defaults to the heuristic implemented invname.- add
[
AssertCollection]
Collection to store assertion messages. SeeAssertCollection.- df
(
data.frame)
data set to test.- variables
(named
listofcharacter)
list of variables to test.- na_level
(
string)
the string you have been using to represent NA or missing data. ForNAvalues please consider using directlyis.na()or similar approaches.- min.levels
[
integer(1)]
Minimum number of factor levels. Default isNULL(no check).- max.levels
[
integer(1)]
Maximum number of factor levels. Default isNULL(no check).- null.ok
[
logical(1)]
If set toTRUE,xmay also beNULL. In this case only a type check ofxis performed, all additional checks are disabled.- any.missing
[
logical(1)]
Are vectors with missing values allowed? Default isTRUE.- n.levels
[
integer(1)]
Exact number of factor levels. Default isNULL(no check).- len
[
integer(1)]
Exact expected length ofx.- include_boundaries
(
flag)
whether to include boundaries when testing for proportions.- rsp
(
logical)
Indicates whether each observation is a responder (TRUE) or a non-responder (FALSE). Missing values are not allowed.- grp
(
factor)
Assigns each observation to one of two groups, such as a reference and a treatment group. Must have exactly two levels and the same length asrsp. Missing values are not allowed.- strata
(
factororNULL)
Defines the stratification variable. If notNULL, it must have the same length asrspand must not contain any missing values.- method
(
character(1))
Specifies the statistical method.- stratified_methods
(
character)
Names of the methods that require stratified data.- strata_vars
(
characterorNULL)
Names of the variables defining the strata, orNULLif no stratification is used.
Functions
assert_list_of_variables(): Checks whetherxis a valid list of variable names.NULLelements of the listxare dropped withFilter(Negate(is.null), x).assert_df_with_variables(): Check whetherdfis a data frame with the analysisvariables. Please notice how this produces an error when not all variables are present in the data.frame while the opposite is not required.assert_valid_factor(): Check whetherxis a valid factor (i.e. has levels and no empty string levels). Note thatNULLandNAelements are allowed.assert_df_with_factors(): Check whetherdfis a data frame where the analysisvariablesare all factors. Note that the creation ofNAby direct call offactor()will trimNAlevels out of the vector list itself.assert_proportion_value(): Check whetherxis a proportion: number between 0 and 1.assert_proportion_data(): Validates the data required for a proportion analysis, including responder status, group assignment, and optional stratification.assert_stratification_compatibility(): Assert compatibility between a method and stratification. Checks that the selected method is compatible with the presence or absence of stratification variables. Methods included instratified_methodsrequire at least one variable defining the strata, while unstratified methods must not use stratification variables.
Examples
x <- data.frame(
a = 1:10,
b = rnorm(10)
)
assert_df_with_variables(x, variables = list(a = "a", b = "b"))
x <- ex_adsl
assert_df_with_variables(x, list(a = "ARM", b = "USUBJID"))
x <- ex_adsl
assert_df_with_factors(x, list(a = "ARM"))
assert_proportion_value(0.95)
assert_proportion_value(1.0, include_boundaries = TRUE)
rsp <- c(TRUE, TRUE, FALSE, TRUE, FALSE, FALSE)
grp <- factor(c(rep("Placebo", 3), rep("X", 3)))
strata <- factor(c("A", "A", "B", "A", "B", "B"))
assert_proportion_data(rsp, grp, strata)
if (FALSE) { # \dontrun{
# An error is raised when `grp` has only one level.
grp <- factor(rep("X", 6))
assert_proportion_data(rsp, grp, strata)
} # }
