Visualization of two different two way interaction of three variables in one model (in R)

98 views Asked by At

Suppose we have three independent variables X=(X_1, X_2, X_3), and a dependent variable Y. If we have a regression model as follow

Y = \alpha+\beta_1 X_1 + \beta_2 X_2 + \beta_3 X_3 + \beta_{12} X_1 X_2 + \beta_{23} X_2 X_3 + \epsilon.

Here is an example: There is a data set as follow: Sample data

In this, example there are two continuous variables "Y" and "age", a binary variable "Sex" and a categorical with three categories named "Cat3gr".

The simple model is :

Fitmodel<- lm(Y ~ Sex+age+Cat3gr+Sex*Cat3gr*age, data = data)

summary(Fitmodel)

with the result of :

Call:
lm(formula = Y ~ Sex + age + Cat3gr + Sex * Cat3gr * age, data = data)

Residuals:
   Min     1Q Median     3Q    Max 
-3.963 -0.528  0.270  0.850  2.274 

Coefficients:
                    Estimate Std. Error t value Pr(>|t|)  
(Intercept)         -2.29563    1.18565   -1.94    0.053 .
SexMale             -0.16346    1.74527   -0.09    0.925  
age                  0.06408    0.03098    2.07    0.039 *
Cat3gr2             -0.65256    1.31432   -0.50    0.620  
Cat3gr3              0.12589    1.60637    0.08    0.938  
SexMale:Cat3gr2      2.73782    1.91548    1.43    0.153  
SexMale:Cat3gr3      1.42120    2.50115    0.57    0.570  
SexMale:age          0.00207    0.04619    0.04    0.964  
age:Cat3gr2         -0.00546    0.03359   -0.16    0.871  
age:Cat3gr3          0.00610    0.04204    0.15    0.885  
SexMale:age:Cat3gr2 -0.05389    0.04963   -1.09    0.278  
SexMale:age:Cat3gr3 -0.03253    0.06617   -0.49    0.623  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.28 on 762 degrees of freedom
  (26 observations deleted due to missingness)
Multiple R-squared:  0.0974,    Adjusted R-squared:  0.0843 
F-statistic: 7.47 on 11 and 762 DF,  p-value: 2.85e-12

How can I visualize two different two interaction way in one plot in R?

I know how to visualize two-way interaction or three-way interaction when there is only one term interaction in the model, but no idea how can I visualize two terms of two-way interaction.

0

There are 0 answers