# A novel method for modelling interaction between categorical variables

- 4.3k Downloads
- 1 Citations

## Keywords

Generalize Linear Model Interaction Variable Weighted Effect Balance Design Unequal Number## Introduction

Sweeney and Ulveling (1972) introduced weighted effect coding, where the estimates for categories of nominal and ordinal variables are deviations from the arithmetic mean, typically from a sample. This somewhat neglected parameterization is preferred over the well-known effect coding (ANOVA) if the data are unbalanced (i.e., when categories hold different numbers of observations) and was recently revived in this journal (te Grotenhuis et al. 2016). In this paper, we show that weighted effect coding can also be applied to regression models with interaction effects. The weighted effect coded interactions represent the additional effects over and above the main effects obtained from the model without these interactions. This is a useful alternative to effect coding when the data are unbalanced as in most observational data. In this contribution, we describe this novel parameterization and provide syntax, data, and examples in SPSS, R, and Stata on http://www.ru.nl/sociology/mt/wec/downloads. For didactical reasons we apply OLS regression models, but weighted effect coded interactions can be used in any generalized linear model. Throughout this text we use the word ‘interaction’, while other researchers prefer ‘moderation’.

### Interactions between categorical variables

#### Dummy coded interaction

*n*= 3314) drawn from the Dutch population (aged 18–70) in 2000, 2005, and 2011 (Eisinga et al. 2002, 2012a, b). We created the dummy coded variables Childless

_{dc}with code 1 for respondents with no children and code 0 for respondents with one or more children, Middle

_{dc}(code 1 for the middle-aged and 0 for both young and older respondents) and Older

_{dc}(1 for older and 0 for both young and middle-aged respondents). The dummy coded interaction variables Childless

_{dc}× Middle

_{dc}, and Childless

_{dc}× Older

_{dc}are multiplications of these dummy coded variables (see Table 1 and our website for details). First, we estimated the main effects without interaction (see Table 4, Model 1) and second, we added the two interaction variables (Table 4, Model 2). Note that the reference categories (a) respondents with children, (b) youngsters, and (c) childless youngsters are omitted from the two models, which means that their estimates are set to zero.

Coding scheme for the dummy coded main and interaction effects for the childless, middle-aged and older-aged (references/omitted categories are with children, young, and childless × young)

Categories | Dummy coding | ||||
---|---|---|---|---|---|

Main effects | Interactions | ||||

Childless | Middle | Older | Childless | Childless | |

With children and younger | 0 | 0 | 0 | 0 | 0 |

With children and middle-aged | 0 | 1 | 0 | 0 | 0 |

With children and older | 0 | 0 | 1 | 0 | 0 |

Childless and younger | 1 | 0 | 0 | 0 | 0 |

Childless and middle-aged | 1 | 1 | 0 | 1 | 0 |

Childless and older | 1 | 0 | 1 | 0 | 1 |

Our results show that without interaction, the estimated mean BMI among childless respondents is a significant 0.9 BMI points lower compared to respondents with children, taking into account their age. Further, the estimated mean BMI is significantly higher in both the middle-aged group (1.36) and in older respondents (2.09), compared to youngsters while controlling for having children or not.

After adding the interactions, the main effect of the dummy coded variable Childless relates to the youngest group only. So, respondents who are youngest and childless have an estimated mean BMI of −1.92 points lower compared to the youngest respondents with children. Further, the main effects in the middle-aged and older group pertain to the respondents with children only. The middle-aged people with children have an estimated mean BMI that is 0.46 (non-significant) higher compared to youngsters with children. The older respondents with children have a BMI that is about 1 BMI point higher (1.22), again compared to youngsters with children.

The two interaction effects (one of them being significant) show the extra effect on BMI on top of the aforementioned main effects. For instance, childless middle-aged respondents have an estimated mean BMI that is −1.92 + 1.22 = −0.7 BMI points less compared to middle-aged respondents with children. Likewise, the childless middle-aged respondents have an estimated mean BMI that is 1.68 higher (0.46 + 1.22) compared to youngsters who are childless.

#### Effect coded interaction

