# Constraints for Multiple imputation for missing values (MICE)

I am imputing average follow-up for a meta-analysis using MICE. In studies reporting a maximum follow-up duration, I attempted to constrain imputations so average follow-up is always less than the maximum follow-up.

I used the custom imputation function described in the excellent community top-post here Multiple imputation for missing values

I used the following adjusted code to do so:

function (y, ry, x, donors = 5, type = 1, ridge = 1e-05, version = "",
...)
{
max <- max(data[,"maxfollowup"], na.rm=TRUE)
)
repeat{
vals <- mice.impute.pmm(y, ry, x, donors = 5, type = 1, ridge = 1e-05,
version = "", ...)
if (all(vals < max)){
break
}
}
return(vals)
}


In reviewing the imputed data, however, some imputed values are greater than the upper limit of the follow-up range. See last row in picture where average > max follow-up. Presumably I did not adjust the code correctly. Where did I go wrong?

• What is "uprange"? If it's the maximum duration of follow-up, then why is it changing with each imputation? Jan 6 at 16:19
• Yes "uprange" is the maximum follow-up duration. Where do you see that it is changing with each imputation? I actually solved the problem, will post below. Jan 8 at 23:59

long <- complete(imp, "long", include = TRUE)