[R] lm question

Martyn Plummer plummer at iarc.fr
Mon Oct 9 12:43:20 CEST 2000


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?

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  

Martyn
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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