Plotting GLM model gives me a linear regression

Hello,

I ran a logit model, but when I try to plot it, I am having some errors. For instance, to show the distribution between two variables, I applied the GLM method in ggplot2, but instead of having the typical logistic curve, I receive a linear regression.

Here is a sample data:

mydata<-data.frame(
  prespartyshare = c(44.7470817120623,46.3035019455253,
                     16.1793372319688,16.1793372319688,17.1539961013645,
                     46.25,46.25,52.5252525252525,52.5252525252525,
                     44.7470817120623,46.3035019455253,16.1793372319688,16.1793372319688,
                     46.25,46.25),
        approved = as.factor(c("0","1","0",
                               "0","1","0","1","0","1","0","1","0","1",
                               "0","1"))
)

And the code I used:

ggplot(mydata, aes(x=prespartyshare, y=as.numeric(mydata$approved) - 1)) + 
  geom_point(alpha=.5) +
  stat_smooth(method="glm", se=FALSE, method.args = list(family=binomial), fullrange=TRUE)

I appreciate your help in advance.

Your curve is pretty linear in the range of the data. Add +xlim(-200,200) and you'll see a nicer looking curve.

1 Like

Thank you for the explanation

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.