1

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.

jay.sf
  • 60,139
  • 8
  • 53
  • 110
TJ87
  • 404
  • 1
  • 3
  • 13
  • 1
    Sorry, it seems to me you don't know much about multiple imputation, and that the analysis you're about to do doesn't make sense. Provide **1.** complete `mice()` call, **2.** information and code of planned analysis, **3.** example data, provided in [this way](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). – jay.sf Jul 20 '19 at 06:49

1 Answers1

1

The issue was that I imputed data for men and women separately and combined the rows of the data frames after I called complete(...,action=long). The .id variable did have repeats because it was a vector of 1:nrow for men and 1:nrow for women. I recoded the .id variable to correspond to individual id and the issue is resolved.

TJ87
  • 404
  • 1
  • 3
  • 13