Analyzing US Census Data in R
Kyle Walker
Instructor
get_acs(geography = "county",
variables = c(median_age = "B01002_001"),
state = "OR")
# A tibble: 36 x 5
GEOID NAME variable estimate moe
<chr> <chr> <chr> <dbl> <dbl>
1 41001 Baker County, Oregon median_age 48.2 0.4
2 41003 Benton County, Oregon median_age 32.6 0.3
3 41005 Clackamas County, Oregon median_age 41.4 0.2
4 41007 Clatsop County, Oregon median_age 43.7 0.4
5 41009 Columbia County, Oregon median_age 43.3 0.4
6 41011 Coos County, Oregon median_age 48.2 0.3
7 41013 Crook County, Oregon median_age 48.3 0.7
# ... with 29 more rows
vt_eldpov <- get_acs(geography = "tract",
variables = c(eldpovm = "B17001_016",
eldpovf = "B17001_030"),
state = "VT")
vt_eldpov
# A tibble: 368 x 5
GEOID NAME variable estimate moe
<chr> <chr> <chr> <dbl> <dbl>
1 50001960100 Census Tract 9601... eldpovm 0. 9.
2 50001960100 Census Tract 9601... eldpovf 5. 5.
3 50001960200 Census Tract 9602... eldpovm 0. 9.
4 50001960200 Census Tract 9602... eldpovf 0. 9.
5 50001960300 Census Tract 9603... eldpovm 16. 14.
6 50001960300 Census Tract 9603... eldpovf 5. 7.
# ... with 362 more rows
tidycensus
includes these functions for calculating margins of error:
moe_sum()
: MOE for a derived summoe_product()
: MOE for a derived productmoe_ratio()
: MOE for a derived ratiomoe_prop()
: MOE for a derived proportionvt_eldpov2 <- vt_eldpov %>%
group_by(GEOID) %>%
summarize(
estmf = sum(estimate),
moemf = moe_sum(moe = moe, estimate = estimate))
vt_eldpov2
# A tibble: 184 x 3
GEOID estmf moemf
<chr> <dbl> <dbl>
1 50001960100 5 10.3
2 50001960200 0 9
3 50001960300 21 15.7
4 50001960400 29 11.4
5 50001960500 0 9
# ... with 179 more rows
Analyzing US Census Data in R