Plotting logistic model with package visreg doesn´t work Data not found

615 views Asked by At

My second question of the day: I want to use the visreg package to plot my logistic regression models. As long as I don't use the attribute "by" it works like a charm, but when I want to use it I get an error. The code I used to create my model is the following:

m3<- glm(alive ~ seatbelt*dvcat + sex + ageOFocc + airbag, family = binomial, data = nassCDS, start=)
summary(m3)

If I then use:

visreg(m3, "seatbelt", scale = "response")

I get the following result enter image description here

which is just fine. But if I now add the "by" attribute I get an error:

visreg(m3, "seatbelt", by="dvcat", scale ="response")

enter image description here

I googled and as far as I understood it the function can't find the data to plot the model. But where can I supply the data? I already tried the "data=" attribute, but it wasn´t working for me (or I did it wrong). There is no console output that I can provide only the message on the graph itself. Can somebody help me? Kind regards, Jan :)


EDIT: I used the "nassCDS" datasat from vincent arel-bundocks github which you can find here: https://vincentarelbundock.github.io/Rdatasets/datasets.html I just inserted the column alive via the column dead so that i am able to use the logistic regression. Therefore i used the dplyr package with the following code:

nassCDS <- nassCDS %>% 
  mutate(dead1 = as.integer(dead)) %>%
  mutate(alive = sjmisc::rec(dead1, rec = "2=0; 1=1")) %>%
select(seatbelt, dead, alive, dvcat, sex, ageOFocc, everything()) %>% 
  select(-dead1)

Furthermore i changed the columns airbag and seatbelt to numeric as it was suggested by one other stackoverflow user.

0

There are 0 answers