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?


Applying constraints insofar as my question was concerned is documented well in this MICE vingette (1)
Here's the embarrassingly simple code:
long <- complete(imp, "long", include = TRUE)  
long$avg <- with(long, ifelse(avg < uprange, avg, uprange))  
imp <- as.mids(long) 

1: https://www.gerkovink.com/miceVignettes/Passive_Post_processing/Passive_imputation_post_processing.html
