Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post-processing: function ifdo() not yet implemented #43

Open
mikgh opened this issue Jul 6, 2017 · 3 comments
Open

Post-processing: function ifdo() not yet implemented #43

mikgh opened this issue Jul 6, 2017 · 3 comments

Comments

@mikgh
Copy link

mikgh commented Jul 6, 2017

Dear Stef,

Another problem I encountered today showed itself when I was trying to reproduce some of your code from your book "Flexible Imputation of Missing Data" (fantastic book!).

At page 135-136 you present two code-solutions to the same post-processing setting:

library(mice)
ini <- mice(airquality[, 1:2], maxit = 0)
post <- ini$post
post["Ozone"] <- "imp[[j]][,i] <- squeeze(imp[[j]][,i], c(1,200))"
imp <- mice(airquality[, 1:2], method = "norm.nob", m = 1, maxit = 1, seed = 1, post = post)

Alternative to line 4:
post["Ozone"] <- "ifdo(c(Ozone < 1, Ozone > 200), c(1, 200))"

The former works fine but the latter gives the OzoneFunction ifdo() not yet implemented.

Has the "ifdo" function been withdrawn from the package?

Best regards,
Mikkel

@mikgh
Copy link
Author

mikgh commented Jul 6, 2017

Just read through the R-script for the chapter on multiple-imputation.com and noticed that you actually write it isn't yet implemented.

@stefvanbuuren
Copy link
Member

Yes, this is still one on the todo list

@stefvanbuuren
Copy link
Member

Note: I found this code on my machine. I didn't test, and it probably does not work, but can be used for inspiration.

##' Conditional imputation helper
##' 
##' Sorry, the \code{ifdo()} function is not yet implemented.
##' @aliases ifdo
##' @param condition a vector of conditions
##' @param action a vector of actions to do when condition is TRUE
##' @return Currently returns an error message.
##' @author Stef van Buuren, 2017
##' @examples
##' \dontrun {
##' # old form
##' ini <- mice(airquality[, 1:2], maxit = 0)
##' post <- ini$post
##' post["Ozone"] <- "imp[[j]][, i] <- squeeze(imp[[j]][, i],c(1, 200))"
##' 
##' # ifdo form
##' post["Ozone"] <- "ifdo(c(Ozone < 1, Ozone > 200), c(1, 200))"
##' imp <- mice(airquality[, 1:2], method = "norm.nob", m = 1, maxit = 1, seed = 1, post = post)
##' }
##' @keywords internal
# ifdo <- function(condition, action, data = p$data) {
#   if (length(condition) != length(action))
#     stop("Different length of `condition` and `action`")
#   imputes <- data[where[, j], , drop = FALSE]
#   for (k in 1:length(condition)) {
#     eval(parse(paste("idx <- with(imputes,", condition[k], ")")))
#     if (substring(action[k], 1, 1) == "~") {
#       eval(parse(paste("imp[[j]][idx, i] <- model.frame(as.formula(", action[k], "), data = imputes[idx, , drop = FALSE])")))
#     } else {
#       eval(parse(paste("imp[[j]][idx, i] <- with(imputes[idx, , drop = FALSE], ", action[k])))
#     }
#     # cat("Function ifdo() not yet implemented.\n")
#   }
# }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants