Dear colegue,
I am not sure if it is this what you want, but to apply the t.test to all
rows in a data frame, you can do like:
apply(dataframe, 1, t.test)
If you want to store the results in a nice data frame, to us after, then you
should do a function, for example:
#################################### wilcox CI plus median
median.ci.wilcox=function(y){
# print("example: use to construct graphs with 95% CI, using xYplot, from
Hmisc. use summarize to compute the CI in function of factors")
if (is.R()) {require(ctest)}
if(length(y)>5){
c=t.test(y, conf.int=T, conf.level=.95)
res=c(mean=c$estimate, Lower=c(c$conf.int[1]), Upper=c(c$conf.int[2]))}
else {res=c(median=NA, Lower=NA, Upper=NA)}
res
}
hope this helps,
All the best,
Marta
----- Original Message -----
From: "pcscan" <s938611 at mail.yzu.edu.tw>
To: <r-help at stat.math.ethz.ch>
Sent: Tuesday, October 19, 2004 4:04 AM
Subject: [R] Questions of t.test {stats}
We are currently using the t-test in Package stats,
t.test(x, y = NULL, alternative = c("two.sided", "less", "greater"),
mu = 0, paired = FALSE, var.equal = FALSE,
conf.level = 0.95, ...)
but have some troubles :
1. why does the t-test take so a long time to perform a single test on a
row
of a data.frame ? Is there any alternative function to perform t-test on
all
the rows of a data.frame ?
2. We got different results on the following data with the argument
var.equal setting as TRUE and FALSE respectively.
We are curious why the "Welch Two Sample t-test" couldn't distinguish
these
two vectors well.
Any help is greatly appreciated.
Sincerely. Liu Yu Ting
Welch Two Sample t-test
data: x and y
t = -2.8369, df = 10.009, p-value = 0.01763
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-3.6338688 -0.4369566
sample estimates:
mean of x mean of y
-0.2180945 1.8173182
t.test(x,y,var.equal=TRUE)
Two Sample t-test
data: x and y
t = -8.2473, df = 98, p-value = 7.507e-13
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-2.525175 -1.545650
sample estimates:
mean of x mean of y
-0.2180945 1.8173182