[R] how to assign fixed factor in lm

Liaw, Andy andy_liaw at merck.com
Thu Mar 8 21:39:39 CET 2007


Either you did not read docs sufficiently carefully, or the source where
you learn to do this from is questionable.  The lm() function has no
argument called "fixed", and the warning should have made that clear to
you.  It was sheer luck on your part that you happen to put "Value" as
the first variable in "Food", in which case lm() will treat it as the
response and the rest as predictors in the absence of a model formula.

You should try:

lm(Value ~ Gender, Food)

lm() itself has no concept of fixed or random effects.  lme() in the
"nlme" package does, and it has the "fixed" argument.

Andy

From: genomenet at gmail.com
> 
> Hi there,
> 
> > Value=c(709,679,699,657,594,677,592,538,476,508,505,539)
> > Lard=rep(c("Fresh","Rancid"),each=6)
> > Gender=rep(c("Male","Male","Male","Female","Female","Female"),2)
> > Food=data.frame(Value,Lard,Gender)
> > Food
>    Value   Lard Gender
> 1    709  Fresh   Male
> 2    679  Fresh   Male
> 3    699  Fresh   Male
> 4    657  Fresh Female
> 5    594  Fresh Female
> 6    677  Fresh Female
> 7    592 Rancid   Male
> 8    538 Rancid   Male
> 9    476 Rancid   Male
> 10   508 Rancid Female
> 11   505 Rancid Female
> 12   539 Rancid Female
> > lm(fixed=Value~Gender,data=Food)
> Call:
> lm(data = Food, fixed = Value ~ Gender)
> 
> Coefficients:
> (Intercept)   LardRancid   GenderMale  
>       651.4       -142.8         35.5  
> 
> Warning message:
> extra arguments fixed are just disregarded. in: lm.fit(x, y, 
> offset = offset, singular.ok = singular.ok, ...) 
> 
> > lm(fixed=Value~Lard+Gender,data=Food)
> 
> Call:
> lm(data = Food, fixed = Value ~ Lard + Gender)
> 
> Coefficients:
> (Intercept)   LardRancid   GenderMale  
>       651.4       -142.8         35.5  
> 
> Warning message:
> extra arguments fixed are just disregarded. in: lm.fit(x, y, 
> offset = offset, singular.ok = singular.ok, ...) 
> 
> I wanted to consider only one factor. But why 
> lm(fixed=Value~Gender,data=Food) return me two estimates of 
> Gender and Lard. And I found the returning results are the 
> same as lm(fixed=Value~Lard+Gender,data=Food). Why lm cannot 
> do analysis of variance according to assigned formula?
> 
> Thank you very much.
> 
> Fan
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 
> 


------------------------------------------------------------------------------
Notice:  This e-mail message, together with any attachments,...{{dropped}}



More information about the R-help mailing list