Session Ready
Exercise

Multiple slopes

You learned about model.matrix() and its relationship to glm() during the video. Now, you can "peek under the hood" of R and see how formulas work. The input to model.matrix() is similar to formula inputs of lm() and glm() with one key difference: model.matrix() does not have a left-hand side (e.g. y ~), only the right-hand side (e.g., ~ x).

For example, model.matrix( ~ x1) or model.matrix( ~ x1 + x2) both would be valid inputs. The output from model.matrix() is called a prediction matrix because it is the prediction (or right-hand side) of a formula in R.

During this exercise, you will use model.matrix() with 2 vectors: size and count. First, build a simple formula that only includes size. Second, build a formula that includes both size and count.

Instructions 1/2
undefined XP
  • 1
    • Use model.matrix() to create a prediction matrix with only size.
    • 2
      • Use model.matrix() to create a prediction matrix with both size (first) and count (second).