Calculating interaction effects from OLS coefficients: Interaction between two categorical independent variables Jane E. Miller, PhD As discussed in the earlier modules on specifying models and defining variables to test for interactions, interactions are used to test whether the association between one independent variable and the dependent variable differs depending on values of a second independent variable. An example is whether the association between socioeconomic status and birth weight differs for infants of different racial/ethnic groups. In this module, I show how to calculate the overall shape of an interaction pattern between two categorical independent variables, working from the estimated coefficients from an ordinary least squares regression. A separate module shows how to calculate the net effect of an interaction between two categorical independent variables for a logit model. Please watch this one first because it goes into a lot more detail about the conceptual steps involved.
Overview General equation for a model with main effects and interactions Review: Coding of main effects and interaction terms Solving for the interaction pattern based on estimated coefficients Graphical depiction of the interaction pattern
Estimated coefficients OLS model of birth weight (grams) β Main effect terms Non-Hispanic black (NHB) –168 Less than high school (<HS) –54 High school diploma (=HS) –62 Interaction terms NHB_<HS –39 NHB_=HS +18 This table displays the estimated coefficients (abbbreviated B) from our OLS model of birth weight in grams. Estimated coefficients for other variables controlled in the model would be reported in a full table of regression estimates, but are not shown here because they are not involved in the calculation of the interaction pattern. Note that sometimes you will want to calculate the predicted value of the dependent variable by setting the values of other independent variables at their mean values in the sample, or at specified values of interest, but that is the subject of a different lecture! I have used color coding to indicate which coefficients are for main effects terms (yellow) and which are for interaction terms (green). The main effects terms for this interaction include a B for the dummy variable for non-Hispanic black, and two Bs for the dummy variables <HS and =HS, which together capture mother’s educational attainment. The interaction terms include one dummy variable for the COMBINATION non-Hispanic black with <HS, and one dummy variable for the combination non-Hispanic black with =HS. The footnote reminds us of the reference category, which is the omitted category for each of the two categorical independent variables involved in the interaction. Reference category: Non-Hispanic whites with >HS education. All variables are dummy-coded: 1 = named value, 0 = other values.
Interpreting the main effects The main effect terms estimate the difference in birth weight relative to those in the reference category (non-Hispanic whites with more than complete high school education). βNHB is an estimate of the difference in intercept between non-Hispanic black infants and those in the reference category. β<HS and β=HS estimate the difference in intercept between infants in the reference category and those born to mothers with less than complete high school and complete high school, respectively. Units are those of the dependent variable, grams. The main effect terms estimate the difference in birth weight compared to those in the reference category (non-Hispanic whites with more than complete high school education), where the difference is measured in the original units of the dependent variable, or birth weight in grams. Because the independent variables are categorical, their respective coefficients estimate the difference in birth weight for the category indicated by the dummy versus the reference category, which measures the difference in intercept relative to the reference category. See podcast on interpreting regression coefficients for a review. For example, BNHB measures how much more or less black infants weigh compared to their white peers born to mothers with >HS education . Since BNHB is -168, that means that controlling for other variables in the model, black infants weigh on average 168 grams less than their white counterparts. B<HS and B=HS estimate the difference in birth weight for infants in those groups compared to white infants born to mothers with >HS education. Both education coefficients are negative, so again, those groups weigh LESS than the reference category in this sample.
Interpreting the interaction between race and education The race_education interaction tests whether the difference in birth weight for <HS versus =HS is different for non-Hispanic black infants than for their non-Hispanic white counterparts. We calculate the overall effect for NHB and <HS as = βNHB+ β<HS + βNHB_<HS If the difference in birth weight across mothers’ education categories were the same for blacks as for whites, then the interaction term βNHB_<HS = 0. But, we can’t interpret that difference in birth weight as uniform for ALL black infants because the model is also testing whether that difference varies by mother’s educational attainment. The estimated overall difference in birth weight for black infants born to mothers with <HS can be calculated as the sum of the three coefficients that pertain to that group: the two relevant main effects terms BNHB, and B<HS, and the interaction term BNHB<HS If the difference in birth weight across mother’s education groups were the same for both blacks and whites, then the estimated interaction coefficient BNHB<HS would equal zero (or not be statistically significantly different from 0). That would mean that we do not need interaction terms in our model, and could completely predict birth weight for that group using the two main effects terms alone. Sometimes when testing an interaction between two multicategory independent variables, it is possible that individual interaction terms will not be statistically significant but the overall interaction will be. See the module on specifying regression models to test interactions for more on this issue.
Calculating overall effect of interaction for specific case characteristics The general equation to calculate how a case differs from the reference category: main effects coefficients interaction term coefficients values of the independent variables = (βNHB × NHB) + (β<HS × <HS) + (β=HS × =HS) + (βNHB_<HS × NHB_<HS) + (βNHB_=HS × NHB_=HS) To see which βs pertain to which cases, fill in values of variables for different combinations of race and education. To calculate the overall effect of the interaction, we can solve for specific values of the independent variables. The general equation [read slide]
Review: Coding of main effects and interaction term variables Case characteristics Main effects terms Interaction terms Race Education Race & education NHB <HS =HS NHB_<HS NHB_=HS Non-H white & <HS 1 Non-H white & =HS Non-H white & >HS Non-H black & <HS Non-H black & =HS Non-H black & >HS Here, we return to a grid we saw in the podcast on creating variables to test for interactions. It shows the values of each of the 5 variables involved in the main effects and interactions specification. For instance, non-Hispanic white infants born to mothers w/ >HS have values of 0 for each of the five variables because they are in the reference category for both race and educational attainment. Reference category
Cases in the reference category for both independent variables General equation to calculate how a case differs from the reference category: = (βNHB × NHB) + (β<HS × <HS) + (β=HS × =HS) + (βNHB_<HS × NHB_<HS) + (βNHB_=HS × NHB_=HS) Fill in values of variables for non-Hispanic whites with >HS: NHB <HS =HS NHB_<HS NHB_=HS Non-H white & >HS Lets see what that does for our overall calculation. Here I repeat the general equation showing how to calculate the difference in birth weight for a given case compared to the reference category, based on the estimated coefficients and the values of the pertinent independent variables. We see that for NHW <HS, the equation results in a value of 0. = (βNHB × 0) + (β<HS × 0) + (β=HS × 0) + (βNHB_<HS × 0) + (βNHB_=HS × 0) = 0
Cases in the reference category for both independent variables = (βNHB × 0) + (β<HS × 0) + (β=HS × 0) + (βNHB_<HS × 0) + (βNHB_=HS × 0) = 0 All of the coefficients fall out of the equation for non-Hispanic whites born to mothers with >HS because each β is multiplied by a value of 0. Thus, cases in the reference category for both race and education have a calculated overall effect of 0. As it should be, because there is no difference between them and themselves! Let’s think about why that happened What it means And why it makes sense. Each coeff was multiplied by 0, so we have a sum of five zeros. That means that NHW infants born to mothers <HS have a birth weight that is no different from mothers in the ref cat Which makes sense because anyone compared to themselves should have a difference of 0!
Cases in the reference category for 1 but not both independent variables Fill values of variables for non-Hispanic whites with =HS into the general equation: NHB <HS =HS NHB_<HS NHB_=HS Non-H white & =HS 1 = (βNHB × 0) + (β<HS × 0) + (β=HS × 1) + (βNHB_<HS × 0) + (βNHB_=HS × 0) = β=HS Now let’s turn to cases that are in the ref cat for one but not both of the IVs involved in the interaction. For instance, NHW infants born to =HS are in the ref cat for race (NHB = 0) but not for education (=HS=1) So in this case, the coeff on the =HS variable gets multiplied by a 1. The other main effects terms are zero, so those terms fall out of the equation. Because NHB=0, the interaction terms also take on the value 0, so they also fall out of the equation. That leaves us with just B =HS pertaining to infants in this group. In other words, the coeff on =HS by itself will tell us by how much BW differs for NHW infants born to moms =HS compared to NHW infants born to moms >HS (the ref cat) The equation for non-Hispanic white infants born to mothers with a high school diploma collapses to include only β=HS because all of the other coefficients are multiplied by a value of 0.
Cases not in the reference category for either independent variable Fill in values of variables for non-Hispanic blacks with =HS: NHB <HS =HS NHB_<HS NHB_=HS Non-H black & =HS 1 = (βNHB × 1) + (β<HS × 0) + (β=HS × 1) + (βNHB_<HS × 0) + (βNHB_=HS × 1) = βNHB + β=HS + βNHB_=HS Now turning to cases that aren’t in either ref cat – neither race nor education. For instance, NHB and =HS. In that case, both of the main effects terms NHB and =HS take on values of 1, so the respective coeffs for those terms stay in the equation. In addition, the interaction term NHB_=HS takes on the value 1, meaning that the coeff on that interaction term also stays in the equation. So, for cases that are in the ref cat for either of the variables involved in the interaction, the difference in BW for them compared to the ref cat requires adding together three coeffs: 1 each for the two pertinent main effects and the associated interaction. Thus, the equation for non-Hispanic black infants born to mothers with a high school diploma collapses to include the main effects terms for both βNHB and β=HS and the interaction term βNHB_=HS. All the other βs fall out because they are multiplied by 0.
Equations to calculate overall effect Subgroup Equation Value Symbols Estimated β Non-Hisp. white, <HS = β<HS = –54 = –54 Non-Hisp. white, = HS = β=HS = –62 Non-Hisp. white, >HS NA (ref cat) NA Non-Hisp. black, <HS = βNHB + β<Hs + βNHB_<HS = (–168) + (–54) + (–39) = –261 Non-Hisp. black, =HS = βNHB + β=Hs + βNHB_=HS = (–168) + (–62) + (+18) = –212 Non-Hisp. black, >HS = βNHB = –168 On the last slide, I showed you the equation for how to calculate the difference in birth weight for ONE of the groups involved in the interaction: non-Hispanic black infants born to mothers with less than a high school education. However, given how this model is specified, there are five other groups involved in the overall pattern of race and mother’s education, so to see that overall pattern we have to calculate the difference in birth weight for each of those groups. One group is easy: non-Hispanic infants born to women with >HS. By definition, the difference in birth weight for the reference category is zero, because the model is comparing difference in birth weight relative to itself (the same group). In fact, no coefficient is involved in “calculating” this difference precisely because the reference category is the omitted category in the specification, meaning that there is no variable or coefficient for that group. That row of this table is shown in RED with “NA” and the footnote defines the specify identity of the reference category for this particular model. Calculations for three other groups are also pretty easy because they each involve only one estimated coefficient. Those groups – in this example, NHW<HS, NHW=HS, and NHB>HS – are those for which one of the two independent variables involved in the model are in the reference category. E.g., NHW<HS is in the ref cat for race, but not the ref cat for education. Their equations include only main effects terms, shown in yellow as in the previous table. The two calculations involving cases NOT in the reference category for EITHER independent variable in the interaction are the messy ones, each involving two main effects terms (yellow) and an interaction term (green). This complexity of having six distinct groups involved in the interaction pattern, several of which involve multi-term calculations, is why interaction calculations should be done BY THE AUTHOR BEHIND THE SCENES, and the results reported and interpreted in the text! Difference in birth weight (grams) compared to infants born to non-Hispanic white women with more than a high school education = reference category.
Interpreting the sign of the interaction terms: NHB_<HS βNHB_<HS = –39, meaning that infants in that group have lower estimated birth weight than would be predicted from their race and mother’s education alone, based on the main effects (βNHB + β<HS) All three βs (both main effects and interaction) have negative signs, meaning that they cumulate to a large deficit in birth weight for NHB <HS. The β on the interaction term reinforces (adds to) the predicted deficit based on race and education alone. Now let’s look more closely at the specific values of the three coefficients that together determine the overall size of the effect for non-Hispanic black infants born to mothers with <HS education. As we saw earlier, the estimated coefficients on both of the main effects terms (NHB and <HS)are negative, meaning that black infants and those whose mothers have <HS weigh less than white infants born to mothers w/ >HS. The interaction term is also negative, meaning that each of the three coefficient acts to INCREASE the estimated deficit in birth weight for infants who are black and <HS. In other words, the negative term on the interaction terms means that the deficit for NHB<HS is even bigger (more negative) than would have been predicted if blacks had the same shape pattern of education & BW as whites.
Calculating overall effect for non-Hispanic blacks with <HS education βNHB = –168 β<HS = –54 βNHB_<HS = –39 = βNHB + β<HS + βNHB_<HS = (–168) + (–54) + (–39) = –261 Here is a visual depiction of that sum, showing how each of the three negative coefficients contributes to the net deficit of 261 grams for black infants w/ <HS compared to white infants >HS. The NHB main effect is shown with the yellow bar The <HS main effect with the green bar And the NHB<HS interaction coefficient with the orange bar To dramatize the direction of each of the component coefficients, in this animated diagram, I have used an arrow pointing to the left for each of the three negative coefficients. The bracket shows the overall effect, with the equation written alternately using the symbols for the three terms and their respective estimated values from the regression output. Taken together, those three estimated coefficients (Bs) cumulate to a net difference of -261 grams. –39 –54 –168 Compared to infants born to non-Hispanic white women with more than a high school education = reference category.
Interpreting the sign of the interaction term: NHB_=HS On the other hand, βNHB_=HS = +18, meaning that infants in that group have higher estimated birth weight than would be predicted from their race and mother’s education alone, based on the main effects (βNHB and β=HS). Both main effects terms have negative signs, but the interaction term has a positive (opposite) sign, so it partially offsets the deficit in birth weight predicted based on race and education alone. The calculation for the NHB =HS group is different because although each of the two main effects’ coefficients are negative (as we saw before), the interaction term NHB=HS is positive. Because the interaction term has OPPOSITE SIGN as the two main effects, the deficit for NHB<HS is SMALLER (in this case, LESS NEGATIVE) than would have been predicted if blacks had the same shape pattern of education & BW as whites. In other words, the +18 for NHB_=HS partially offsets the -168 and -62 from NHB and =HS terms, respectively.
Calculating overall effect for non-Hispanic blacks with =HS education βNHB = –168 β=HS = –62 Note that interaction term has the OPPOSITE SIGN of the two main effects, partially offsetting their two negative effects on birth weight with a positive effect. βNHB_=HS = +18 = βNHB + β=HS + βNHB_=HS = (–168) + (–62) + (+18) = –212 Here is a visual depiction of how those three terms add together to yield the overall difference in birth weight for non-Hispanic black infants born to mothers with a high school diploma, compared to non-Hispanic white infants born to mothers with >HS. As with the NHB <HS pattern, both the race and education main effects are negative, but in this case, the coefficient for the interaction term NHB_=HS is positive, so it shrinks the overall difference for that group compared to what would be predicted if blacks in that education category had the same BW gap as whites. The red color coding and the opposite direction of the arrow for the interaction term help to emphasize that in this example, the interaction term has a positive sign, partially offsetting the negative contributions of each of the two main effects terms. In this case, the net difference, taking into account all three terms involved in NHB, =HS yields an estimated deficit of 212 grams for black infants born to mothers with = HS compared to white infants born to mothers with >HS. +18 –62 –168 Compared to infants born to non-Hispanic white women with more than a high school education = reference category.
Overall effects of race and mother’s education on birth weight = -261 The overall pattern for race and birth weight is depicted in this graph, which shows the difference in birth weight for each of the six possible combinations of race and education, when each is compared to the reference (omitted) category of NHW and >HS. Because all five of the other groups have lower birth weight (a negative predicted difference), the X-axis is scaled DOWNWARD from 0 (which is shown on the far right of the horizontal axis). At the top of the Y-axis is a 0 for the NHW_>HS group, because by definition the difference in birth weight compared to themselves must be zero. The next three bars are the three groups for which only main effects terms are needed to calculate their birth weight difference compared to the ref cat: orange bar = main effect for <HS, which is the only term needed to calculate the NHW<HS difference green bar = main effect for =HS, the only term involved for NHW=HS Yellow bar = main effect for NHB, the only term involved for NHB_>HS The bottom two bars are for groups that require summing multiple coefficients because they aren’t in the ref cat for either race or education. These repeat the calculations already explained for NHB<HS and NHB=HS, but use the color coding from this slide: NHB<HS involves both main effects terms for NHB (yellow) and <HS (green) as well as the grey & white striped bar for the interaction term NHB_<HS NHB=HS involves both main effects terms for NHB (yellow) and =HS (orange) as well as the grey & orange striped bar for the interaction term NHB_=HS Solid = main effect term. Striped = interaction of education level w/ NHB. Compared to non-Hispanic whites with >HS education.
Predicted value and the intercept term The intercept (or “constant”) term estimates the value of the dependent variable Y for cases in the reference category. To calculate the predicted value of Y for each combination of the Xi, add the estimated coefficient for the intercept (β0) to the βs for each variable that pertains to the category of interest.
Examples: Predicted value For instance, β0 = 3,042.8. So infants who are in the reference category for all variables are estimated to weigh 3,042.8 grams. This includes non-Hispanic whites born to women with >HS. Reference category for race and mother’s education Those born to Mexican American women with less than a high school education: β0 + βMA + β<HS + βMA_<HS = 3,042.8 + (–104.2) + (–54.2) + 99.4 = 3,039.8 – 59.0 = 2,983.8 grams.
Use a spreadsheet to calculate and graph the interaction Spreadsheets can Store The estimated coefficients The input values of the independent variables The correct generalized formula to calculate the predicted values for many combinations of the IVs involved in the interaction Graph the overall pattern See spreadsheet template and podcast
Summary Calculating the overall shape of an interaction pattern requires adding together the pertinent main effects and interaction term coefficients for each possible combination of the two categorical IVs in the interaction. A spreadsheet can be helpful for storing and organizing the coefficients and formulas. Depending on the respective signs of those βs, the interaction can either amplify or dampen the main effects on the component variables.
Suggested resources Chapter 16 of Miller, J.E. 2013. The Chicago Guide to Writing about Multivariate Analysis, 2nd Edition. Chapters 8 and 9 of Cohen et al. 2003. Applied Multiple Regression/Correlation Analysis for the Behavioral Sciences, 3rd Edition. Florence, KY: Routledge.
Supplemental online resources Podcast on creating interaction term variables Spreadsheet template for calculating overall effect of an interaction between two categorical variables.
Suggested practice exercises Study guide to The Chicago Guide to Writing about Multivariate Analysis, 2nd Edition. Questions #3 and 5 in the problem set for Chapter 16 Suggested course extensions for Chapter 16 “Applying statistics and writing” exercise #1.
Contact information Jane E. Miller, PhD jmiller@ifh.rutgers.edu Online materials available at http://press.uchicago.edu/books/miller/multivariate/index.html