It seems a bit odd to use dummy coding in our example because to our knowledge there is no theory that for instance predicts a stronger age-effect among the childless or a weaker effect of having children among the middle-aged. In general, dummy coding is less appropriate if one is agnostic about the direction of effects as the selection of reference categories and the associated statistical tests are then mostly arbitrary. One popular solution is effect coding, where in interaction models the main effect represents a grand mean effect while the interaction effects are deviations from that grand mean effect. This grand mean effect is unweighted, so effect coding is tailor-made for so-called completely balanced designs (Berger and Wong 2009). In such designs all cells have equal numbers of observations. This is not a necessary condition for the sample data; it suffices to assume a population with such a balanced design, while the sample is unbalanced due to randomness for instance. Especially in experimental settings where equal group sizes are often desired, this type of parameterization is well suited to test whether the treatment effect differs across relevant groups (Berger and Wong 2009). Note that in that particular case there are no hypotheses about the directions of the interaction effects.

_{ec}and With Children

_{ec}multiplied with Young

_{ec}, Middle

_{ec}, and Older

_{ec}, which are also effect coded (see Table 2 and our website for details).

Coding scheme for the effect coded main and interactions effects for the childless, middle-aged and older-aged (omitted categories are with children, young, and childless × young)

Categories | Effect coding | ||||
---|---|---|---|---|---|

Main effects | Interactions | ||||

Childless | Middle | Older | Childless | Childless | |

With children and younger | −1 | −1 | −1 | 1 | 1 |

With children and middle-aged | −1 | 1 | 0 | −1 | 0 |

With children and older | −1 | 0 | 1 | 0 | −1 |

Childless and younger | 1 | −1 | −1 | −1 | −1 |

Childless and middle-aged | 1 | 1 | 0 | 1 | 0 |

Childless and older | 1 | 0 | 1 | 0 | 1 |

The results for this effect coded interaction model are given in Table 4, and again model 1 with no interaction is presented first. The grand mean BMI is 24.73 (intercept) and respondents with children have an estimated mean BMI of 24.73 **+** 0.45 = 25.18. The respondents with no children have an estimated mean BMI of 24.73 − 0.45 = 24.28. To find the grand mean again we have to sum 25.18 and 24.28 and divide it by 2, resulting in 24.73, which again is the value for the intercept. This proves that with regard to the point of reference, effect coding does not take into account the possible unequal number of observations in the categories. Compared to this grand mean of 24.73, the estimated mean BMI is −1.15 lower for the younger respondents, 0.21 higher for the middle-aged, and 0.94 higher for the older respondents. Note that when these three deviations are summed, the outcome equals zero, which is typical for using a balanced design. After adding the effect coded interaction variables (Model 2), the grand mean shifts to 24.88 and the main effects also change. This is due to the unbalanced nature of our data, for instance the number of older respondents without children is 62, whereas 3314/6 = 552 is expected in a completely balanced design. The interaction effects denote the extra change in the estimated mean BMI over and above the unweighted main effect. Young, childless respondents have a mean BMI of 0.41 less, so their estimated mean BMI is 24.88 − 0.56 − 0.97 − 0.41 = 22.94. For youngsters with children the estimated mean is 0.41 higher than the main effects indicate: 24.88 + 0.56 − 0.97 + 0.41 = 24.88. Note that both interaction effects are counterparts and note also that the sum of all interaction effects equals zero, which again is the result of assuming balanced data.

#### Weighted effect coded interaction

*t*values when the data are unbalanced. This is illustrated in Table 4, last two columns. In Model 1 (without interactions), the estimate for the intercept equals 24.98, and equals the observed (arithmetic) sample mean in our dataset. Respondents with children have an estimated mean BMI that is 0.29 higher than 24.98, whereas childless respondents score 0.61 BMI points lower. Further, the youngster have a mean BMI of 24.98 − 1.24 = 23.74, whereas for the middle-aged the mean BMI is slightly higher (+0.12), and finally for older respondents we must add 0.85 to 24.98 to find their estimated mean BMI. Note that the effects no longer add up to 0, as we take into account the unequal numbers of observations. When the six interactions are added in Model 2, nothing changes in the intercept or main effects, because the interactions have a mean of 0 and are orthogonal to the main effects. The interpretation of these interactions is straightforward: it is the extra estimated mean BMI over and above the main effects found in the model without interactions. For instance the young respondents with no children have a BMI which is an extra −0.17 lower compared to 24.98 (on top of the main effects −1.24 and −0.61). Note that the equal sized interaction effects −0.17 (childless × young) and 0.17 (childless × older) have quite different

*t*values (−2.75 vs. 0.39). This is a direct result of taking into account the different number of respondents per category; there are much less older people than younger people, so the power of that test is lower. Note also that the

*t*value for children × older and childless × older is equal (−0.39) as the dichotomy children/childless is mutually exclusive. Note further that weighted effect coded interaction effects do not add up to zero as in effect coding, again due to the different numbers per category. We finally add that in Table 4 the explained variances are the same in all three models 1 and in all three models 2. So, no matter which type of coding is used, the predicted BMI scores are exactly the same. The only difference is the type of base line one wishes to use. In dummy coding this base line is a particular subset of respondents, in effect coding it is a grand mean of estimates (neglecting the possible unbalance in the data), while in weighted effect coding the base line is the weighted main effect.

Coding scheme for the *weighted effect coded* main and interactions effects for the childless, middle-aged and older-aged (omitted categories are with children, young, and childless × young)

Categories | Weighted effect coding | ||||
---|---|---|---|---|---|

Main effects | Interactions | ||||

Childless | Middle | Older | Childless | Childless | |

With children and younger | −( | −( | −( | ( | ( |

With children and middle-aged | −( | 1 | 0 | −( | 0 |

With children and older | −( | 0 | 1 | 0 | −( |

Childless and younger | 1 | −( | −( | −( | −( |

Childless and middle-aged | 1 | 1 | 0 | 1 | 0 |

Childless and older | 1 | 0 | 1 | 0 | 1 |

Ordinary least squares regression effects on the body mass index (BMI), using dummy coding, effect coding, and weighted effect coding, without interactions (Model 1) and with interactions (Model 2), number of cases per category between brackets (*n*)

Data source: Eisinga et al. (2002, 2012a, b), total *n* = 3314

OLS effects on BMI | Dummy coding | Effect coding | Weighted effect coding | |||
---|---|---|---|---|---|---|

b-estimates | | b-estimates | | b-estimates | | |

| ||||||

Intercept | 24.02 | 118.58 | 24.73 | 317.14 | 24.98 | 389.21 |

Having children | ||||||

With children (2254) | 0.00 (ref) | 0.45 | 5.51 | 0.29 | 5.51 | |

Childless (1060) | −0.90 | −5.51 | −0.45 | −5.51 | −0.61 | −5.51 |

Age-group | ||||||

Young (610) | 0.00 (ref) | −1.15 | −8.46 | −1.24 | −7.81 | |

Middle (2111) | 1.36 | 6.93 | 0.21 | 2.28 | 0.12 | 2.38 |

Older (593) | 2.09 | 8.56 | 0.94 | 7.52 | 0.85 | 5.99 |

Variance explained | 6.1 % | 6.1 % | 6.1 % | |||

| ||||||

Intercept | 24.88 | 67.06 | 24.88 | 223.52 | 24.98 | 389.54 |

Having children | ||||||

With children (2254) | 0.00 (ref) | 0.56 | 4.99 | 0.29 | 5.51 | |

Childless (1060) | −1.92 | −4.74 | −0.56 | −4.99 | −0.61 | −5.51 |

Age-group | ||||||

Young (610) | 0.00 (ref) | −0.97 | −5.97 | −1.24 | −7.80 | |

Middle (2111) | 0.46 ns | 1.21 | 0.11 ns | 0.87 | 0.12 | 2.39 |

Older (593) | 1.22 | 3.01 | 0.86 | 4.72 | 0.85 | 5.99 |

Children × young (99) | Not applicable | 0.41 | 2.50 | 0.86 | 2.75 | |

Children × middle (1624) | Not applicable | −0.21 ns | −1.66 | −0.05 | −2.00 | |

Children × older (531) | Not applicable | −0.20 ns | −1.10 | −0.02 ns | −0.39 | |

Childless × young (511) | 0.00 (ref) | −0.41 | −2.50 | −0.17 | −2.75 | |

Childless × middle (487) | 1.22 | 2.72 | 0.21 ns | 1.66 | 0.15 | 2.00 |

Childless × older (62) | 1.21 ns | 1.88 | 0.20 ns | 1.10 | 0.17 ns | 0.39 |

Variance explained | 6.3 % | 6.3 % | 6.3 % |

To save space we did not include control variables in our models, the interpretation, however, is basically the same: the weighted effect coded interaction effects still reflect deviations from the weighted main effects, only this time after taking into account one or more control variables. Because the weighted effect coded interactions may be correlated with the control variable(s), the main effects in a controlled model with and without weighted coded interaction parameters can be different in such cases (see our website for an example). The interaction between weighted effect coded variables and interval/ratio scaled variables is available on our website as well.

To conclude: whenever non-directional interaction hypotheses are tested using unbalanced data and this unbalancedness is deemed relevant for the target population, weighted effect coded interactions are to be preferred over effect coded interactions.

### Weighted effect coded interactions in generalized linear models

In this contribution, we showed that weighted effect coded interaction effects represent deviations from the overall main effects (i.e., the main effects found in a model without interaction). This general interpretation holds for any generalized linear model. However, we must add that in logistic regression models the main and interaction effects relate to the odds (i.e., *p* _{1}/(1 **−** *p* _{1})). They do not directly relate to *p* _{1} itself, i.e., the estimated probability to score 1 on the dependent variable. In fact, even without interaction parameters, the effects of the predictor variables in a logistic regression model exhibit interaction when the probability (*p* _{1}) is considered (Mood 2010).

## Notes

### Acknowledgments

The authors are grateful to Thomas Kohlmann and an anonymous reviewer for helpful comments on a previous version of this manuscript and suggestions for improvements.

### Compliance with ethical standards

#### Ethical approval

All procedures performed in studies involving human participants were in accordance with the ethical standards of the institutional and/or national research committee and with the 1964 Helsinki declaration and its later amendments or comparable ethical standards.

## References

- Berger MPF, Wong W-K (2009) An introduction to optimal designs for social and biomedical research. Wiley, New YorkCrossRefGoogle Scholar
- Eisinga R, Coenders M, Felling A, te Grotenhuis M, Oomens S, Scheepers P (2002) Religion in Dutch society 2000. Documentation of a national survey on religious and secular attitudes in 2000. NIWI-Steinmetz Archive, AmsterdamGoogle Scholar
- Eisinga R, Need A, Coenders M, de Graaf ND, Lubbers M, Scheepers P, Levels M, Thijs P (2012a) Religion in Dutch society 2005. Documentation of a national survey on religious and secular attitudes and behaviour in 2005. DANS Data Guide 10. Amsterdam University Press, The HagueGoogle Scholar
- Eisinga R, Kraaykamp G, Scheepers P, Thijs P (2012b) Religion in Dutch society 2011–2012. Documentation of a national survey on religious and secular attitudes and behaviour in 2011–2012. DANS Data Guide 11. Amsterdam University Press, The HagueGoogle Scholar
- Hardy MA (1993) Regression with dummy variables. Sage, Newbury ParkCrossRefGoogle Scholar
- Mood C (2010) Logistic regression: why we cannot do what we think we can do, and what we can do about it. Eur Sociol Rev 26:67–82CrossRefGoogle Scholar
- Sweeney R, Ulveling EF (1972) A transformation for simplifying the interpretation of coefficients of binary variables in regression analysis. Am Stat 26:30–32Google Scholar
- te Grotenhuis M, Pelzer B, Eisinga R, Nieuwenhuis R, Schmidt-Catran A, Konig R (2016) When size matters: advantages of weighted effect coding in observational studies. Int J Public Health. 10.1007/s00038-016-0901-1
- Umberson D, Lui H, Mirowsky J, Reczek C (2011) Parenthood and trajectories of change in body weight over the life course. Soc Sci Med 73:1323–1331CrossRefPubMedPubMedCentralGoogle Scholar

## Copyright information

**Open Access**This article is distributed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits unrestricted use, distribution, and reproduction in any medium, provided you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license, and indicate if changes were made.