0

I am trying to replace missing values in 15 ordinal variables using MICE. The variables are on a 5-point scale (level of agreement scale) that I effects coded from -2 to 2.

I thought the appropriate estimation method would be proportional odds model (polr), but I keep getting the following error: "Error in colMeans(as.matrix(imp[[j]]), na.rm = TRUE) :'x' must be numeric" and the warning: "Imputation method polr is for categorical data". My data is ordered categorical data, so I am not sure why I am getting this error.

Here is my coding:

impute <- mice(Data, m=5, maxit=10, method='polr', seed=12) 

where Data is a dataset with just the 15 ordinal variables.

jrcalabrese
  • 2,184
  • 3
  • 10
  • 30
Nicki
  • 1
  • Can you provide `dput(Data)`? See here: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – jrcalabrese Jun 28 '23 at 15:43

1 Answers1

0

Welcome to stack overflow. Without seeing the data, my guess is that "polr" is expecting factors and not numerical data.

I was able to recreate your error message with the following:

categories <- c(-2,-1,0,1,2, NA)

Data <- matrix(data = NA,
               nrow = 5, 
               ncol = 15)

for(i in 1:15){
  Data[,i] <- sample(categories, 5, replace = FALSE, prob = NULL)
}

out <- mice(Data, m=5, maxit=10, method='polr', seed=12) 

I would convert your numeric levels to factors which would transform the data to factors using the following:

test.Data <- apply(test.Data, FUN = factor, levels = c(-2,-1,0,1,2), MARGIN = 2)

And then try running the mice command after

Liam Haller
  • 182
  • 10