group.estimate: Compute estimates and standard errors on grouped ACS PUMS...

Description Usage Arguments Value Examples

View source: R/group.estimate.R

Description

Collect point estimate, standard error and 90 any statistic across groups defined by gp.var and (optionally) over the whole data. If x is grouped already, gp.var is added to the grouping, but in this case, gp.var can be NULL, which does not add a new grouping.

Usage

1
2
group.estimate(x, f, gp.var, ..., result.name = NULL, drop.na.group = FALSE,
  include.total = TRUE)

Arguments

x

a data frame of PUMS data. If x is already grouped, then this function optionally adds a level to the grouping.

f

a function to calculate the statistic. It must take data and a weight replicate number called wt.rep.num with a default value of NULL.

gp.var

name of variable in x to group data by (string) or NULL if x is grouped and you do not want to add a level of grouping. May not be NULL if x is not grouped.

...

other data passed to f

result.name

name of estimate column in result. Default of NULL uses deparse(substitute(f)).

drop.na.group

default FALSE, drop the group where gp.var is NA

include.total

include the total across all groups, default TRUE

Value

data frame of estimate, standard error of the estimate, and the margin of error of the estimate, for the statistic defined by 'f', over the groups defined by gp.var and (optionally) the whole data.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Total of occupied households in Washington State in 2016
group.estimate(wa.house16, estimate, 'TEN', drop.na.group=TRUE)

# 90% household income by tenure type for Washington State in 2016
group.estimate(wa.house16, acs.quantile, 'TEN', field='HINCP',
               probs=0.9, result.name='HH.Inc90', drop.na.group = TRUE)

# First example, with data already grouped using group_by
library(dplyr)
gp <- group_by(wa.house16, TEN)
group.estimate(gp, estimate, NULL, drop.na.group=TRUE)

davidthaler/PUMSutils documentation built on July 13, 2019, 9:58 a.m.