Advertisement
Guest User

Untitled

a guest
May 24th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.39 KB | None | 0 0
  1. # Plot Pearson and deviance residuals for poisson
  2. pearson <- influence(model.best)$pear.res/ sqrt(1 - influence(model.best)$hat)
  3. summary(pearson)
  4. deviance <- influence(model.best)$dev.res/ sqrt(1 - influence(model.best)$hat)
  5. summary(deviance)
  6. xb <- predict(model.best)
  7. plot(pearson~xb) #Over 30
  8. plot(pearson^2~xb) # LArger than 1200 XD This is terrible
  9. abline(4,0, col = "red", lty = 3)
  10. plot(deviance~xb) # Over 20
  11. abline(2,0, col = "red", lty = 3)
  12. abline(-2,0, col = "red", lty = 3)
  13.  
  14. # Plot Pearson and deviance residuals for negative binomial
  15. pearson <- influence(model.gneg_cars)$pear.res/ sqrt(1 - influence(model.gneg_cars)$hat)
  16. summary(pearson)
  17. deviance <- influence(model.gneg_cars)$dev.res/ sqrt(1 - influence(model.gneg_cars)$hat)
  18. xb <- predict(model.gneg_cars)
  19. plot(pearson~xb) #Over 6
  20. plot(pearson^2~xb) # Larger than 40. Not good, but miles ahead of Poisson
  21. abline(4,0, col = "red", lty = 3)
  22. plot(deviance~xb) #Over 3, not good
  23. abline(2,0, col = "red", lty = 3)
  24. abline(-2,0, col = "red", lty = 3)
  25.  
  26. # Cooks distance for poisson
  27. cd <- cooks.distance(model.best)
  28. n <- 500
  29. plot(cd~xb) # very weird
  30. abline(h = c(1, 4 / n), col = "red", lty = 3) # Largest 3.5
  31.  
  32. # Cooks distance for negative binomial
  33. cd <- cooks.distance(model.gneg_cars)
  34. n <- 500
  35. plot(cd~xb) # very weird
  36. abline(h = c(1, 4 / n), col = "red", lty = 3) # smaller than  0.05
  37.  
  38. # Conclusion: Dont use Poisson in this case
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement