【发布时间】:2018-07-07 12:24:39
【问题描述】:
使用survey 包,我在创建imputationList 时遇到问题svydesign 将接受。这是一个可重现的示例:
library(tibble)
library(survey)
library(mitools)
# Data set 1
# Note that I am excluding the "income" variable from the "df"s and creating
# it separately so that it varies between the data sets. This simulates the
# variation with multiple imputation. Since I am using the same seed
# (i.e., 123), all the other variables will be the same, the only one that
# will vary will be "income."
set.seed(123)
df1 <- tibble(id = seq(1, 100, by = 1),
gender = as.factor(rbinom(n = 100, size = 1, prob = 0.50)),
working = as.factor(rbinom(n = 100, size = 1, prob = 0.40)),
pweight = sample(50:500, 100, replace = TRUE))
# Data set 2
set.seed(123)
df2 <- tibble(id = seq(1, 100, by = 1),
gender = as.factor(rbinom(n = 100, size = 1, prob = 0.50)),
working = as.factor(rbinom(n = 100, size = 1, prob = 0.40)),
pweight = sample(50:500, 100, replace = TRUE))
# Data set 3
set.seed(123)
df3 <- tibble(id = seq(1, 100, by = 1),
gender = as.factor(rbinom(n = 100, size = 1, prob = 0.50)),
working = as.factor(rbinom(n = 100, size = 1, prob = 0.40)),
pweight = sample(50:500, 100, replace = TRUE))
# Create list of imputed data sets
impList <- imputationList(df1,
df2,
df3)
# Apply NHIS weights
weights <- svydesign(id = ~id,
weight = ~pweight,
data = impList)
我收到以下错误:
Error in eval(predvars, data, env) :
numeric 'envir' arg not of length one
【问题讨论】:
-
错误来自
svydesign。我们不需要查看您是如何获取数据的,尝试创建一个小的reproducible data 会产生相同的错误,可能是dput(head(impList))。 -
是的,错误来自
svydesign,但我不知道为什么。我正在关注?imputationList中的示例,其中imputationList(datasets,...)。通常我会使用小的可重现示例,但这更复杂(例如,估算数据、调查权重),我认为最好使用真实世界的数据,因为很难重现确切的情况。 -
@zx8754 这不是重复的.. 问题特定于
library(survey) -
@AnthonyDamico 我从错误消息中说“可能”,以便 OP 可以探索链接的帖子是否有帮助。
标签: r survey imputation