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

From CommunityData
< Statistics and Statistical Programming (Winter 2017)
Revision as of 05:39, 16 February 2017 by Benjamin Mako Hill (talk | contribs) (Created page with "* fitting a linear model with one variable: lm() ** module formulae, which we've already seen! ** looking at model objects: summary(); m$<tab> or names(m) *** m$fitted.values...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
  • fitting a linear model with one variable: lm()
    • module formulae, which we've already seen!
    • looking at model objects: summary(); m$<tab> or names(m)
      • m$fitted.values;
      • residuals: mtcars$mpg - m$fitted.values OR m$residuals
      • also functions: coefficients(m) (or coef), predict(m), residuals(m) (or resid)
  • plotting residuals:
    • hist(residuals(m))
    • plot against our x: plot(mtcars$hp, residuals(m)
    • QQ-plots with qqnorm(residuals(m))
    • doing a plot with ggplot just involves making a dataset: d.fig <- data.frame(hp=mtcars$hp, resids=residuals(m))
  • adding controls: just make our formula more complex
    • update.formula()
    • or just a write a new one
  • generating nice regression plots:
    • one of many options: stargazer(m1, m2, type="text") or type="html"