From ripley at stats.ox.ac.uk  Tue Aug  5 09:00:42 2003
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Tue Aug  5 09:00:21 2003
Subject: [Rd] unexpected behaviour in lm() (PR#3657)
In-Reply-To: <Pine.LNX.4.44.0308050723450.24036-100000@gannet.stats>
Message-ID: <Pine.LNX.4.44.0308050759480.24247-100000@gannet.stats>

On Tue, 5 Aug 2003, Prof Brian Ripley wrote:

> On Mon, 4 Aug 2003, Thomas Lumley wrote:
> 
> > On Mon, 4 Aug 2003 ottk@bms.com wrote:
> > 
> > >
> > > > lm(c(1:10) ~ c(1:10))
> > >
> > > Call:
> > > lm(formula = c(1:10) ~ c(1:10))
> > >
> > > Coefficients:
> > > (Intercept)
> > >         5.5
> > 
> > It's a feature. Unfortunately it's not a well documented feature.  A
> > variable on the right-hand side of the formula is removed if it has the
> > same name as the left-hand side of the formula.  This is done in
> > model.matrix.
> > 
> > It's a feature because
> >  - it's always been done that way
> >  - it allows  y~. to specify all the columns of a data frame *except* y
> > 
> > It needs to be documented. Unfortunately the logical place is
> > help(model.matrix), where no-one will look.
> 
> It could give an informative warning though, except in the y ~ . case.
> I think that is possible: let me look into the code.

That's easy, as the y ~ . case is handled in terms(). I've added a 
warning, documentation in ?model.matrix and a cross-ref in ?lm.

Brian

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


[Rd] unexpected behaviour in lm() (PR#3657)
Prof Brian Ripley