使用重复权重确定PUMS数据的直接标准错误

我正在与2010 – 2014年5年PUMS数据。 我正在尝试使用复制权重来查找标准错误。 标准错误公式是在文档中,但我遇到了麻烦把它转换为Microsoft Excel或R,我正在使用的两个程序的公式。 我可以在Excel中交叉expression两个variables来获得每个重复重量和PWGTP的总和,但我想有一个更简单的方法。

有没有人在这里与PUMS数据和重复的权重? 文档可以在这里find:

http://www.census.gov/programs-surveys/acs/technical-documentation/pums/documentation.2014.html

在R中,你可以做这样的事情:

wgt <- "PWGTP" var <- "SEX" est <- aggregate(PUMS[[wgt]], by=list(PUMS[[var]]), FUN=sum, simplify=T, drop=F) err <- vector("list", 80) for(i in 1:80){ err[[i]] <- aggregate(PUMS[[paste0(wgt, i)]], by=list(PUMS[[var]]), FUN=sum, simplify=T, drop=F) err[[i]] <- (err[[i]][,2] - est[,2])**2 } SE <- ((4/80)*colSums(do.call(rbind, err)))**.5 

这是假设您正在使用人员logging和计算variablesSEX SE。

还有其他计算平均数,中位数,比例等的SE的公式。这里使用的公式可能是最常用的公式,所以我假定这是你正在查询的那个公式。

surveysrvyr软件包将对你有用。

 library(tidyverse) library(survey) library(srvyr) hga <- read_csv("ss11hga.csv") # georgia, but it will be the same for you # survey design, specifying replicate weights pumsd_hh <- hga %>% as_survey_rep( weights = WGTP, repweights = starts_with("WGTP"), combined_weights = TRUE ) # calculate average income and standard error by size of household pumsd_hh %>% filter(!is.na(FINCP)) %>% mutate(NP = ifelse(NP > 5, 5, NP)) %>% group_by(NP) %>% summarise( survey_mean(FINCP, na.rm = TRUE) ) 
Interesting Posts