ejscreen.create: Replicate or Create EJSCREEN-like dataset from your own...

View source: R/ejscreen.create.R

ejscreen.createR Documentation

Replicate or Create EJSCREEN-like dataset from your own Environmental and Demographic Data

Description

NOTE : does not include demographic subgroups yet see names.d.subgroups

The EJSCREEN dataset each year is already available as a dataset in this package (as bg21 for example). But if you want to recreate that kind of dataset from your own environmental data (and demographic data), this function does that. This function ejscreen.create() starts with raw environmental indicator data, and/or ACS demographics, and will create (or replicate) a full EJSCREEN dataset. The ACS demographics, if not provided to the function, are downloaded from Census and calculated by this function. The ACS 5-year summary file is used to obtain block group estimates of population count, minorities, low-income, etc. The source code for this function also contains further comments with an outline of steps involved. It relies on ejscreen.acsget() which relies on ACSdownload::get.acs(), and uses ejanalysis::addFIPScomponents() to add FIPS.TRACT, countyname, etc., and also uses ejanalysis::make.bin.pctile.cols, ejanalysis::ej.indexes(), ejanalysis::flagged(), etc. @details **Note that if non-default fieldnames are used in e and/or acsraw, those must be specified in parameters including demogvarname0, wtsvarname, keep.old (and could be reflected in prefix and suffix params as well).

This function does not create lookup tables that are used in EJSCREEN to convert a raw score in a buffer to a US,Region,or state percentile. Use ejscreen.lookuptables() to create those lookup tables of 100 population weighted percentiles and mean, for US and each EPA Region and each State; for each raw score.

Usage

ejscreen.create(
  e,
  acsraw,
  folder = getwd(),
  keep.old,
  formulas,
  mystates = "all",
  popup = FALSE,
  write.lookup.us = FALSE,
  write.lookup.regions = FALSE,
  write.lookup.states = FALSE,
  demogvarname0 = "VSI.eo",
  wtsvarname = "pop",
  checkfips = TRUE,
  EJprefix0 = "EJ.DISPARITY",
  EJprefix1 = NULL,
  EJprefix2 = NULL,
  ejformulasfromcode = FALSE,
  ejtype = 1,
  demogvarname0suffix = "eo",
  end.year,
  addflag = FALSE,
  threshold = 0.8,
  thresholdfieldnames,
  ...
)

Arguments

e

Data.frame of raw data for environmental indicators, one row per block group, one column per indicator.

acsraw

Optional data.frame of raw demographic indicators. Downloaded if not provided as parameter.

folder

Optional, default is getwd(). Passed to ACSdownload::get.acs() if demog data must be downloaded. Passed to but not currently used by ejscreen.acs.rename which uses analyze.stuff::change.fieldnames() in analyze.stuff package. Not currently passed to ejscreen.acs.calc which uses analyze.stuff::calc.fields() in analyze.stuff package.

keep.old

optional vector of colnames from e that are to be used/returned. For nondefault colnames, this must be used.

formulas

optional, see ejscreen.acs.calc for details. Defaults are in ejscreenformulas$formula Note that if formulas is specified, ejformulasfromcode is ignored.

mystates

optional vector of 2-letter state abbreviations. Default is "all" which specifies all states plus DC (BUT NOT PR - we exclude PR so that calculating US percentiles works right)

popup

optional, default is FALSE, whether to add columns of text that can be used for popup info on maps, with raw value and percentile and units for each envt, demog, and EJ indicator (US Percentiles only?)

write.lookup.us

whether to save file with lookup table of US percentiles and means

write.lookup.regions

whether to save file with lookup table of REGION percentiles and means

write.lookup.states

whether to save file with lookup table of State percentiles and means

demogvarname0

optional, default is "VSI.eo" used as demographic indicator for EJ Indexes. Must be a colname in acsraw or created and kept by formulas.

wtsvarname

optional, default is "pop" used for weighted percentiles, etc. Must be a colname in acsraw or created and kept by formulas.

checkfips

optional, default is TRUE. If TRUE, function checks to verify all FIPS codes appear to be valid US FIPS (correct number of characters, adding any leading zero needed, and checking the first five to ensure valid county). To use something other than actual US FIPS codes, set this to FALSE.

EJprefix0

optional, default is "EJ.DISPARITY" - specifies prefix for colnames of main EJ Indexes, with a period separating prefix from body of colname

EJprefix1

optional, default is NULL, none used (old way was "EJ.BURDEN" - specifies prefix for colnames of Alternative 1 version of EJ Indexes, with a period separating prefix from body of colname)

EJprefix2

optional, default is NULL, none used (old way was "EJ.PCT" - specifies prefix for colnames of Alternative 2 version of EJ Indexes, with a period separating prefix from body of colname)

ejformulasfromcode

optional, default is FALSE. If TRUE, use EJ Index formulas built into this function instead of the EJ Index formulas in ejscreenformulas. The parameters such as demogvarname0 are only used if ejformulasfromcode=TRUE. Note that if formulas is specified, ejformulasfromcode is ignored.

ejtype

optional, default is 1, defines which formula to use for ejindex if not using ejscreenformulas. See ejanalysis::ej.indexes But note alt1 and alt2 still use type 5 and 6 ignoring ejtype.

demogvarname0suffix

optional, default is "eo" - specifies suffix for colnames of EJ Indexes based on demogvarname0, with a period separating body of colname from suffix

end.year

optional to pass to ACSdownload::get.acs() such as end.year="2013" – otherwise uses default year used by ACSdownload::get.acs()

addflag

optional, default is FALSE. Set to TRUE to add a column (called "flagged") to results that is TRUE when one or more of certain percentiles (US EJ Index) in a block group (row) exceed cutpoint. A field called flagged can also be added via ejanalysis::flagged() ejanalysis::flagged() or via ejscreen.download( addflag = TRUE )

threshold

optional, default is 0.80 (80th percentile). If addflag == TRUE, then threshold defines the threshold against which percentiles are compared.

thresholdfieldnames

optional, default is standard EJSCREEN EJ Indexes built into code. Otherwise, vector of character class fieldnames, specifying which fields to compare to threshold if addflag is TRUE.

...

optional extra parameters passed only to ACSdownload::get.acs such as new.geo = FALSE, save.files = TRUE, write.files = TRUE

Value

Returns a data.frame with full ejscreen dataset of environmental and demographics indicators, and EJ Indexes, as raw values, US percentiles, but not actually the text for map popups. Output has one row per block group.

See Also

ejscreen.lookuptables

Examples

 ## Not run: 
 set.seed(99)
 envirodata=data.frame(FIPS=analyze.stuff::lead.zeroes(1:1000, 12),
   air=rlnorm(1000), water=rlnorm(1000)*5, stringsAsFactors=FALSE)
 demogdata=data.frame(FIPS=analyze.stuff::lead.zeroes(1:1000, 12),
   pop=rnorm(n=1000, mean=1400, sd=200), mins=runif(1000, 0, 800),
   num2pov=runif(1000, 0,500), stringsAsFactors=FALSE)
 demogdata$povknownratio <- demogdata$pop
 # downloads ACS demographics and combines with user provided envirodata:
 # bg1=ejscreen.create(envirodata, mystates=c("de","dc"))
 # currently does not work for nonstandard colnames
 #  unless keep.old used as follows (work in progress):
 y=ejscreen.create(e=envirodata, acsraw=demogdata,
   keep.old = c(names(envirodata), names(demogdata)),
   demogvarname0 = "pctmin",wtsvarname = "pop" )

 
## End(Not run)

ejanalysis/ejscreen documentation built on April 2, 2024, 10:15 a.m.