TotalGadha
TotalGadha

Reputation: 89

Response must have 3 or more levels

I am trying to perform a ordinal logistic regression using R, but I keep getting this error which says: response must have 3 or more levels. What does "response" mean in R? Tried searching on google but nothing is explained on the meaning of response in R. I am pasting the snapshot of the data I am trying to regress and the code I have written so far:

enter image description here

m <- polr(as.factor(Gender) ~ VeryUnsat + Unsat + Sat + VerySat, data = df, Hess=TRUE)
summary(m)
ctable <- coef(summary(m))
p <- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE) * 2
ctable <- cbind(ctable, "p value" = p)
ci <- confint(m)
exp(coef(m))
exp(cbind(OR = coef(m), ci))`

Upvotes: 0

Views: 2800

Answers (1)

Picarus
Picarus

Reputation: 780

You should look at the example of polr method. Just type ?polr in your command line in RStudio

You will see that your response variable is not well defined for what polr expects (unless I am misunderstanding what you try to do)

polr tries to model multilevel ordered variables such as Sat in the example.

I see two problems in your data:

  1. you have aggregated data, a count of how many samples have each level of satisfaction for each combination of age and gender.

  2. your response variable is splitted across different columns. Starting from the non-aggregated data you need to convert to a single variable with multiple possible values (VeryUnsat, Unsat, Sat, VerySat)

You may be able to use the aggregated data if the method allows to specify some weights to each combination (haven't checked the details of the method).

Upvotes: 0

Related Questions