is_age_coherent | R Documentation |
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 |
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.
logical. TRUE
if the arguments are considered consistent.
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
# incorrectly coded OAG
is_age_coherent(Age = Age, AgeInt = AgeInt, OAG = TRUE) # FALSE
# correctly coded OAG
AgeInt[100] <- NA
is_age_coherent(Age = Age, AgeInt = AgeInt, OAG = TRUE) # 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
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.