[R] lm question

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Oct 9 13:40:33 CEST 2000


> Date: Mon, 09 Oct 2000 12:43:20 +0200 (CEST)
> From: Martyn Plummer <plummer at iarc.fr>
> 
> On 09-Oct-00 Peter Dalgaard BSA wrote:
> > Bill Simpson <wsi at gcal.ac.uk> writes:
> > 
> >> I have not really used lm before and I was hoping for some help on a
> >> simple problem.
> > 
> >> I want to fit a model that has one y-intercept and three slopes, one for
> >> each group.
> > 
> > Actually, this is not so simple because it goes somewhat against the
> > grain of the way the S/R model formulas are designed (they generally
> > assume that identical intercepts only make sense with identical
> > slopes).
> > 
> > However, 
> > 
> >> lm(y~x:(grp-1)+1)
> > 
> > Call:
> > lm(formula = y ~ x:(grp - 1) + 1)
> > 
> > Coefficients:
> > (Intercept)       x.grpa       x.grpb       x.grpc  
> >    -0.80977      0.01847      0.13124      0.14259  
> > 
> > The form grp-1 gives you the "no-intercept" coding of the grp factor
> > and its interaction (":") with x specifies separate slopes for each
> > group. Once you've used "-1" the intercept disappears from the model,
> > so you need to add it back in with "+1". 
> 
> Is that really necessary?

It shouldn't be.

> R> lm(y ~ grp:x, data=foo)
> 
> Call:
> lm(formula = y ~ grp:x, data = foo)
> 
> Coefficients:
> (Intercept)       grpa.x       grpb.x       grpc.x  
>    -0.80977      0.01847      0.13124      0.14259  

In 1.1.1 each of these will only work in some codings, in particular
not for ordered factors.  But it should work for all (does in S) and is
fixed in the R-devel snapshot.

-- 
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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list