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:
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
library(mice) 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:
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, corstr="ar1")) summary(pool(fit))