R中使用MICE插补方法的权重过多

时间:2019-10-10 13:10:05

标签: r r-mice

library(DBI)
    library(RPostgreSQL)
    library(readr)
    library(tidyverse)
    library(dplyr)
    library(lubridate)
    library(rpart)
    library(rpart.plot)
    library(caret)
    library(RANN)
    library(readxl)
    library(mice)

data <- read_excel("Dataset - LBP RA.xlsx", sheet = "Training Dataset") %>%
  mutate(Treatment = as.factor(Treatment))%>%
  mutate(Age = as.factor(Age))%>%
  select(-c('Response_totaal')) 

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

LogReg <- data
LogReg <- LogReg %>% mutate_if(is.numeric, as.factor)
LogReg <- LogReg %>% mutate(Decreased_mobility = as.numeric(Decreased))
str(LogReg)

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

predM[, c("Treatment")]=0
meth[c("Earlier_hospitalization", "Age", "Neurogenic_signals", "arm_right_pain_intensity", "Paidwork", "Stress", "Uses_analgesics", "Continuous_pain", "neck_pain_intensity", "leg_left_pain_intensity", "Familiy_history", "Decreased_mobility", "low_back_pain_intensity", "leg_right_pain_intensity", "Sick_leave", "Depression", "Nocturnal_pain", "Failure_symptoms", "arm_left_pain_intensity")]=""
meth[c("Extremely_nervous", "Irrational_thoughts_work", "Weightloss_per_year", "Coping_strategy", "Duration_of_pain", "Relationship_with_colleagues", "Kinesiophobia_physical_exercise", "Irrational_thoughts_risk_lasting", "Kinesiophobia_pain_stop", "working_ability")]="polyreg"
meth[c("Incoordination", "Fever", "Workoverload", "Loss_muscle_strength", "Uses_corticosteroids", "Trauma", "Serious_disease")]="logreg"

view(meth)

set.seed(1003)
imputed = mice(LogReg, method=meth, predictorMatrix=predM, m=5, maxit=24000000)

imputed <- complete(imputed)

当尝试运行估算的= mice(...)代码时。我得到了:

iter imp变量   1 1发热nnet.default中的Duration_of_painError(X,Y,w,mask = mask,size = 0,skip = TRUE,softmax = TRUE,:   太多(2400)重量

作为错误。由于我对R语言还比较陌生,所以如果有人可以帮助我解决该错误

0 个答案:

没有答案