[R] quesion about lm function

PIKAL Petr petr.pikal at precheza.cz
Mon Mar 11 08:45:14 CET 2013


Hi

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of meng
> Sent: Sunday, March 10, 2013 5:33 AM
> To: Greg Snow
> Cc: R help
> Subject: Re: [R] quesion about lm function
> 
> Thanks for your reply.
> But the mean y of sex(f) and sex(m) can't be negative since the min and
> max of y is 1632.5 and 6410.6 respectively.
> 
> And your code's result:
> 
> sex(f): -1255.56
> sex(m):-1118.73
> 
> The above result isn't correct since they are negative.

You did not read the full advice.


> The tests are likely to be meaningless in this case and the means are
> the predicted means at x1=0 and x2=0 (so the means may make more sense
> if x1 and x2 are centered  first).

The above results (means) are correct at x1 and x2 = 0.

result_lm <- lm(y~0+factor(sex) + scale(x1) + scale(x2), data=test)
coef(result_lm)
factor(sex)f factor(sex)m    scale(x1)    scale(x2) 
   3876.6290    4013.4576     945.5634     592.7385 

Anyway not a big difference from

tapply(test$y, test$sex, mean)
       f        m 
3790.760 4099.327 

Regards
Petr


> 
> Thanks
> 
> 
> 
> 
> 
> 
> 
> 
> 
> At 2013-03-10 02:39:21,"Greg Snow" <538280 at gmail.com> wrote:
> 
> You can get the 2 means with:
> 
> 
> result_lm <- lm(y~0+factor(sex) + x1 + x2)
> 
> 
> The tests are likely to be meaningless in this case and the means are
> the predicted means at x1=0 and x2=0 (so the means may make more sense
> if x1 and x2 are centered  first).
> 
> 
> 
> On Sat, Mar 9, 2013 at 3:35 AM, meng <laomeng_3 at 163.com> wrote:
> Hi all:
> My data is in the attachment.
> I want to analysis the mean difference of y between 2 sex.
> 
> My code:
> result_lm<-lm(y~factor(sex) + x1 + x2)
> summary(result_lm)
> 
> The result of "factor(sex)m" 136.83, is the mean difference of y
> between 2 sex,and the corresponding p value is 0.07618.
> 
> My question is: how to get the mean y of sex(m) and sex(f) respectively
> via lm function?
> 
> Many thanks for your help.
> My best.
> 
> 
> ______________________________________________
> R-help at r-project.org 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.
> 
> 
> 
> 
> 
> 
> 
> --
> Gregory (Greg) L. Snow Ph.D.
> 538280 at gmail.com
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org 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.



More information about the R-help mailing list