Hi, I want to impute the missing values in my data set multiple times, and then combine the results (like multiple imputation, but manually) to get a mean of the parameter(s) from the multiple imputations. Does anyone know how to do this?
I have the following script: y1 <- rnorm(20,0,3) y2 <- rnorm(20,3,3) y3 <- rnorm(20,3,3) y4 <- rnorm(20,6,3) y <- c(y1,y2,y3,y4) x1 <- 1+2*y1+ rnorm(20,0,8) x2 <- 1+2*y2+ rnorm(20,0,8) x3 <- 1+2*y3+ rnorm(20,0,8) x4 <- 1+2*y4+ rnorm(20,0,8) x <- c(x1,x2,x3,x4) mcar.y <- rep(NA,80) y.mis <- rep(NA,80) df <- data.frame(y=y, y.mis=y.mis, mcar.y=mcar.y, x=x) df$y.mis <- df$y for (j in 1:80) { df$mcar.y <- rbinom(80,1,0.15) } ind0 <- which(df$mcar.y==0) ind1 <- which(df$mcar.y==1) if (length(ind0) > 68) { df$mcar.y[sample(ind0, length(ind0) - 68)] <- 1 } else { df$mcar.y[sample(ind1, 68 - length(ind0))] <- 0 } df$y.mis[df$mcar.y==1] <- NA This gives me data sets with missing values completely at random. Now I would like to apply single imputation: library(Hmisc) lm.y <- lm(df$y.mis~df$x,data=df); lm.y library(arm) pred.y <- rnorm(length(df$y), predict (lm.y, df), sigma.hat(lm.y)) y.imp<- df$y.mis impute <- function (y, y.impute) { ifelse (is.na(y), y.impute, y) } y.imp <- impute (y.imp, pred.y) df <- data.frame(df$y, df$y.mis, pred.y, y.imp, x) and repeat this imputation process a couple of times (say, 5 times) for each data set. If I, however, have run this imputation-script (for 1 incomplete data set), my data set is already complete. I would like to get back to the incompleted data set used before, and repeat the single imputation process four times with the same incomplete data set (so I can calculate some mean of parameters from the 5 imputed data sets later on). But how? Thanks. -- View this message in context: http://r.789695.n4.nabble.com/multiple-imputation-manually-tp3263786p3263786.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.