A helper that captures a bare deprivation cutoff expression and
optional per-indicator settings for use inside the deprivations
argument of compute_mpi.
Arguments
- .cutoff
A bare logical expression evaluated against the indicator's data frame. Rows where this evaluates to
TRUEare considered deprived.- .data
An optional data frame to use for this indicator instead of the primary
.datapassed tocompute_mpi. Useful when one or more indicators are at a different unit of analysis (e.g. person-level roster).- collapse_fn
An optional function applied to collapse roster-level data to the unit-of-analysis level (e.g.
maxto flag a household as deprived if any member is deprived). IfNULL(default), no collapsing is performed. NAs are removed before calling the function; if all values areNAthe result isNA.- set_na_equal_to
Coerce
NAdeprivation values to0(not deprived, default) or1(deprived).- ...
Reserved; passing old dotted names (e.g.
.collapse_fn) triggers a helpful error.
Examples
deprived(drinking_water == 2)
#> $cutoff
#> <quosure>
#> expr: ^drinking_water == 2
#> env: 0x55a5723bb928
#>
#> $data
#> NULL
#>
#> $collapse_fn
#> NULL
#>
#> $set_na_equal_to
#> [1] 0
#>
#> attr(,"class")
#> [1] "mpi_d"
deprived(undernourished == 1 & age < 70, .data = df_household_roster, collapse_fn = max)
#> $cutoff
#> <quosure>
#> expr: ^undernourished == 1 & age < 70
#> env: 0x55a5723bb928
#>
#> $data
#> # A tibble: 905 × 8
#> uuid line_number class sex age attending_school undernourished
#> <chr> <int> <chr> <chr> <int> <int> <int>
#> 1 5dbec60a-ebda-… 1 Rural Male 55 NA 2
#> 2 5dbec60a-ebda-… 2 Rural Fema… 48 NA 2
#> 3 5dbec60a-ebda-… 3 Rural Fema… 17 1 2
#> 4 5dbec60a-ebda-… 4 Rural Male 10 1 2
#> 5 8b70c208-8642-… 1 Rural Fema… 30 NA 2
#> 6 8b70c208-8642-… 2 Rural Male 26 NA 2
#> 7 8b70c208-8642-… 3 Rural Male 3 NA 2
#> 8 8b70c208-8642-… 4 Rural Male 19 1 2
#> 9 aa7cb64d-ba16-… 1 Rural Male 66 NA 2
#> 10 aa7cb64d-ba16-… 2 Rural Fema… 62 NA 2
#> # ℹ 895 more rows
#> # ℹ 1 more variable: completed_6yrs_schooling <int>
#>
#> $collapse_fn
#> function (..., na.rm = FALSE) .Primitive("max")
#>
#> $set_na_equal_to
#> [1] 0
#>
#> attr(,"class")
#> [1] "mpi_d"