DGMartin
DGMartin

Reputation: 67

What is the difference between y ~ 1, y ~ 0 and y ~ -1 in R formulas?

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

Upvotes: 1

Views: 600

Answers (1)

Vincent
Vincent

Reputation: 17805

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.

Upvotes: 4

Related Questions