Get startedGet started for free

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.

This exercise is part of the course

Generalized Linear Models in R

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Use model.matrix() with size
___
Edit and Run Code