View source: R/ejscreen.lookuptables.R
ejscreen.lookuptables | R Documentation |
*** Was work in progress as of 2022 ...maybe this has more useful code in some parts
see also:
ejanalysis::write.wtd.pctiles.by.zone
ejscreen::ejscreen.lookuptables
ejscreen/inst/SCRIPT_pctilelookups_Create new lookup tables for EJScreen 2.0.R
ejscreen/inst/SCRIPT_pctilelookups_read-downloaded-pctile-lookups.R
will recode to use
ejanalysis::write.wtd.pctiles.by.zone
and see
table.pop.pctile and
map service with lookup tables
or check gdb for lookup tables?
Start with raw environmental, demographic, and EJ indicator data, and write as csv files to disk a series of lookup tables that show population percentiles and mean values for each indicator.
ejscreen.lookuptables(
x,
weights,
cols,
zonecols = c("ST", "REGION"),
zoneOverallName = "USA",
folder = getwd(),
filename1 = "lookupUSA",
filenameprefix = "lookup",
savefilezoneset = TRUE,
savefileperzone = FALSE,
missingcode = NA
)
x |
Data.frame of indicators, one row per block group, one column per indicator. |
weights |
Weights for percentiles – Default is x$pop (if found in x, otherwise no weights) (population count to provide population percentiles.) |
cols |
Optional vector of colnames of x that need percentile lookup tables, or |
zonecols |
Optional. Must set to NULL if no zones wanted, because default is |
zoneOverallName |
Name of entire domain to use in table column called REGION. Default is USA. |
folder |
Default is |
filename1 |
specifies name of file saved, but .csv is added after this |
filenameprefix |
specifies first part of names of files saved for zones |
savefilezoneset |
Save a file for the entire set of zones of one type, like 1 file containing stats on all states |
savefileperzone |
Save one file for each zone, like each state |
missingcode |
Leave this unspecified if missing values are set to NA in the input data. Default is -9999999 (but if already NA then do not specify anything for this). The number or value in the input data that designates a missing value. |
As of mid-2022 EJScreen was changing from pop weighted to unweighted percentiles, and changing so low tied values are 0th and percentile will mean percent <x not percent <= x
Percentiles are calculated as exact values and then rounded down to the nearest 0-100 percentile. This calculates percentiles among only the non-NA values. In other words, people in places with missing data are excluded from the calculation. This means the percentile is the percent of people with valid data (i.e., not NA) who have a tied or lower value.
Overall lookup table(s) as data.frame (but not zonal ones). Creates lookup tables saved as csv files to specified folder. One table for overall percentiles, and one for each of the zonecols (unless that is set to NULL).
## Not run:
# ejscreen dataset:
bg <- bg22
out <- ejscreen.lookuptables(ejscreen::bg[bg$REGION %in% 2:3,], weights=bg$pop[bg$REGION %in% 2:3,])
# Try with a sample envt data set:
set.seed(99)
envirodata <- data.frame(FIPS=analyze.stuff::lead.zeroes(1:1000, 12),
pm = runif(1000,5,20), o3 = runif(1000,3,50),
air=rlnorm(1000), water=rlnorm(1000)*5, stringsAsFactors=FALSE)
demogdata <- data.frame(FIPS=analyze.stuff::lead.zeroes(1:1000, 12),
pop = rlnorm(1000, meanlog = log(1000), sdlog = 1), stringsAsFactors=FALSE)
x <- ejscreen.lookuptables(envirodata, weights=demogdata$pop, cols='all', zonecols=NULL)
x
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.