ej.indexes | R Documentation |
Create an index that combines environmental and demographic indicators for each Census unit (e.g., block group).
ej.indexes(
env.df,
demog,
weights,
us.demog,
universe.us.demog,
as.df = TRUE,
prefix = "EJ.DISPARITY.",
type = 1,
na.rm = FALSE
)
env.df |
Environmental indicators vector or numeric data.frame, one column per environmental factor, one row per place (e.g., block group). |
demog |
Demographic indicator(s) vector or data.frame, numeric fractions of population that is in specified demographic group (e.g., fraction below poverty line), one per place. |
weights |
Optional, and default is equal weighting. If us.demog and universe.us.demog are not specified, weights are used to find weighted mean of demog to use as area-wide overall average (e.g., population-weighted average percent Hispanic, for all block groups in USA). One weight per place. |
us.demog |
Optional overall area-wide value for demog percentage share of population as fraction 0 to 1 (e.g., US Demographic Indicator). The correct value to use for EJScreen 2.0, for example, is with(ejscreen::bg21, ( sum(mins)/sum(pop) + sum(lowinc)/sum(povknownratio) ) / 2) Default is to approximate it as weighted mean of demog, where the weights are universe.us.demog if specified, or else just 'weights'. If the weights are population counts and demog is percent Hispanic, for example, us.demog is the percent of US population that is Hispanic. |
universe.us.demog |
Optional numeric vector. If specified and us.demog not specified, used instead of weights to get weighted mean of demog to find area-wide demog. This should be the actual denominator, or universe, that was used to create percent demog – universe.us.demog if specified should be a vector that has the count, for each place, of the denominator for finding the US overall percent and this may be slightly different than total population. For example if demog=places$pctlowinc then true universe.us.demog=places$povknownratio which is the count for whom poverty ratio is known in each place, which is <= pop. |
as.df |
Default is TRUE. |
prefix |
Optional character string used as first part of each colname in results. Default is "EJ.DISPARITY." |
type |
Specifies type of EJ Index. Default is type=1. Several formulas are available:
where
|
na.rm |
Default is FALSE. NOTE: This is complicated but important. See notes in source code about handling NA values in various formulas here. |
Creates one EJ index column for each environmental indicator column,
or if given a vector or single column of environmental indicators instead of data.frame, returns a vector or column.
Each "place" can be a Census unit such as a State, County, zip code, tract, block group, block, for example (or even by individual if person-level data are available).
Note: For 1.5, 3.5, 4.5 need vector d.avg.all.elsewhere. calculated in each of those.
But does not properly handle cases where us.demog or universe.us.demog specified because denominator is not same as pop
and need to fix for when is.na(p) | is.na(demog)
Type 2 however does handle NA values appropriately, meaning a result for a given col of env.df is set to NA for a given row
(assuming na.rm=FALSE) if and only if NA is found in that row, in demog or weights or that one col of env.df.
Returns a numeric data.frame (or matrix if as.df=FALSE
) of EJ indexes, one per place per environmental indicator.
statedat <- data.frame(state.x77)
hist(myej <- ej.indexes(env.df=statedat[ , c('Life.Exp', 'Frost')],
demog=statedat$HS.Grad/100, weights=statedat$Population, prefix='EJtype1.', type=1 ))
set.seed(999)
myej <- ej.indexes(env.df=rnorm(1000, 10, 3), demog=runif(1000, 0, 1),
weights=runif(1000, 500, 5000))
myej
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.