Build the EJSCREEN web-app "thresholds" layers (P1..P100 hit counts)
Source:R/calc_ejscreen_threshold_layers.R
calc_ejscreen_threshold_layers.RdProduces the four "threshold map widget" layers requested for the EJSCREEN web
app in issue #395: us_ejindexes, state_ejindexes, us_supplemental, and
state_supplemental. Each layer has one row per block group containing the
per-index percentile ranks plus 100 columns P1..P100 giving, for that block
group, how many of its EJ-index percentile ranks land at each integer
percentile (e.g. if a block group is at the 4th percentile for P_D2_OZONE
and no other D2 index rank is 4, then P4 = 1).
Usage
calc_ejscreen_threshold_layers(
pctiles,
id_col = "bgfips",
layers = c("us_ejindexes", "state_ejindexes", "us_supplemental", "state_supplemental"),
cols_us_ej = names_ej_pctile,
cols_state_ej = names_ej_state_pctile,
cols_us_supp = names_ej_supp_pctile,
cols_state_supp = names_ej_supp_state_pctile,
out_dir = NULL
)Arguments
- pctiles
A data.frame, one row per block group, containing
id_coland the EJ-index percentile-rank columns – for example the output ofcalc_ejscreen_export()(which holdsP_D2_*andP_D5_*), or a merge of the national and state exports so all four column sets are present.- id_col
Name of the block-group id column to carry through. Default
"bgfips".- layers
Which layers to build; any of
"us_ejindexes","state_ejindexes","us_supplemental","state_supplemental".- cols_us_ej, cols_state_ej, cols_us_supp, cols_state_supp
Character vectors of the percentile-rank column names for each layer. Defaults are the EJAM name vectors names_ej_pctile, names_ej_state_pctile, names_ej_supp_pctile, names_ej_supp_state_pctile.
- out_dir
Optional directory; if supplied, each layer is written there as
<layer>.csv.
Value
A named list of data.frames, one per requested layer (the id column +
the percentile-rank columns + P1..P100).
Details
Percentile ranks are rounded to integers and clamped into 1..100 (a rank
that rounds to 0 is counted in P1, anything above 100 in P100, and NA
ranks are not counted), then the number of indexes at each integer percentile
is tallied per block group in a single pass over the data. For ranks already
in 1..100 this equals the colcounter() identity
colcounter(x, k) - colcounter(x, k + 1) (count at-or-above k minus count
at-or-above k + 1), i.e. it is the per-block-group analogue of the
EXCEED_COUNT_* fields in calc_ejscreen_export().
The four layers differ only in which set of percentile columns they tabulate:
us_ejindexes-> names_ej_pctile (national D2 EJ indexes)state_ejindexes-> names_ej_state_pctileus_supplemental-> names_ej_supp_pctile (national supplemental, D5)state_supplemental-> names_ej_supp_state_pctile
In the annual pipeline these layers are produced by the ejscreen_export stage
of calc_ejscreen_dataset() when include_ejscreen_export is TRUE: it calls
calc_ejscreen_threshold_layers_from_exports() on the national and state
exports and saves them under the registered stage names
ejscreen_threshold_us_ejindexes, ejscreen_threshold_us_supplemental,
ejscreen_threshold_state_ejindexes, and
ejscreen_threshold_state_supplemental. (Issue #395 part (a) — the US/State
percentile CSVs — is the existing ejscreen_export / ejscreen_export_statepct;
part (c) — the ACS-by-geography layers — is calc_acs_by_geography().)