R 公式中 y ~ 1、y ~ 0 和 y ~ -1 有什么区别?

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

在 R 公式中(例如 lm),这是 y ~ 1y ~ 0y ~ -1 之间的区别?

来自 ?formula 文档:

 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’.

所以:

  • y ~ 1 包括截距
  • y ~ 0 不包括拦截
  • y ~ -1 不包括拦截

最后两个在功能上是等价的。