Use "colon" between two characters as a regressor in lm()
Asked Answered
M

2

14

What does it mean when we put a colon : between two characters? I'm sure it's not saying from character A to character B.

Here is the code:

fit9=lm(Sales~.+Income:Advertising+Price:Age,data=Carseats)

Coefficients:
                     Estimate  Std. Error   t value Pr(>|t|)    
(Intercept)         6.5755654  1.0087470   6.519 2.22e-10 ***
CompPrice           0.0929371  0.0041183  22.567  < 2e-16 ***
Income              0.0108940  0.0026044   4.183 3.57e-05 ***
Advertising         0.0702462  0.0226091   3.107 0.002030 ** 
Population          0.0001592  0.0003679   0.433 0.665330    
Price              -0.1008064  0.0074399 -13.549  < 2e-16 ***
ShelveLocGood       4.8486762  0.1528378  31.724  < 2e-16 ***
ShelveLocMedium     1.9532620  0.1257682  15.531  < 2e-16 ***
Age                -0.0579466  0.0159506  -3.633 0.000318 ***
Education          -0.0208525  0.0196131  -1.063 0.288361    
UrbanYes            0.1401597  0.1124019   1.247 0.213171    
USYes              -0.1575571  0.1489234  -1.058 0.290729    
Income:Advertising  0.0007510  0.0002784   2.698 0.007290 ** 
Price:Age           0.0001068  0.0001333   0.801 0.423812    

I couldn't understand why does two extra regressors Income:Advertising and Price:Age mean?

Methodius answered 24/3, 2017 at 11:16 Comment(2)
Read help("formula").Discriminatory
Does this answer your question? " * " vs " : " in R for modellingSupplementary
G
15

As noted in the comments above, : denotes an interaction term between regressors. If you want to consider each regressor on its own and the interaction, then you can use x1*x2 which is the same as x1 + x2 + x1:x2.

Gault answered 24/3, 2017 at 11:24 Comment(0)
B
0

I think that there are two confusing things here:

  • The term "interaction" is used here to mean "multiplication".
  • : is used to represent "multiplication", whereas * is usually used in everyday life to mean "multiplication".

Let's use mathematical functions/models to explain:

  • The model/math function for x1:x2 is: enter image description here, where c is the coefficient to be determined with lm.
  • The model for x1 + x2 + x1:x2 (so x1*x2) is: enter image description here, where a1, a2 and c are the coefficients to be determined.
Basset answered 28/12, 2022 at 10:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.