Asterisk (*) vs. colon (:) in R formulas [closed]
Asked Answered
G

1

32

I always thought that * and : meant the same thing when adding interaction terms in R formulas. For example:

  • amount_of_gas ~ temperature*gas_type
  • amount_of_gas ~ temperature:gas_type

However, now that I've started using Generalized Linear Models (glm() in R) I see that these generate different scores, different estimates, etc. when I switch between the two. Can someone explain to me why this happens? Is it a problem with the stats package in R?

##UPDATE## April 26th, 2021

It's been ~4.5 years or so since I asked this question and I keep getting notified that it still has a lot of traffic. Here's the short answer: y~x*z basically means: y~x+z+x:z while y~x:z is just the interaction of x and z (as described in the answer below)

Glazer answered 12/11, 2016 at 20:39 Comment(5)
This explains it pretty well, which I found by Googling "asterisk vs colon in R modelling"Stable
Thank you so much!Glazer
Now that you've started using GLMs, wouldn't it be natural to read ?glm? It's all there.Dexamethasone
hmmmm i might try that. You're input has been so valuable.Glazer
@RichScriven, but now this post is the first hit when googling "asterisk vs colon in R modelling"Reest
H
32

From help(formula):

 In addition to ‘+’ and ‘:’, a number of other operators are useful
 in model formulae.  The ‘*’ operator denotes factor crossing:
 ‘a*b’ interpreted as ‘a+b+a:b’.
Howerton answered 12/11, 2016 at 20:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.