使用
我收到了以下错误信息:
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
。我们不需要看到您如何获取数据,尝试创建一个小的可重现数据,可以生成相同的错误,例如dput(head(impList))
。 - zx8754svydesign
,但我不知道为什么。我正在遵循?imputationList
中的示例,其中包括imputationList(datasets,...)
。通常我会使用小的可重现示例,但这更加复杂(例如,填充数据、调查权重),我认为最好使用真实世界的数据,因为很难重新创建完全相同的情况。 - scottsmithlibrary(survey)
。 - Anthony Damico