I'm trying to pool results from a multiple imputation database created in SPSS by using the miceadds package in R (I'm quite new to R so sorry if the terminology is a little off). When I try to change the database to a mids object using the as.mids2 code I get this error message:
Error in 1:(max(as.numeric(levels(data2[, .imp])))) :
result would be too long a vector
In addition: Warning messages:
1: In max(as.numeric(levels(data2[, .imp]))) :
no non-missing arguments to max; returning -Inf
2: In max(as.numeric(levels(data2[, .imp]))) :
no non-missing arguments to max; returning -Inf
Anyone have any idea what this means? The database is 28 variables with 2378 obs so not large.
This is the script I'm using:
mydata <- read.csv("mydata.csv", na.strings = "999")
as.mids2 <- function(data2, .imp=1, .id=2){
ini <- mice(data2[data2[, .imp] == 0, - c(.imp, .id)], m = max(as.numeric(levels(data2[, .imp]))), maxit=0)
names <- names(ini$imp)
if (!is.null(.id)){
rownames(ini$data) <- data2[data2[, .imp] == 0, .id]
}
for (i in 1:length(names)){
for(m in 1:(max(as.numeric(levels(data2[, .imp]))))){
if(!is.null(ini$imp[[i]])){
indic <- data2[, .imp] == m & is.na(data2[data2[, .imp]==0, names[i]])
ini$imp[[names[i]]][m] <- data2[indic, names[i]]
}
}
}
return(ini)
}
mydata.mids <- as.mids2(mydata)
Any help would be very appreciated.