0

I am trying to code an ordinal logistic regression using R, but I keep getting this error which says: response must have 3 or more levels.

My independent and dependent variable are ordered factors and only have (O and 1):

dataset$defense <- factor(dataset$defense, levels=c(1,0),
                     , ordered = FALSE)


dataset$pol_violence <- factor(
  dataset$pol_violence, levels=c(1,0),
                          , ordered = TRUE)

and whenever I try to run the regression using this code:

m <- polr(defense ~ pol_violence, data = dataset, Hess=TRUE) 

I get the error message: response must have 3 or more levels

What should I do?

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Mariam
  • 1
  • 3
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. But you are trying to do a proportional log odds model with a response that only has two levels (0/1)? That seems like an unusual choice and hence the function is confused. – MrFlick Jun 11 '20 at 19:55
  • For some reason the website is not letting me add a picture to my post. But my dependent and independent variables are categorical and only have two levels. if proportional log odds model is not the appropriate model then what do you suggest I use instead? – Mariam Jun 11 '20 at 20:04
  • 2
    ... logistic regression – user20650 Jun 11 '20 at 20:04
  • 1
    Why `polr` ? While it is true you can technically order a binary or dichotomous outcome (0.1) with a correction to your code which should be `ordered = TRUE` you don't really need `polr` since you only have a single outcome and single predictor https://www.stat.berkeley.edu/~s133/factors.html – Chuck P Jun 11 '20 at 20:04
  • Which regression command do you suggest i use instead of polr? I intend on also including control variables – Mariam Jun 11 '20 at 20:06
  • 1
    `m <- glm(defense ~ pol_violence, data = dataset, family=binomial)` – user20650 Jun 11 '20 at 20:07
  • Take a look at https://stats.idre.ucla.edu/r/dae/logit-regression/ – Chuck P Jun 11 '20 at 20:08
  • 1
    so yes, glm makes more sense I suppose? does that make more sense to you guys as well? thank you so much! – Mariam Jun 11 '20 at 20:10

0 Answers0