get ratios of each site's scores to US means (using output of batch buffering)
Source:R/calc_ratios_to_avg.R
calc_ratios_to_avg.Rd
Used to create input to boxplots_ratios()
and can be used elsewhere now
Arguments
- out
data.frame output from
ejscreenapi_plus()
or fromejscreenapi()
or doaggregate(), one row per buffer or site, and columns for indicators named in evarnames, dvarnames, avg.evarnames, avg.dvarnames- evarnames
vector of variable names for environmental indicators in out, like pm, o3, etc.
- dvarnames
vector of variable names for residential population indicators in out, such as pctlowinc
- zone.prefix
us or state, must fit with colnames in out such as avg.pctlowinc and state.avg.pctlowinc
- avg.evarnames
use only if user-specific variable names are in out, with defaults like avg.pm
- avg.dvarnames
use only if user-specific variable names are in out, with defaults like avg.pctlowinc
Value
a list with ratios_d and ratios_e which are vectors of numbers the lengths of dvarnames and evarnames
Details
Note that colnames returned are same as input, not renamed to say "ratio" If names_d_subgroups are included, those means are not in API output from EJScreen so it gets the means from usastats or statestats
Examples
out <- testoutput_ejscreenit_5$table # has long names
names(out) <- fixcolnames(names(out1),'long','r')
#> Error: object 'out1' not found
out2 <- testoutput_ejscreenapi_plus_5 # has r names already
# these are data.frames, but the colnames are different:
# names like "Demog.Index" but they are ratios
calc_ratios_to_avg(out)$ratios_d
#> US averages for demog subgroups like pcthisp not found (note they are not provided by the EJScreen API)
#> so looking up and adding those, and rescaling as 0-100, which is how ejscreen tables store percentages though not how ejamit() does
#> Warning: some variable names are not found in out - ignoring those
#> Missing from table provided, but expected to see here:
#>
#> Demog: Demog.Index, Demog.Index.Supp, pctlowinc, pctlingiso, pctunemployed, pctlths, pctunder5, pctover64, pctmin, pcthisp, pctnhba, pctnhaa, pctnhaiana, pctnhnhpia, pctnhotheralone, pctnhmulti, pctnhwa, avg.Demog.Index, avg.Demog.Index.Supp, avg.pctlowinc, avg.pctlingiso, avg.pctunemployed, avg.pctlths, avg.pctunder5, avg.pctover64, avg.pctmin
#>
#> Envt: pm, o3, no2, dpm, rsei, traffic.score, pctpre1960, proximity.npl, proximity.rmp, proximity.tsdf, ust, proximity.npdes, drinking, avg.pm, avg.o3, avg.no2, avg.dpm, avg.rsei, avg.traffic.score, avg.pctpre1960, avg.proximity.npl, avg.proximity.rmp, avg.proximity.tsdf, avg.ust, avg.proximity.npdes, avg.drinking
#>
#> Error in calc_ratios_to_avg(out): None of the specified (or expected default if not specified) Variable names were found in the provided dataset
# names like "ratio.to.avg.Demog.Index"
out[ , names_d_ratio_to_avg] # needs EJAM for names_d_ratio_to_avg
#> Error in `[.data.frame`(out, , names_d_ratio_to_avg): undefined columns selected
boxplots_ratios(calc_ratios_to_avg(out)$ratios_d,"pctlowinc","% low income",
wheretext="Within a mile of")
#> US averages for demog subgroups like pcthisp not found (note they are not provided by the EJScreen API)
#> so looking up and adding those, and rescaling as 0-100, which is how ejscreen tables store percentages though not how ejamit() does
#> Warning: some variable names are not found in out - ignoring those
#> Missing from table provided, but expected to see here:
#>
#> Demog: Demog.Index, Demog.Index.Supp, pctlowinc, pctlingiso, pctunemployed, pctlths, pctunder5, pctover64, pctmin, pcthisp, pctnhba, pctnhaa, pctnhaiana, pctnhnhpia, pctnhotheralone, pctnhmulti, pctnhwa, avg.Demog.Index, avg.Demog.Index.Supp, avg.pctlowinc, avg.pctlingiso, avg.pctunemployed, avg.pctlths, avg.pctunder5, avg.pctover64, avg.pctmin
#>
#> Envt: pm, o3, no2, dpm, rsei, traffic.score, pctpre1960, proximity.npl, proximity.rmp, proximity.tsdf, ust, proximity.npdes, drinking, avg.pm, avg.o3, avg.no2, avg.dpm, avg.rsei, avg.traffic.score, avg.pctpre1960, avg.proximity.npl, avg.proximity.rmp, avg.proximity.tsdf, avg.ust, avg.proximity.npdes, avg.drinking
#>
#> Error in calc_ratios_to_avg(out): None of the specified (or expected default if not specified) Variable names were found in the provided dataset