I am trying to create new variables after multiple imputation.
I have the following variables:
data: mydata
total number of observations=500
HDL: continuous (no missing values)
Physical activity: factor (63 case are missing)
Smoking: binary (90 case are missing)
CVD: binary (no missing values)
My predictor is HDL and after multiple imputation, I would like to group it into 3 categories then perform cox hazard proportional hazard ratio.
I did the following steps: 1- I imputed missing data using the following code:
impu<- mice::mice(mydata,seed = 123, print = FALSE,m=5, maxit = 0)
2-Tranformed the data into long format.
impu_long<-mice::complete(impu, action="long", include = TRUE)
3-Grouping HDL into 3 categories:
impu_long<-impu_long %>% mutate(HDLg <-case_when(HDL<40~0,
HDL>=50~1,
HDL>=60~2) )
4-Convert the imputed datasets back to mids type.
impu1<-as.mids(impu_long, .imp = ".imp")
However I got the following error. "Error in class(ff) <- "formula" : attempt to set an attribute on NULL" Any idea? Thank you in advance.
mutateyou need to use=for assignment rather than<-. Otherwise you end up with a column named "... <- NULL", which apparently MICE doesn't like. Changing tomutate(HDLg = case_when(HDL<40~0,HDL>=50~1,HDL>=60~2)should work. $\endgroup$