简体   繁体   English

如何在 R 中应用与 NIS(国家住院患者样本)相关的权重

[英]How to apply weights associated with the NIS (National inpatient sample) in R

I am trying to apply weights given with NIS data using the R package "survey", but I have been unsuccessful.我正在尝试使用 R package“调查”应用 NIS 数据给出的权重,但我没有成功。 I am fairly new to R and survey commands.我对 R 和调查命令相当陌生。

This is what I have tried:这是我尝试过的:

# Create the unweighted dataset
d <- read.dta13(path) 

# This produces the correct weighted amount of cases I need.
sum(d$DISCWT) # This produces the correct weighted amount of cases I need.

library(survey)

# Create survey object
dsvy <- svydesign(id = ~ d$HOSP_NIS, strata = ~ d$NIS_STRATUM, weights = ~ d$DISCWT, nest = TRUE, data = d) 
d$count <- 1
svytotal(~d$count, dsvy)

However I get the following error after running the survey total:但是,在运行调查总数后出现以下错误:

Error in onestrat(x[index, , drop = FALSE], clusters[index], nPSU[index][1],  : 
 Stratum (1131) has only one PSU at stage 1

Any help would be greatly appreciated, thank you!任何帮助将不胜感激,谢谢!

The error indicates that you have specified a design where one of the strata has just a single primary sampling unit.该错误表明您指定了一个设计,其中一个层只有一个初级抽样单位。 It's not possible to get an unbiased estimate of variance for a design like that: the contribution of stratum 1131 will end up as 0/0.对于这样的设计,不可能获得无偏的方差估计:第 1131 层的贡献最终将是 0/0。

As you see, R's default response is to give an error, because a reasonably likely explanation is that the data or the svydesign statement is wrong.如您所见,R 的默认响应是给出错误,因为合理可能的解释是数据或svydesign语句是错误的。 Sometimes, as here, that's not what you want, and the global option 'survey.lonely.psu' describes other ways to respond.有时,就像这里一样,这不是您想要的,全局选项“survey.lonely.psu”描述了其他响应方式。 You want to set你想设置

options(survey.lonely.psu = "adjust")

This and other options are documented at help(surveyoptions)此选项和其他选项记录在help(surveyoptions)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM