A few checks are carried out to test if Age
is internally consistent, that OAG
is consistent with AgeInt
, and that Age
and AgeInt
are consistent with one another. For Age
to be internally consistent, we cannot have redundant values, and values must be sequential.
is_age_coherent(Age, AgeInt, OAG = TRUE)
Age | integer vector of single ages (lower bound) |
---|---|
AgeInt | integer vector. Age interval widths |
OAG | logical (default |
logical. TRUE
if the arguments are considered consistent.
If OAG
is TRUE
then AgeInt
must be coded as NA
. If Age
is not sorted then we sort both Age
and AgeInt
, assuming that they are in matched order. This isn't incoherence in itself, but a message is returned to the console.
Age <- 0:99 AgeInt <- rep(1, 100) # closed, sequential, non-redundant ages, any easy yes: is_age_coherent(Age = Age, AgeInt = AgeInt, OAG = FALSE) # TRUE#> [1] TRUE# incorrectly coded OAG is_age_coherent(Age = Age, AgeInt = AgeInt, OAG = TRUE) # FALSE#>#> [1] FALSE# correctly coded OAG AgeInt[100] <- NA is_age_coherent(Age = Age, AgeInt = AgeInt, OAG = TRUE) # TRUE#> [1] TRUE# correct unordered, but this isn't incoherence per se. # watch out though! aaoo <- order(sample(Age, 100, replace = FALSE)) is_age_coherent(Age[aaoo], AgeInt = AgeInt[aaoo], OAG = TRUE) # TRUE#>#>#> [1] TRUE# check redundancy AgeRed <- c(0:100,70) AgeInt <- c(rep(1, 100), NA, NA) ao <- order(AgeRed) AgeRed <- AgeRed[ao] AgeIntRed <- AgeInt[ao] is_age_coherent(AgeRed, AgeInt, TRUE) # FALSE#>#> [1] FALSE