Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在r中使用mice包时如何解决此错误?_R_Statistics_Missing Data_Imputation_R Mice - Fatal编程技术网

在r中使用mice包时如何解决此错误?

在r中使用mice包时如何解决此错误?,r,statistics,missing-data,imputation,r-mice,R,Statistics,Missing Data,Imputation,R Mice,我试图为一组分类变量和数值变量估算缺失值。 我使用的代码如下: sapply(data, function(x) sum(is.na(x))) library(dplyr) data1 <- data %>% mutate( Age = as.numeric(Age), Sex = as.factor(Sex), BMI = as.numeric(BMI), Smoking = as.factor(Smoking), Alcohol =

我试图为一组分类变量和数值变量估算缺失值。 我使用的代码如下:

sapply(data, function(x) sum(is.na(x)))

library(dplyr) 
data1 <- data %>%
  mutate(
    Age = as.numeric(Age),
    Sex = as.factor(Sex),
    BMI = as.numeric(BMI),
    Smoking = as.factor(Smoking),
    Alcohol = as.factor(Alcohol),
    HIV = as.factor(HIV),
    DM = as.factor(DM),
    Outcome = as.factor(Outcome),
    
      )

library(mice)
init = mice(data1, maxit=0) 
meth = init$method
predM = init$predictorMatrix

meth[c("Age", "BMI")]="norm" 
meth[c("Sex", "Smoking", "Alcohol", "HIV", "DM", "Outcome")]="logreg" 

set.seed(123)
imputed = mice(data1, method=meth, predictorMatrix=predM, m=5)

imputed1 <- complete(imputed)
sapply(数据、函数(x)和(is.na(x)))
图书馆(dplyr)
数据1%
变异(
年龄=作为数字(年龄),
性别=作为因素(性别),
BMI=作为数值(BMI),
吸烟=作为因素(吸烟),
酒精=as.因子(酒精),
HIV=as.因子(HIV),
DM=总系数(DM),
结果=作为因素(结果),
)
图书馆(mice)
初始化=鼠标(数据1,最大值=0)
meth=init$方法
predM=init$predictor矩阵
方法[c(“年龄”、“体重指数”)]=正常值
方法[c(“性”、“吸烟”、“酒精”、“艾滋病毒”、“糖尿病”、“结果”)]=“logreg”
种子集(123)
插补=小鼠(数据1,方法=meth,预测矩阵=predM,m=5)

插补1错误发生在哪里?@dcarlson当我运行此命令时:插补=小鼠(数据1,方法=meth,预测矩阵=predictMatrix=predM,m=5)如果只使用默认值运行它是否有效:
插补=小鼠(数据1)