concept interaction in category R

This is an excerpt from Manning's book R in Action, Third Edition.
8.2.5 Multiple linear regression with interactions
Some of the most interesting research findings are those involving interactions among predictor variables. Consider the automobile data in the mtcars data frame. Let’s say that you’re interested in the impact of automobile weight and horsepower on mileage. You could fit a regression model that includes both predictors, along with their interaction, as shown in the next listing.
Listing 8.5 Multiple linear regression with a significant interaction term
> fit <- lm(mpg ~ hp + wt + hp:wt, data=mtcars) > summary(fit) Call: lm(formula=mpg ~ hp + wt + hp:wt, data=mtcars) Residuals: Min 1Q Median 3Q Max -3.063 -1.649 -0.736 1.421 4.551 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 49.80842 3.60516 13.82 5.0e-14 *** hp -0.12010 0.02470 -4.86 4.0e-05 *** wt -8.21662 1.26971 -6.47 5.2e-07 *** hp:wt 0.02785 0.00742 3.75 0.00081 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 2.1 on 28 degrees of freedom Multiple R-squared: 0.885, Adjusted R-squared: 0.872 F-statistic: 71.7 on 3 and 28 DF, p-value: 2.98e-13You can see from the Pr(>|t|) column that the interaction between horsepower and car weight is significant. What does this mean? A significant interaction between two predictor variables tells you that the relationship between one predictor and the response variable depends on the level of the other predictor. Here it means the relationship between miles per gallon and horsepower varies by car weight.
The model for predicting mpg is mpg = 49.81 – 0.12 × hp – 8.22 × wt + 0.03 × hp × wt. To interpret the interaction, you can plug in various values of wt and simplify the equation. For example, you can try the mean of wt (3.2) and one standard deviation below and above the mean (2.2 and 4.2, respectively). For wt=2.2, the equation simplifies to mpg = 49.81 – 0.12 × hp – 8.22 × (2.2) + 0.03 × hp × (2.2) = 31.41 – 0.06 × hp. For wt=3.2, this becomes mpg = 23.37 – 0.03 × hp. Finally, for wt=4.2 the equation becomes mpg = 15.33 – 0.003 × hp. You see that as weight increases (2.2, 3.2, 4.2), the expected change in mpg from a unit increase in hp decreases (0.06, 0.03, 0.003).
You can visualize interactions using the effect() function in the effects package. The format is

This is an excerpt from Manning's book R in Action, Second Edition: Data analysis and graphics with R.
Some of the most interesting research findings are those involving interactions among predictor variables. Consider the automobile data in the mtcars data frame. Let’s say that you’re interested in the impact of automobile weight and horsepower on mileage. You could fit a regression model that includes both predictors, along with their interaction, as shown in the next listing.
Listing 8.5. Multiple linear regression with a significant interaction term
> fit <- lm(mpg ~ hp + wt + hp:wt, data=mtcars) > summary(fit) Call: lm(formula=mpg ~ hp + wt + hp:wt, data=mtcars) Residuals: Min 1Q Median 3Q Max -3.063 -1.649 -0.736 1.421 4.551 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 49.80842 3.60516 13.82 5.0e-14 *** hp -0.12010 0.02470 -4.86 4.0e-05 *** wt -8.21662 1.26971 -6.47 5.2e-07 *** hp:wt 0.02785 0.00742 3.75 0.00081 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 2.1 on 28 degrees of freedom Multiple R-squared: 0.885, Adjusted R-squared: 0.872 F-statistic: 71.7 on 3 and 28 DF, p-value: 2.98e-13You can see from the Pr(>|t|) column that the interaction between horsepower and car weight is significant. What does this mean? A significant interaction between two predictor variables tells you that the relationship between one predictor and the response variable depends on the level of the other predictor. Here it means the relationship between miles per gallon and horsepower varies by car weight.
The model for predicting mpg is
. To interpret the interaction, you can plug in various values of wt and simplify the equation. For example, you can try the mean of wt (3.2) and one standard deviation below and above the mean (2.2 and 4.2, respectively). For wt=2.2, the equation simplifies to
. For wt=3.2, this becomes
. Finally, for wt=4.2 the equation becomes
. You see that as weight increases (2.2, 3.2, 4.2), the expected change in mpg from a unit increase in hp decreases (0.06, 0.03, 0.003).
You can visualize interactions using the effect() function in the effects package. The format is
. To interpret the interaction, you can plug in various values of wt and simplify the equation. For example, you can try the mean of wt (3.2) and one standard deviation below and above the mean (2.2 and 4.2, respectively). For wt=2.2, the equation simplifies to
. For wt=3.2, this becomes
. Finally, for wt=4.2 the equation becomes
. You see that as weight increases (2.2, 3.2, 4.2), the expected change in mpg from a unit increase in hp decreases (0.06, 0.03, 0.003).