Sax

MachLearn02

Sax
Feb 1st, 2017
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.09 KB | None | 0 0
  1. hod2 <- count(deaths, c("hod", "cod"))
  2. hod2 <- subset(hod2, !is.na(hod))
  3. hod2 <- join(hod2, codes, by = "cod")
  4. hod2 <- ddply(hod2, "cod", transform, prop = freq / sum(freq))
  5. overall <- ddply(hod2, "hod", summarise, freq_all = sum(freq))
  6. overall <- transform(overall, prop_all = freq_all / sum(freq_all))
  7. hod2 <- join(hod2, overall, by = "hod")
  8. devi <- ddply(hod2, "cod", summarise, n = sum(freq),
  9. dist = mean((prop - prop_all)^2))
  10. devi <- subset(devi, n > 50)
  11.  
  12. ggplot(data = devi, aes(x = n, y = dist)) + geom_point()
  13. last_plot() + scale_x_log10() + scale_y_log10() +
  14. geom_smooth(method = "rlm", se = FALSE)
  15. ggsave("n-dist-resid.pdf", width = 6, height = 6)
  16.  
  17. devi$resid <- resid(rlm(log(dist) ~ log(n), data = devi))
  18. unusual <- subset(devi, resid > 1.5)
  19. hod_unusual <- match_df(hod2, unusual)
  20. ggplot(hod_unusual_big, aes(hod, prop)) +
  21.   geom_line(aes(y = prop_all),
  22.   data = overall, colour = "grey50") +
  23.   geom_line() +
  24.   facet_wrap(~ disease, ncol = 3)
  25.  
  26. ggsave("unusual-big.pdf", width = 8, height = 6)
  27. last_plot() %+% hod_unusual_sml
  28. ggsave("unusual-sml.pdf", width = 8, height = 4)
Add Comment
Please, Sign In to add comment