在 R 中面临调查包版本 4.2.2 的问题,得到标准错误 Inf 并带有警告消息。
我使用的数据集具有多阶段分层,并且必须针对一个或多个层进行调整,其中有一个 PSU,我使用选项进行调整(survey.lonely.psu =“调整”)。下面是我想要得到的调查设计和估计
#creating country design
c_design=svydesign(id=~PSU_ID,strata=~STATE_STRATUM,weights=~c_weight,data=df,nest = TRUE)
#creating state design
s_design=svydesign(id=~PSU_ID,strata=~STATE_STRATUM,weights=~s_weight,data=df,nest = TRUE)
#Generating estimate at country level
est_country=svyby(formula = ~constant,by=~country+VAR_1,design = c_design,FUN = svytotal)
我收到的警告消息如下所示
Warning messages:
1: In tapply(X = nPSU, INDEX = as.numeric(strata), FUN = head, 1) :
NAs introduced by coercion
2: In tapply(X = nPSU, INDEX = as.numeric(strata), FUN = head, 1) :
NAs introduced by coercion
3: In tapply(X = nPSU, INDEX = as.numeric(strata), FUN = head, 1) :
NAs introduced by coercion
4: In tapply(X = nPSU, INDEX = as.numeric(strata), FUN = head, 1) :
NAs introduced by coercion```
在输出中,标准错误以 Inf 形式出现,而使用之前的版本 4.2.1 标准错误以数字形式出现,没有警告消息。
您需要使用因子变量而不是字符串作为层变量,例如
c_design=svydesign(id=~PSU_ID,strata=~factor(STATE_STRATUM),weights=~c_weight,data=df,nest = TRUE)