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

Petr PIKAL petr.pikal at precheza.cz
Tue Aug 14 15:35:13 CEST 2007


Hi

r-help-bounces at stat.math.ethz.ch napsal dne 14.08.2007 15:11:11:

> 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))

What about

by(warpbreaks,tension,function(x)t.test(breaks ~ wool,data=x,paired = 
TRUE))

Regards
Petr


> *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