0

I am trying to plot a logit curve. The code below works well except for the last line which throws this error: "Error in xy.coords(x, y) : 'x' and 'y' lengths differ". Below is dataset's structure. What could be wrong?

Observations: 532
Variables: 14
$ `N Personal`   <chr> "P001", "P002", "P005", "P007", "P008", "P010", "P011", "P012", "P...
$ Binaria        <dbl> 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, ...
$ Rendimiento    <dbl> 0.81, 0.75, 0.75, 0.60, 0.80, 1.00, 0.75, 0.85, 0.86, 0.86, 0.85, ...
$ Edad           <dbl> 2, 3, 2, 3, 3, 2, 2, 1, 2, 2, 1, 2, 2, 3, 2, 3, 3, 2, 3, 3, 3, 4, ...
$ Posición       <dbl> 2, 1, 2, 2, 2, 2, 1, 1, 1, 1, 2, 1, 1, 3, 1, 1, 4, 2, 5, 1, 2, 2, ...
$ Sexo           <dbl> 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, ...
$ Nacional       <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, ...
$ Distancia      <dbl> 1, 4, 3, 5, 3, 1, 4, 1, 1, 2, 3, 4, 2, 2, 5, 4, 4, 5, 4, 1, 2, 4, ...
$ Estrato        <dbl> 3, 2, 3, 2, 5, 3, 5, 3, 3, 3, 3, 1, 3, 5, 3, 2, 4, 5, 6, 3, 3, 6, ...
$ `Estado civil` <dbl> 1, 4, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 1, 2, 1, 3, 1, 1, 1, ...
$ Hijos          <dbl> 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, ...
$ Formación      <chr> NA, NA, NA, "PREGRADO", "PREGRADO", NA, NA, "PREGRADO", "PREGRADO"...
$ Educación      <dbl> NA, NA, NA, 3, 3, NA, NA, 3, 3, NA, 3, NA, 3, 4, NA, 3, NA, 3, 3, ...
$ Performance    <dbl> 2, 3, 3, 4, 3, 1, 3, 2, 2, 2, 2, 2, 3, 1, 2, 2, 1, 1, 2, 3, 2, 2, ...
logit1=glm(RH$Binaria ~ RH$Posición, data=RH, family = "binomial" )

plot(RH_train$Posición, RH_train$Binaria, pch = 16, xlab = "Posicion", ylab = "Binaria")

xPosicion <-seq (1, 5, 0.5)

yPosicion <- predict(logit1, list(Posi= xPosicion), type="response")

lines(xPosicion, yPosicion)

Error in xy.coords(x, y) : 'x' and 'y' lengths differ

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
  • Please provide a reproducible example. See https://stackoverflow.com/q/5963269/8107362 – mnist Oct 14 '19 at 21:41
  • 1
    Don't use `$` with formulas. Try `logit1=glm(Binaria ~ Posición, data=RH, family = "binomial" )`. But also make sure you share your data in a [reproducible format](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – MrFlick Oct 14 '19 at 21:42
  • why did you write `list(Posi=...` instead of `Data.Frame(Posición=...`? it should work if you fix this. also it should be enaugh to just remove the list and use xPosicion as the second parameter of the `predict` function. – carlo Oct 14 '19 at 21:58

0 Answers0