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. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: dat.txt URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130309/ed591f9a/attachment.txt>
On Sat, Mar 9, 2013 at 10:35 AM, meng <laomeng_3@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? >lm() would be overkill no? I'd just use tapply(), by(), ave(), or the like: e.g., tapply(dat$y, dat$sex, mean) Cheers, MW [[alternative HTML version deleted]]
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. Thanks At 2013-03-10 02:39:21,"Greg Snow" <538280@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@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@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@gmail.com [[alternative HTML version deleted]]