I have a longitudinal database that has more than 50% of the missing data of the MAR type.

This amount of missing values was a surprise to me because I did not foresee this in the study design, and for that reason I cannot delete those that have missing values because my sample N will be very small. however, these imputation methods are new to me, and I am facing many difficulties.

I saw some tutorials on multiple imputation through the MICE package. So the following points were not clear:

How to specify categorical variables (The categorical variables have no missing data). In my case I have two categorical variables, one with two levels (before and after) and the other with 4 levels (grp1,grp2, grp3, grp4). and eight continuous variables with missing values (D0 to D7).

Just like in the example below:

enter image description here

When imputing data I would like to specify that an imputation should occur through categorical variables (time and group).

I used the code below but I don't know if considered the categorical variables

 imputed_Data <- mice (my.data, m = 5, maxit = 50, method = 'pmm', seed = 500)

After making the imputations, I would like to change from the wide format to the long format, where there would be only the columns: ID, Name, Time, group and a two columns one with the repeated mensure (D0 to D6) and other with Values. I know how to do this with DAtaFrames, but the object generated by mice is of the mids type. As in the example below:

![enter image description here

As my data are repeated (dependent) measures, I want to perform the analysis of generalized equation estimation.

fit<- with(geeglm(value ~ Time+ group,
              data= IM.imputed_Data ,family=gaussian,id=ID,


You could use tidyr::gather() to transform your data into long format and then use the package jomo for multiple imputation accounting for the nested structure of the data.

  • $\begingroup$ I tried to use ´gather´but the object generated by mice is of the mids type, and gather did not work. $\endgroup$ – Kledson Lemes Mar 29 at 13:50
  • $\begingroup$ Sorry, I meant using gather() first. Once you have the data in long format, then proceed to imputing. $\endgroup$ – teamug Mar 29 at 18:01
  • $\begingroup$ teamug I thought that to use mice the variables should be in columns (Wide format) .. I will try it like this. $\endgroup$ – Kledson Lemes Mar 29 at 19:13
  • $\begingroup$ That is probably true, but if you want to proceed in long format, jomo can handle it, and specifying the cluster is pretty straightforward. $\endgroup$ – teamug Mar 30 at 5:56
  • $\begingroup$ Okay, the jomo package is new to me so I research it to understand it better. I don't know if I will have enough time, but I will try. $\endgroup$ – Kledson Lemes Mar 30 at 13:33

Have you tried the following:

fit<- with(imputed_Data, geeglm(value ~ Time+ group,

  • 1
    $\begingroup$ ,I did a test with other data that I have and it worked, but with my data it is not working because I couldn't change from wide format to long $\endgroup$ – Kledson Lemes Mar 29 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.