0

I generated 25 imputed datasets using mice in R. Because I want to add variables and make subsets after imputation, I convert the mids object to a long format:

long1 <- complete(imp, action='long', include=TRUE)

This generates no errors.

Hereafter, I want to convert the long format back to a mids object with this code:

imp<-as.mids(long1)

However, when running this line of code I get this error:

**Error in sample.int(length(x), size, replace, prob) : 
  cannot take a sample larger than the population when 'replace = FALSE'**

Can someone tell me what the error means and how to solve it? I have used as.mids many times in the past and never experienced trouble with it.

jrcalabrese
  • 2,184
  • 3
  • 10
  • 30
TesM
  • 1
  • 1
  • Welcome to StackOverflow. Can you make your post [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and provide your data and include your code where you add variables/make subsets? – jrcalabrese Dec 08 '22 at 15:20
  • You also tagged this question as `long-format-data`, but are you converting your object from wide to long (e.g., using `pivot_longer`) after running `complete`, or is this just referring to the argument `action = "long"`? – jrcalabrese Dec 08 '22 at 15:23
  • This is indeed referring to the argument action= "long". I found out what caused the error. I imputed two different cohorts in which 1 variable was completely missing. – TesM Dec 09 '22 at 16:10
  • Generally, `mids` objects that have been `complete`'d don't get called "long" (even though they technically are) since "long" is usually reserved for longitudinal or repeated measures datasets. – jrcalabrese Dec 09 '22 at 16:13

0 Answers0