0

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.

4

1 回答 1

0

问题是我分别估算了男性和女性的数据,并在我调用完整(...,action = long)之后组合了数据框的行。该.id变量确实有重复,因为它是男性 1:nrow 和女性 1:nrow 的向量。我将.id变量重新编码为对应于个人 ID,问题得到解决。

于 2019-07-24T22:14:41.083 回答