This is my first time trying to use mice in R. I have a cross-sectional dataset with responses for several scales. I would like to calculate the sums of several scales after imputing missing data.
I would like to adapt the code provided in R - mice - adding a column that sums columns with imputed values, which is based on responses posted in a post on how to Perform operation on each imputed dataset in R's MICE. However, I am not certain what each line in this section of code does:
pred1 <- ini$pred
#change the predictor matrix so only bdd$EE1-9 predicts EE (necessary?)
pred1[ "EE", ] <- 0
pred1[ "EE", c("EE1", "EE2", "EE3", "EE4", "EE5", "EE6", "EE7", "EE8", "EE9")] <- 1
#change the predictor matrix so that EE isnt used to predict
pred1[ , "EE" ] <- 0
I think that the first line accesses the prediction matrix in the mids df generated when executing mice(.). Next, lines 2 and 3 change the matrix so that only the variables included in the ~I() statement are used to impute/calculate the sums. I think this is not required? Please confirm. Finally, line 4 changes the matrix so that the sum is not used to impute other variables. This is required? Please confirm
Can you either confirm that I understand the function of this code or provide a line-by-line explanation of its function? Thanks in advance!