ustotals: Get US Totals and Percentages Overall for EJSCREEN Fields

View source: R/ustotals.R

ustotalsR Documentation

Get US Totals and Percentages Overall for EJSCREEN Fields

Description

NOTE: May replace with ustotals2 from batch.summarizer pkg, and or replace to be more generic by using ejscreenformulas style formulas rather than formulas and variable names hard coded in this function.

This function simply takes a data.frame of EJSCREEN demographic data and returns the total count or overall US percentage for various fields, by using the appropriate denominator (universe) to calculate any given percentage. For example, PCTLOWINC.US equals sum(lowinc) / sum(povknownratio), not sum(lowinc) / sum(pop). This function is hard-coded to use specified field names referring to EJSCREEN variables. This function is not needed to create an EJSCREEN dataset, but is convenient if one wants US summary values.

Usage

ustotals(bg)

Arguments

bg

Must be a data.frame that has the following colnames:

  • pop,

  • lowinc,

  • mins,

  • under5,

  • over64,

  • lths,

  • lingiso,

  • pre1960,

  • hisp,

  • nhwa,

  • nhba,

  • nhaiana,

  • nhaa,

  • nhnhpia,

  • nhotheralone,

  • nhmulti,

  • povknownratio,

  • age25up,

  • hhlds,

  • builtunits

Value

Returns a named list of US totals and percentages (as fractions 0-100) (e.g., POP.US=xxxx, etc.):

  • POP.US,

  • LOWINC.US,

  • MINS.US,

  • UNDER5.US,

  • OVER64.US,

  • LTHS.US,

  • LINGISO.US,

  • POVKNOWNRATIO.US # denominator FOR PCTLOWINC,

  • BUILTUNITS.US # denominator FOR PCTPRE1960,

  • HHLDS.US # denominator FOR LINGISO,

  • PRE1960.US,

  • HISP.US,

  • NHWA.US,

  • NHBA.US,

  • NHAIANA.US,

  • NHAA.US,

  • NHNHPIA.US,

  • NHOTHERALONE.US,

  • NHMULTI.US,

  • PCTLOWINC.US,

  • PCTMIN.US,

  • PCTUNDER5.US,

  • PCTOVER64.US,

  • PCTLTHS.US,

  • PCTLINGISO.US,

  • PCTPRE1960.US,

  • PCTHISP.US,

  • PCTNHWA.US,

  • PCTNHBA.US,

  • PCTNHAIANA.US,

  • PCTNHAA.US,

  • PCTNHNHPIA.US,

  • PCTNHOTHERALONE.US,

  • PCTNHMULTI.US

Examples

## Not run: 
# See EJSCREEN demographic variables plus some race/ethnicity subgroups
c1 = ejscreen::ustotals(ejscreen::bg20DemographicSubgroups2014to2018)
c1 = cbind(c1[c1 != 0 & !is.na(c1)])
c2 = ejscreen::ustotals(ejscreen::bg20[!is.na(ejscreen::bg20$ST),])
### c2 = ejscreen::ustotals(ejscreen::bg20[!is.na(ejscreen::bg20$ST) & ejscreen::bg20$ST != 'PR',])
c2 = cbind(c2[c2 != 0 & !is.na(c2)])
US_2014to2018 = unique(rbind(c1, c2))
colnames(US_2014to2018) = 'total_count_or_fraction'
print(US_2014to2018)


 # Display as a nice table with two columns, rounded numbers, rownames and colnames
 tots <- ustotals(bg20)
 tots <- round(cbind(unlist(tots)), 3)
 totrownames <- rownames(tots)[1:16]
 tots <- cbind(tots[1:16], 100 * c(1, tots[17:31]))
 rownames(tots) <- totrownames
 colnames(tots) <- c('count', 'pct')
 tots

## End(Not run)

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