Exercise

Modeling with categorical variable

In previous exercises you have fitted a logistic regression model with color as explanatory variable along with width where you treated the color as quantitative variable. In this exercise you will treat color as a categorical variable which when you construct the model matrix will encode the color into 3 variables with 0/1 encoding.

Recall that the default encoding in dmatrix() uses the first group as a reference group. To view model matrix as a dataframe an additional argument in dmatrix(), namely, return_type will be set to 'dataframe'.

The color variable has a natural ordering as follows:
1: medium light
2: medium
3: medium dark
4: dark

The crab dataset is preloaded in the workspace.

Instructions 1/4

undefined XP
    1
    2
    3
    4
  • Construct a model_matrix with color as a variable. color should be treated as categorical and the reference group set to 4 using Treatment() function.
  • Fit and print the results of a logistic model with y as the response.