Search code examples
rordinal

R is showing "Error in getY(fullmf) : response needs to be a factor" when the response is already an ordered factor


I am using the ordinal package and using the clmm function on R, but keep getting the following error despite ensuring that my response variable is ordinal (aka an ordered factor):

Error in getY(fullmf) : response needs to be a factor

Here is the code with the error, also showing how R already understands the variable 'helpfulness' to be an ordered factor.

> library(ordinal)
> hyp1.model1<-clmm(helpfulness~reflectiontype+session+(1+reflectiontype|participant),data=hyp1data)
Error in getY(fullmf):response needs to be a factor
> unique(helpfulness)
[1] 4 2 1 3 0 
Levels: 0 < 1 < 2 < 3 < 4
> class(helpfulness)
[1] "ordered" "factor"

Solution

  • I do not have much to add to what have been said by Roland and Ryan J Field. I am just trying to explain it. Without looking at your data, I could be totally wrong. I have tested using the example data wine. The model only gave such an error message when the left side of the ~ is numeric. It did not give men any error messages when I replaces other variables with numeric values.

    It appears that you might have two helpfulness: one vector helpfulness and one variable helpfulness in your data hyp1data.

    > unique(helpfulness)
    [1] 4 2 1 3 0 
    Levels: 0 < 1 < 2 < 3 < 4
    > class(helpfulness)
    [1] "ordered" "factor"
    

    Only tells the vector helpfulness is a factor. Your variable hyp1data$helpfulness might still be numeric. You may want to try class(hyp1data$helpfulness) to check this. Please let me know if this is not the case. I will delete this answer.