1
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$ Commented Mar 7, 2022 at 16:17
  • 2
    $\begingroup$ 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. $\endgroup$ Commented Mar 8, 2022 at 3:45
  • $\begingroup$ @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. $\endgroup$ Commented Mar 8, 2022 at 6:09
  • 1
    $\begingroup$ @DavidLukeThiessen, Thank you for your comment it worked. $\endgroup$ Commented Mar 8, 2022 at 6:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.