RR.table | R Documentation |
Make table of Relative Risk results by zone by group by envt risk factor. See source code for notes on this work.
RR.table(
mydat,
Enames = ejscreen::names.e[ejscreen::names.e %in% names(mydat)],
Dnames = ejscreen::names.d[ejscreen::names.d %in% names(mydat)],
popcolname = "pop",
Zcolname,
testing = FALSE,
digits = 4
)
mydat |
Data.frame of input data, one row per geographic unit such as US Census block groups, or tracts. |
Enames |
names of columns with environmental risk factor data, default is names.e from ejscreen package |
Dnames |
names of columns with percent (fraction) of population that is in each given demographic group, default is names.d from ejscreen package |
popcolname |
name of column with total population count, default is pop |
Zcolname |
name of column with name of zone such as US State name |
testing |
default is FALSE |
digits |
Default is 4. How many significant digits to use. |
Compiles RR values in array of 3 dimensions: RRS[Dnames, Enames, Zcolnames]
Returns a matrix with
one demographic group per row,
one environmental risk indicator per column, and
third dimension for which zone (e.g., which US State)
RR()
# (This is very slow right now)
# See examples for [RR.table()] and [RR.means()] and [RR()]
######################################## #
## if just using ejanalysis pkg test data:
bg <- ejanalysis::bgtest
enames <- c("pm", "o3", "cancer", "resp", "dpm", "pctpre1960", "traffic.score",
"proximity.npl", "proximity.rmp", "proximity.tsdf", "proximity.npdes", "ust")
dnames = c("pctlingiso", "pctlowinc")
dnames.subgroups.count = c("hisp", "nhwa", "nhba", "nhaiana",
"nhaa", "nhnhpia", "nhotheralone", "nhmulti")
dnames.subgroups.pct = c("pcthisp", "pctnhwa", "pctnhba", "pctnhaiana",
"pctnhaa", "pctnhnhpia", "pctnhotheralone", "pctnhmulti")
## if EJAM pkg available:
# bg <- as.data.frame(EJAM::blockgroupstats)
# enames = EJAM::names_e
# dnames = EJAM::names_d
# dnames.subgroups.count = EJAM::names_d_subgroups_count
# dnames.subgroups.pct = EJAM::names_d_subgroups
## if EJAM pkg not available and using ejscreen pkg data:
# bg <- ejscreen::bg22
# enames = ejscreen::names.e
# dnames = ejscreen::names.d
# dnames.subgroups.count = ejscreen::names.d.subgroups
# dnames.subgroups.pct = ejscreen::names.d.subgroups.pct
######################################## #
Ratios <- ejanalysis::RR.table(bg, Enames = enames,
Dnames = c(dnames, dnames.subgroups.pct),
popcolname = 'pop', digits = 2)
# done like this, it still has NA values:
MeansByGroup_and_Ratios <- ejanalysis::RR.means(
subset(bg, select = enames),
subset(bg, select = c(dnames, dnames.subgroups.pct)),
bg$pop)
RRS.US <- RR.table(mydat = bg, Enames = enames,
Dnames = c(dnames, dnames.subgroups.pct),
popcolname = 'pop')
RRS.ST <- RR.table(mydat = bg, Enames = enames,
Dnames = c(dnames, dnames.subgroups.pct),
popcolname = 'pop', Zcolname = 'ST')
RRS <- RR.table.add(RRS.ST, RRS.US)
RRS['pctlowinc', , ]
RRS[ , , 'CA'] # RRS[, , 'PR']
RRS[ , 'pm', ]
RRS.REGION <- RR.table(mydat = bg,
Enames = enames,
Dnames = c(dnames, dnames.subgroups.pct),
popcolname = 'pop', Zcolname = 'REGION')
RRS2 <- RR.table.add(RRS, RRS.REGION)
RRS2[ , , '8']
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.