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)

## Arguments

Age integer vector of single ages (lower bound) integer vector. Age interval widths logical (default TRUE). Is the final age group open?

## Value

logical. TRUE if the arguments are considered consistent.

## Details

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.

## Examples

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
#>  TRUE
# incorrectly coded OAG
is_age_coherent(Age = Age, AgeInt = AgeInt, OAG = TRUE)      # FALSE
#> The AgeInt value for OAG should be NA, but it is1#>  FALSE
# correctly coded OAG
AgeInt <- NA
is_age_coherent(Age = Age, AgeInt = AgeInt, OAG = TRUE)      # 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
#> Age isn't sorted. Sorting Age and AgeInt
#> under strong assumption that they are in matched order.#>  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
#> At least one age repeated, ergo Age is incoherent#>  FALSE