1

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.

Bkry
  • 37
  • The best idea would be to avoid the categorization in the first place. See this thread among many others on the site. Keep HDL continuous and model it flexibly, for example with regression splines. Also, it's not clear where the "LDL" comes from in your code, as you don't include that in the list of variables you describe. – EdM Mar 07 '22 at 16:17
  • 2
    When using mutate you need to use = for assignment rather than <-. Otherwise you end up with a column named "... <- NULL", which apparently MICE doesn't like. Changing to mutate(HDLg = case_when(HDL<40~0,HDL>=50~1,HDL>=60~2) should work. – David Thiessen Mar 08 '22 at 03:45
  • @EdM, Thank you for your comment. I would like to categorize the variable because I want to see the effects of HDL at each level. There is already a cutoff point for normal HDL and low HDL and I would like to compare the risk of CVD for people with low HDL levels compared to those with normal HDL. I am sorry for my mistake LDL is not in the model. I have modify it. – Bkry Mar 08 '22 at 06:09
  • 1
    @DavidLukeThiessen, Thank you for your comment it worked. – Bkry Mar 08 '22 at 06:09

0 Answers0