Statistics and Statistical Programming (Winter 2017)/R lecture outline: Week 6

From CommunityData
< Statistics and Statistical Programming (Winter 2017)
Revision as of 06:06, 8 February 2017 by Benjamin Mako Hill (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
  • the cut() function: cut(airquality$Temp, quantile(airquality$temp))
  • tabular data: many ways to create it
    • input it directly (using the matrix command, which I used in week 2 or using rbind):
genpol <- as.matrix(rbind(c(762, 327, 468), c(484, 239, 477)))
dimnames(gen.pol) <- list(gender = c("F", "M")
party = c("Democrat","Independent", "Republican"))
  • more ways to create tabular data:
    • with tapply: tapply(warpbreaks$breaks, list(warpbreaks$wool, warpbreaks$tension), sum)
    • creating it with table(): table(cut(airquality$Temp, quantile(airquality$Temp)), airquality$Month)
  • once we have tables, we can look at them: margin.table() is fast; prop.table() is super useful
  • chisq tests: chisq.test()
    • looking into the chisq.test() object; i often use TAB; names() is also good
  • debugging code
    • print line debugging
    • running the inside of functions