geom_smooth with logistic regression plot

3,283 views
Skip to first unread message

Scott Chamberlain

unread,
Feb 24, 2012, 10:12:53 AM2/24/12
to ggp...@googlegroups.com
Hello, 

I want to make plots to display results of logistic regression analyses.  I wonder what the correct way is to code this in geom_smooth.  Is the following appropriate for plotting logistic regression?


dat <- data.frame(sign = rep(c(0,1), 200), resp = rnorm(400, sd=20))

ggplot(dat, aes(resp, sign)) +
  geom_smooth(method = "glm", family="poisson", colour='black', size=1.5)


And gives the attached plot.  Is this right? 


Thanks! Scott Chamberlain
Rplot.png

Scott Chamberlain

unread,
Feb 24, 2012, 10:47:16 AM2/24/12
to ggp...@googlegroups.com
Woops, I meant to say family = "binomial" instead of family = "poisson". 

And the plot attached.

S
Rplot01.png

Ben Bolker

unread,
Feb 24, 2012, 11:19:03 AM2/24/12
to ggp...@googlegroups.com

dat <- data.frame(sign = rep(c(0,1), 200), resp = rnorm(400, sd=20))

ggplot(dat, aes(resp, sign)) +
geom_smooth(method = "glm", family="binomial", colour='black', size=1.5)

I think this is right.

You can also do this by hand, with slightly more difficulty, by using
predict() on the results of the glm() and using geom_line() and
geom_ribbon()


> --
> You received this message because you are subscribed to the ggplot2
> mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

Reply all
Reply to author
Forward
0 new messages