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

Daniel Stahl daniel_stahl at operamail.com
Tue Aug 14 15:11:11 CEST 2007


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







--



More information about the R-help mailing list