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

S Ellison S.Ellison at LGCGroup.com
Wed Sep 21 17:34:35 CEST 2016


> Subject: Re: [R] Why removing the (Intercept) from lm is done by adding -1?
> 
> And in R, - means omit, as in
> mydataframe[, -1]
> right?

Not really, no. 
In the specific interpretation of an R model formula, '-' means 'remove the _term_ following '-'  ...'.  As below:
> This is all in the help for formula, where it says "The - operator removes the
> specified terms".

Almost everywhere else, '-'  it means negate as a unary operator and subtract as a binary operator. 
In '[', '-' still means negate, not remove. It's just that '[' uses negative _numbers_ as a special case to denote omission. As a recent post noted, [-"601",] does not work.

> > 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?
See above; '-' _in a formula_ means 'remove the following term'

Following that consistently, if there's a weirdness there, it's that ~0+x works to omit the intercept, not that ~x-1 does. 

But that arises from a slightly different, but still fairly reasonable, perspective on describing the model.

S Ellison



*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}



More information about the R-help mailing list