Here is an example looking at the effects of illiteracy and murder rates on income.
states <- as.data.frame(state.x77)
describe(states)
## vars n mean sd median trimmed mad min
## Population 1 50 4246.42 4464.49 2838.50 3384.28 2890.33 365.00
## Income 2 50 4435.80 614.47 4519.00 4430.08 581.18 3098.00
## Illiteracy 3 50 1.17 0.61 0.95 1.10 0.52 0.50
## Life Exp 4 50 70.88 1.34 70.67 70.92 1.54 67.96
## Murder 5 50 7.38 3.69 6.85 7.30 5.19 1.40
## HS Grad 6 50 53.11 8.08 53.25 53.34 8.60 37.80
## Frost 7 50 104.46 51.98 114.50 106.80 53.37 0.00
## Area 8 50 70735.88 85327.30 54277.00 56575.72 35144.29 1049.00
## max range skew kurtosis se
## Population 21198.0 20833.00 1.92 3.75 631.37
## Income 6315.0 3217.00 0.20 0.24 86.90
## Illiteracy 2.8 2.30 0.82 -0.47 0.09
## Life Exp 73.6 5.64 -0.15 -0.67 0.19
## Murder 15.1 13.70 0.13 -1.21 0.52
## HS Grad 67.3 29.50 -0.32 -0.88 1.14
## Frost 188.0 188.00 -0.37 -0.94 7.35
## Area 566432.0 565383.00 4.10 20.39 12067.10
states$Illiteracy_m<- states$Illiteracy-mean(states$Illiteracy, na.rm=T)
states$Murder_m<- states$Murder-mean(states$Murder, na.rm=T)
fiti <- lm(Income ~ Illiteracy_m+Murder_m+Illiteracy_m * Murder_m, data = states)
mcSummary(fiti)
## lm(formula = Income ~ Illiteracy_m + Murder_m + Illiteracy_m *
## Murder_m, data = states)
##
## Omnibus ANOVA
## SS df MS EtaSq F p
## Model 6055590 3 2018530.1 0.327 7.461 0
## Error 12445502 46 270554.4
## Corr Total 18501092 49 377573.3
##
## RMSE AdjEtaSq
## 520.148 0.283
##
## Coefficients
## Est StErr t SSR(3) EtaSq tol CI_2.5
## (Intercept) 4617.315 96.338 47.928 621490293.89 0.980 NA 4423.396
## Illiteracy_m -246.592 200.260 -1.231 410227.87 0.032 0.371 -649.694
## Murder_m 9.815 28.802 0.341 31422.39 0.003 0.488 -48.159
## Illiteracy_m:Murder_m -117.096 40.131 -2.918 2303391.14 0.156 0.678 -197.876
## CI_97.5 p
## (Intercept) 4811.234 0.000
## Illiteracy_m 156.510 0.224
## Murder_m 67.790 0.735
## Illiteracy_m:Murder_m -36.315 0.005
\(Income = 4617.315 -246.592*Illiteracy_m + 9.815*Murder_m -117.096*Illiteracy_m*Murder_m\)
The effect of Illiteracy_m on Income is \(-246.592 -117.096*Murder_m\). When murder_m = 0 (aka mean murder rates), the effect of Illiteracy_m is \(-246.592-(117.096*0) = -246.592\). For two cities with mean murder rates (Murder_m=0), we expect the one with a one unit increase in Illiteracy to have 246.592 lower Income
For cities with the highest murder rate (murder_m=15.1), the effect of illiteracy on income is \(-246.592-(117.096*15.1) = -2014.742\). For two cities with the highest murder rates (Murder_m=15.1), we expect the one with a one unit increase in Illiteracy to have -2014.742 lower Income
Because of the interaction, the effect of having higher illiteracy rate is different for different rates of murder. Another way of saying this is that the slopes of the regression lines between illiteracy and income are different for the different levels of murder.
the interaction indicates how different those slopes are. We can also say as murder rates increase 1, the relationship between illiteracy and income change by -117.096.
plot_model(fiti,
type = "pred",
terms = c("Illiteracy_m","Murder_m"))