为什么我不能使用 R 包 acs 从 SF1 获得国家和 ZCTA 级别的估计?

Why can't I get national and ZCTA-level estimates from SF1 using R package acs?

以下作品:

acs::acs.fetch(dataset = "acs",
               endyear = 2015, 
               span = 5,
               geography = acs::geo.make(zip = "*"),
               variable = "B01001_001")

这也是:

acs::acs.fetch(dataset = "sf1",
               endyear = 2010,
               span = 0,
               geography = acs::geo.make(state = "*"),
               variable = "PCT0120001")

请向我解释为什么以下内容不起作用,因为这不是因为人口普查 API 没有可用的邮政编码级别估计值。我是否需要以不同方式指定地理区域才能从 sf1 获得国家和 ZCTA 级别的估计值,而不是从人口普查中的 acs5 获得国家级和 ZCTA 级估计值 API?

acs::acs.fetch(dataset = "sf1",
               endyear = 2010,
               span = 0,
               geography = acs::geo.make(zip = "*"),
               variable = "PCT0120001")
# Error in file(file, "rt") : cannot open the connection
# In addition: Warning message:
# No data found at:
#   http://api.census.gov/data/2010/sf1?key=2dd03c4048ca2edb8463d8c0bbdc09c5eb3b4013&get=PCT0120001,NAME&for=zip+code+tabulation+area:*

acs::acs.fetch(dataset = "sf1",
               endyear = 2010,
               span = 0,
               geography = acs::geo.make(us = "*"),
               variable = "PCT0120001")
# Error in file(file, "rt") : cannot open the connection
# In addition: Warning message:
# No data found at:
#   http://api.census.gov/data/2010/sf1?key=2dd03c4048ca2edb8463d8c0bbdc09c5eb3b4013&get=PCT0120001,NAME&for=us:* 

这似乎是 2010 年十年一次的人口普查的局限性 API - 无法通过 API 获得整个美国的数据,ZCTA 数据只能按州获得。参见 http://api.census.gov/data/2010/sf1/geography.html

您可以使用 totalcensus package 下载摘要文件并提取每个邮政编码中的数据。数据下载到您自己的计算机上,因此对数据的访问不受人口普查的限制API。

library(totalcensus)
aaa <- read_decennial(
    year = 2010,
    states = "US",
    table_contents = "PCT0120001",
    geo_headers = "ZCTA5",
    summary_level = "860"
)


print(aaa)

#               lon      lat ZCTA5 state population PCT0120001 GEOCOMP SUMLEV
#     1:  -66.74996 18.18056 00601    NA      18570      18570     all    860
#     2:  -67.17613 18.36227 00602    NA      41520      41520     all    860
#     3:  -67.11989 18.45518 00603    NA      54689      54689     all    860
#     4:  -66.93291 18.15835 00606    NA       6615       6615     all    860
#     5:  -67.12587 18.29096 00610    NA      29016      29016     all    860
# ---                                                                     
# 33116: -130.04103 56.00232 99923    NA         87         87     all    860
# 33117: -132.94593 55.55020 99925    NA        819        819     all    860
# 33118: -131.47074 55.13807 99926    NA       1460       1460     all    860
# 33119: -133.45792 56.23906 99927    NA         94         94     all    860
# 33120: -131.60683 56.41383 99929    NA       2338       2338     all    860