I'm experiencing an error using the function as.mids
in the package mice
(v3.5.0) for R v3.6:
Error in `.rowNamesDF<-`(x, value = value) :
duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique values when setting 'row.names': '1', '2', '3', [...]
Here's some background:
I'm using multiple imputation for covariate data. I imputed the missing covariate data, then saved the result as a data frame in long format:
imputed <- mice(raw.data,...)
mydata <- complete(imputed, "long", inc = TRUE)
I tried to convert the data frame to a mids object for analysis.
mydata <- as.mids(mydata)
However, this resulted in the error above.
I don't understand the message because the dataframe doesn't have rownames (I checked with rownames(mydata) <- NULL)
.
I appreciate any advice.
Update The package manual states:
The function expects the input data long to be sorted by imputation number (variable ".imp" bydefault), and in the same sequence within each imputation block.
So I tried newdata <- mydata[order(mydata$.imp,mydata$.id),]
, then as.mids
. The same error message results.