1

In R formulas (e.g. for lm), which is the difference between y ~ 1, y ~ 0 and y ~ -1?

DGMartin
  • 67
  • 7
  • 1
    some of these [answers](https://stackoverflow.com/questions/13366755/what-does-the-r-formula-y1-mean?rq=1) might be helpful - the question is quite close to being a duplicate. – Miff Nov 06 '20 at 13:35

1 Answers1

4

From the ?formula documentation:

 The ‘-’ operator removes the specified terms, so that ‘(a+b+c)^2 -
 a:b’ is identical to ‘a + b + c + b:c + a:c’.  It can also used to
 remove the intercept term: when fitting a linear model ‘y ~ x - 1’
 specifies a line through the origin.  A model with no intercept
 can be also specified as ‘y ~ x + 0’ or ‘y ~ 0 + x’.

So:

  • y ~ 1 includes an intercept
  • y ~ 0 does not include an intercept
  • y ~ -1 does not include an intercept

The last two are functionally equivalent.

Vincent
  • 15,809
  • 7
  • 37
  • 39