This can be done easily as follows:
Use complete() to convert the mids object to long-format data.frame:
long1 <- complete(midsobj1, action='long', include=TRUE)
Perform any necessary manipulations:
long1$new.var <- long1$chl/2 long2 <- subset(long1, age >= 5)
use as.mids() to convert inverse managed data into a mids object:
midsobj2 <- as.mids(long2)
Now you can use midsobj2 as needed. Note that include=TRUE (used to include source data with missing values) is required for as.mids() to properly compress long format data. Please note that before v2.25 mice, an error occurred in the function as.mids () (see this post https://stats.stackexchange.com/a/158327/69413 )
EDIT: According to this answer fooobar.com/questions/1205918 / ... (from what is essentially a duplicate question) you can also edit the mids object directly by referring to $ data and $ imp, So for example
midsobj2<-midsobj1 midsobj2$data$new.var <- midsobj2$data$chl/2 midsobj2$imp$new.var <- midsobj2$imp$chl/2
You will have problems if you want to multiply $ imp or want to use $ call, so I would not recommend this solution as a whole.
source share