Linear regression is of the form
y = mx + b
right?
And in R, - means omit, as in
mydataframe[, -1]
right?
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".
Sarah
On Wed, Sep 21, 2016 at 10:19 AM, mviljamaa 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
http://www.functionaldiversity.org
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.