[R] Why removing the (Intercept) from lm is done by adding -1?

Sarah Goslee sarah.goslee at gmail.com
Wed Sep 21 16:34:00 CEST 2016

Linear regression is of the form

y = mx + b


And in R, - means omit, as in

mydataframe[, -1]


But when you specify a formula within lm(), the intercept is implicit.
That is, you write:

y ~ x

and m and b are fitted.

So if you want to omit the intercept, you use 1 as a placeholder
rather than leaving the - dangling somewhere.

y ~ x - 1

But as you say, there are other ways, so use the one you like.

Note that if you really wanted to subtract 1 from x before fitting the
model, you'd need to make that clear to R:

y ~ I(x - 1)

This is all in the help for formula, where it says "The - operator
removes the specified terms".


On Wed, Sep 21, 2016 at 10:19 AM, mviljamaa <mviljamaa at kapsi.fi> wrote:
> So I found out that to remove the (Intercept) term from lm's model one can
> add -1 to the predictors. I.e. do lm(resp ~ x1 + x2 - 1)
> Another way is to add 0, e.g. lm(resp ~ 0 + x1 + x2).
> Adding (or setting the (Intercept) term) zero seems more logical than
> subtracting one, but why is there the method of subtracting one? Why does
> subtracting one mean that the (Intercept) term disappears?
Sarah Goslee

More information about the R-help mailing list