14 Categorical predictors


The previous chapters applied linear regression models to cases where we wanted to predict a metric variable \(y\) based on the values of associated metric measurements \(x_i\) (\(1 \le i \le n\)). In this chapter, we are generalizing this approach to also deal with the case where a predictor \(x_i\) is a categorical variable, such as an indicator value showing which group or experimental condition a measurement of \(y\) belongs to. In this way, at the end of the chapter, we will be able to apply linear regression modeling to the analysis of (metric) measurements, for instance, from a factorial design - a common design type of psychological experiments (see Chapter 3).

As we will see in this chapter, the only “trick” to generalizing linear regression modeling to also cover categorical predictors, as we will call them, is to map levels of a categorical variable onto numbers. For example, if we have two groups in a predictor variable \(x\), say group \(A\) and \(B\), we could just encode group \(A\) as a value of \(x = 0\) and group \(B\) as a value of \(x = 1\). But there are many sensible mappings of this kind, and many helplessly ridiculous ones. The relevant technical term here is contrast coding, i.e., a scheme of mapping categorical distinctions onto numeric representations in such a way that the theoretically interesting contrasts (i.e., the distinctions between groups that we want to test) can be easily tested with the resulting regression model.

The chapter is structured as follows. Section 14.1 uses the Simon task data to cover the case of a single categorical predictor with just two category levels (e.g., just groups \(A\) and \(B\)). Section 14.2 then uses data from the Mental Chronometry experiment to look at the more general case of a single categorical predictor with more than two category levels (e.g., just groups \(A\), \(B\) and \(C\)). Section 14.3 considers cases with several categorical predictors, including their interaction, based on the politeness data set.

The video below provides a dense coverage of single-predictor contrast coding, i.e., the contents of Sections 14.1 and 14.2.

The learning goals for this chapter are:

  • understand the basic idea behind contrast coding
  • be able to interpret the results of a regression analysis that uses treatment coding
  • be able to interpret inferences for models including an interaction coefficient for two categorical predictors