[R] Problem with "by": does not work with ttest (but with lme)

Greg Snow Greg.Snow at intermountainmail.org
Tue Aug 14 17:42:26 CEST 2007


I think at least part of your problem is that in the lm example you use
data=x (correct), but in the t.test example you use data=warpbreaks, so
in that case it is uing the full data set, not just the portion passed
by the 'by' function.  Try the t.test example again with data=x and see
what happens.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
 
 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Daniel Stahl
> Sent: Tuesday, August 14, 2007 7:11 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Problem with "by": does not work with ttest (but 
> with lme)
> 
> Hello,
> 
> I would like to do a large number of e.g. 1000 paired ttest 
> using the by-function. But instead of using only the data 
> within the 1000 groups, R caclulates 1000 times the ttest for 
> the full data set(The same happens with Wilcoxon test). 
> However, the by-function works fine with the lme function.
> Did I just miss something or is it really not working? If 
> not, is there any other possibility to avoid loops? 
> Thanks
> Daniel
> 
> Here is the R help example for "by" 
>  require(stats)
>  attach(warpbreaks)
>  by(warpbreaks, tension, function(x) lm(breaks ~ wool, data = 
> x)) *->works great 
> by(warpbreaks,tension,function(x)t.test(breaks ~ 
> wool,data=warpbreaks,paired = TRUE)) *Same output for each 
> level of tension:
> 
> tension: L
> 
> 	Paired t-test
> 
> data:  breaks by wool
> t = 1.9956, df = 26, p-value = 0.05656
> alternative hypothesis: true difference in means is not equal to 0
> 95 percent confidence interval:
> -0.1735803 11.7291358
> sample estimates:
> mean of the differences
>                 5.777778
> 
> --------------------------------------------------------------
> ----------
> 
> tension: M
> 
> 	Paired t-test
> 
> data:  breaks by wool
> t = 1.9956, df = 26, p-value = 0.05656
> alternative hypothesis: true difference in means is not equal to 0
> 95 percent confidence interval:
> -0.1735803 11.7291358
> sample estimates:
> mean of the differences
>                 5.777778
> 
> --------------------------------------------------------------
> ----------
> 
> tension: H
> 
> 	Paired t-test
> 
> data:  breaks by wool
> t = 1.9956, df = 26, p-value = 0.05656
> alternative hypothesis: true difference in means is not equal to 0
> 95 percent confidence interval:
> -0.1735803 11.7291358
> sample estimates:
> mean of the differences
>                 5.777778
> 
> 
> 
> 
> 
> 
> 
> --
> 
> ______________________________________________
> 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.
>



More information about the R-help mailing list