Guest User

Untitled

a guest
Nov 17th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. fit <- glm(am ~ mpg, family=binomial(), data=mtcars) # Logistic regression
  2. p <- c(.05,.10,.20,.50,.80,.90,.95) # Specify probabilities
  3. x <- (log(p/(1-p)) - coef(fit)[1])/coef(fit)[2] # Compute corresponding x's
  4. i <- ordered(1:length(p)) # Identify p's and x's for plotting
  5. #
  6. # Compute the fitted curve.
  7. #
  8. Z <- data.frame(mpg=with(mtcars, seq(min(mpg), max(mpg), length.out=101)))
  9. Z$am <- predict(fit, Z, type="response")
  10. #
  11. # Plot everything.
  12. #
  13. library (ggplot2)
  14. ggplot(mtcars, aes(mpg, am)) +
  15. geom_hline(aes(yintercept=p, color=i), data.frame(p, i), alpha=0.8, show.legend=FALSE)+
  16. geom_vline(aes(xintercept=x, color=i), data.frame(x, i), alpha=0.8, show.legend=FALSE)+
  17. geom_point(size=2, alpha=0.25, fill="Black", shape=21) +
  18. geom_line(aes(mpg, am), Z, size=1.25, color="#303030") +
  19. ylab("Probability(am=1)") +
  20. ggtitle("Probability grid with associated regressor values") +
  21. theme(panel.grid=element_blank())
Add Comment
Please, Sign In to add comment