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

From CommunityData
(Created page with "Running: * 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...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
Running:
* the cut() function: cut(airquality$Temp, quantile(airquality$temp))
* the cut() function: cut(airquality$Temp, quantile(airquality$temp))
* tabular data: many ways to create it
* tabular data: many ways to create it
Line 7: Line 5:
  dimnames(gen.pol) <- list(gender = c("F", "M")
  dimnames(gen.pol) <- list(gender = c("F", "M")
  party = c("Democrat","Independent", "Republican"))
  party = c("Democrat","Independent", "Republican"))
* more ways to create tabular data:
** with tapply: tapply(warpbreaks$breaks, list(warpbreaks$wool, warpbreaks$tension), sum)
** with tapply: tapply(warpbreaks$breaks, list(warpbreaks$wool, warpbreaks$tension), sum)
** creating it with table(): table(cut(airquality$Temp, quantile(airquality$Temp)), airquality$Month)
** 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
* once we have tables, we can look at them: margin.table() is fast; prop.table() is super useful
* chisq tests: chisq.test()
* chisq tests: chisq.test()
** looking into the chisq.test() object; i often use TAB
** looking into the chisq.test() object; i often use TAB; names() is also good
* debugging code
* debugging code
** print line debugging
** print line debugging
** running the inside of functions
** running the inside of functions

Latest revision as of 06:06, 8 February 2017

  • 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