Skip to content
Prev 314737 / 398502 Next

how to aggregate T-test result in an elegant way?

HI,
I tried to create an example dataset (as you didn't provide the data).
set.seed(25)
a<-array(sample(1:50,60,replace=TRUE),dim=c(2,10,3))
dimnames(a)[[1]]<-c("13%","21%")
dimnames(a)[[2]]<-paste("TWF2H",101:110,sep="")
dimnames(a)[[3]]<-c("EW.INCU","EW.17.5","EMW")


str(a)
# int [1:2, 1:10, 1:3] 21 35 8 45 7 50 32 17 4 15 ...
?#- attr(*, "dimnames")=List of 3
? #..$ : chr [1:2] "13%" "21%"
? .#.$ : chr [1:10] "TWF2H101" "TWF2H102" "TWF2H103" "TWF2H104" ...
? #..$ : chr [1:3] "EW.INCU" "EW.17.5" "EMW"

res<-lapply(lapply(seq_len(dim(a)[3]),function(i) t.test(a[dimnames(a)[[1]][1],,i],a[dimnames(a)[[1]][2],,i])),function(x) data.frame(mean=x$estimate,p.value=x$p.value))
res1<-do.call(rbind,res)
? row.names(res1)[grep("mean of x",row.names(res1))]<-gsub("(.*\\.).*$","\\113%",row.names(res1)[grep("mean of x",row.names(res1))])
?row.names(res1)[grep("mean of y",row.names(res1))]<-gsub("(.*\\.).*$","\\121%",row.names(res1)[grep("mean of y",row.names(res1))])
res1
#??????????? mean?? p.value
#EW.INCU.13% 22.3 0.2754842
#EW.INCU.21% 29.3 0.2754842
#EW.17.5.13% 20.5 0.4705772
#EW.17.5.21% 16.0 0.4705772
#EMW.13%???? 23.9 0.9638679
#EMW.21%???? 24.2 0.9638679
A.K.




----- Original Message -----
From: Yao He <yao.h.1988 at gmail.com>
To: arun <smartpink111 at yahoo.com>
Cc: R help <r-help at r-project.org>
Sent: Sunday, January 6, 2013 11:21 PM
Subject: Re: [R] how to aggregate T-test result in an elegant way?

Thank you?it is really helpful everytime.

I didn't provide any example data because I thought it is just a
question of how to report t.test() result in R.
However,as you say,it is better to show more details for finding an elegant way

In fact? I generate a 3-dimension array like that:
str(a)
num [1:2, 1:245, 1:3] 47.5 NA 48.9 NA 47.5 ...
- attr(*, "dimnames")=List of 3
? ..$ : chr [1:2] "13%" "21%"
? ..$ : chr [1:245] "TWF2H101" "TWF2H105" "TWF2H106" "TWF2H110" ...
? ..$ : chr [1:3] "EW.INCU" "EW.17.5" "EMW"

I want to do two sample mean t-test between 13% and 21% for each
variable "EW.INCU" "EW.17.5" "EMW".

So I try these codes:
variable<-dimnames(a)[[3]]
? O2<-dimnames(a)[[1]]
? for (i in variable) {
? ? print(i)
? ? print(O2[1])
? ? print(O2[2])
? ? print(t.test(a[O2[1],,i],a[O2[2],,i],na.rm=T))
? ? }

I don't think it is an elegant way and I am inexperience to report raw result.
Could you give me more help?

Yao He

2013/1/7 arun <smartpink111 at yahoo.com>: