to_survey: Convert a data frame returned by get_pums() to a survey...

Description Usage Arguments Value Examples

View source: R/pums.R

Description

This helper function takes a data frame returned by get_pums and converts it to a tbl_svy from the srvyr as_survey package or a svyrep.design object from the svrepdesign package. You can then use functions from the srvyr or survey to calculate weighted estimates with replicate weights included to provide accurate standard errors.

Usage

1
2
3
4
5
6
to_survey(
  df,
  type = c("person", "housing"),
  class = c("srvyr", "survey"),
  design = "rep_weights"
)

Arguments

df

A data frame with PUMS person or housing weight variables, most likely returned by get_pums.

type

Whether to use person or housing-level weights; either "housing" or "person" (the default).

class

Whether to convert to a srvyr or survey object; either "survey" or "srvyr" (the default).

design

The survey design to use when creating a survey object. Currently the only option is code"rep_weights"/.

Value

A tbl_svy or svyrep.design object.

Examples

1
2
3
4
5
6
## Not run: 
pums <- get_pums(variables = "AGEP", state = "VT", rep_weights = "person")
pums_design <- to_survey(pums, type = "person", class = "srvyr")
survey::svymean(~AGEP, pums_design)

## End(Not run)

tidycensus documentation built on Sept. 24, 2021, 1:07 a.m.