Skip to contents

Verifies that age and sex can be turned into the eight demographic groups, and reports group coverage, including how many respondents fall below the age-2 floor that the composite metrics apply.

Usage

eiod_check_demographics(
  age,
  sex,
  age_units = c("years", "months"),
  male = NULL,
  female = NULL
)

Arguments

age

Numeric vector of ages.

sex

Factor, character or numeric vector of sex.

age_units

`"years"` (default) or `"months"`.

male, female

Optional codes; see [eiod_age_sex_group()].

Value

An object of class `eiod_check`.

Details

Like the other check functions, this reports rather than stops. Where [eiod_age_sex_group()] would raise an error, this records it as a finding so you can see every problem in one pass instead of one per run.

Examples

data(eiod_demo)
eiod_check_demographics(eiod_demo$age, eiod_demo$sex)
#> reiod data quality report
#> 
#>   ERROR    0
#>   WARNING  0
#>   NOTE     2
#> 
#>   NOTE     sex            sex          sex is a factor with levels "male", "female". This is the recommended
#>                                        input type.
#>   NOTE     group          coverage     15 respondent(s) under 2 years. Tables 3 and 4 apply to them; HESD and
#>                                        HDLEI do not, and will be NA. Decide explicitly whether they belong in
#>                                        your denominator.
#> 
#>   No blocking problems.

# numeric sex with no codes given: reported, not guessed
eiod_check_demographics(eiod_demo$age,
                        as.integer(eiod_demo$sex == "male"))
#> reiod data quality report
#> 
#>   ERROR    1
#>   WARNING  0
#>   NOTE     0
#> 
#>   ERROR    sex            sex          `sex` is numeric, so reiod cannot tell which code means male.  Observed
#>                                        codes: 0, 1 Survey data uses 1/2 and 0/1 about equally often, and
#>                                        guessing wrong would invert every result without any error.  Either
#>                                        state the codes: eiod_age_sex_group(age, sex, male = 1, female = 2) or
#>                                        convert once, which is the recommended route: dat$sex <-
#>                                        eiod_as_sex_factor(dat$sex, male = 1, female = 2)
#> 
#>   1 blocking problem. Fix before computing metrics.