Aggregate paired ACS estimate and MOE columns by group.
Usage
acs_aggregate(
data,
group_var,
value_cols,
moe_cols,
cov_strategy = c("zero", "supplied", "constant"),
cov_value = 0,
conf = 0.9
)Arguments
- data
A data frame containing ACS estimate and MOE columns.
- group_var
Name of the grouping column, supplied as a single string.
- value_cols
Character vector of estimate column names to aggregate.
- moe_cols
Character vector of MOE column names paired with
value_cols.- cov_strategy
Covariance strategy:
"zero","supplied", or"constant".- cov_value
For
"constant", a scalar correlation. For"supplied", a named list of full covariance matrices keyed by estimate column.- conf
Confidence level associated with input and output MOEs.
Details
cov_strategy = "constant" interprets cov_value as a correlation,
not a covariance. This differs from scalar cov arguments in core
propagation functions, where a scalar means an off-diagonal covariance on
the standard-error scale.
Output rows are ordered by first appearance of each group level in data,
not alphabetically.
Examples
tracts <- data.frame(
region = c("north", "north", "south", "south"),
pop = c(1000, 1200, 900, 1100),
pop_moe = c(120, 140, 100, 130)
)
acs_aggregate(tracts, "region", "pop", "pop_moe")
#> region pop pop_moe
#> 1 north 2200 184.3909
#> 2 south 2000 164.0122
acs_aggregate(tracts, "region", "pop", "pop_moe",
cov_strategy = "constant", cov_value = 0.25)
#> region pop pop_moe
#> 1 north 2200 205.9126
#> 2 south 2000 182.7567