[R] First Variable in lm
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed Mar 24 19:49:09 CET 2004
It isn't lm but terms.formula. Compare
terms(dat$y ~ .,data = dat)
terms(dat[, 1] ~ ., data = dat)
Now as to why, exactly, see the C code in src/main/model.c.
The short answer is that dat$y matches y, and dat[, 1] does not.
(I am not at all sure the first is intentional.)
On Wed, 24 Mar 2004, Baskin, Robert wrote:
> First: Thanks to everyone who develops R, maintains r-help, and participates
> in the list :)
>
> This is a silly follow up question.
>
> >From Andy Liaw:
> > dat <- data.frame(y=rnorm(10), x1=rnorm(10), x2=rnorm(10))
>
> (Silly question - if the answer is on the lm or formula help page I didn't
> get it:)
> Why does lm | formula treat dat[,1] slightly differently than dat$y?
--
Brian D. Ripley, ripley at 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
More information about the R-help
mailing list