[R] extracting the t-statistic: just the numbers, please

Michael Rennie mrennie at utm.utoronto.ca
Thu Jul 29 07:57:02 CEST 2004


Hi, there

I am quite sure there is an easy answer to this, but I am unsure how to gather 
a bunch of t-statistics in an organized format.

I am trying to generate a list of t-statistics for a randomization routine. If 
I try to collect a bunch of t-statistics from a run, this is what happens:


> M <- 10 ; simt <- NULL
> for(i in 1:M)
+     {
+    perm<-sample(site,replace=F)
+ 
+ permute<-cbind(perm, site, a, b, c)
+ 
+ m<- order(perm)
+ 
+ m1<-cbind(perm[m], site[m], a[m], b[m], c[m])
+ 
+ black<-c((m1[1:5,5]),(m1[11:15,5]))
+ #black
+ 
+ white<-c((m1[6:10,5]),(m1[16:20,5]))
+ #white
+ 
+ sims <- t.test(black,white,var.equal=FALSE,mu=0)$statistic
+ simt<-c(simt,sims)
+ #simt
+ } # Next i (next simulation)
> 
> simt
         t          t          t          t          t          t          t 
 0.3474150  0.1542973 -0.4044992  1.2466663 -0.2933944 -0.5809257  0.7799080 
         t          t          t 
-1.4132713  1.2048335 -0.6596936

Which gives me a list, but not in a form that I can do anything with. This is 
in stark contrast to what happens when requesting p-values, which gives output 
like this:



 M <- 10 ; simt <- NULL
> for(i in 1:M)
+     {
+    perm<-sample(site,replace=F)
+ 
+ permute<-cbind(perm, site, a, b, c)
+ 
+ m<- order(perm)
+ 
+ m1<-cbind(perm[m], site[m], a[m], b[m], c[m])
+ 
+ black<-c((m1[1:5,5]),(m1[11:15,5]))
+ #black
+ 
+ white<-c((m1[6:10,29]),(m1[16:20,5]))
+ #white
+ 
+ sims <- t.test(black,white,var.equal=FALSE,mu=0)$p.value
+ simt<-c(simt,sims)
+ #simt
+ } # Next i (next simulation)
> 
> simt
 [1] 0.6763749 0.7480091 0.9447851 0.3342029 0.7852635 0.3199006 0.5272153
 [8] 0.3863616 0.7333693 0.7268907

Now THAT'S what I'd like to get for my t-statistics- a nice vector (simt) that 
I can deal with later, rather than the output I am currently getting (the first 
output above).

Does anyone know a way to extract JUST the t-statistics from the t.test, 
without the "t" character header, so I can generate a nice little vector? 
Alternatively, can I manipulate the output I am currently getting for the t-
statistics so that I can isolate just the numbers? 

-- 
Michael Rennie
Ph.D. Candidate
University of Toronto at Mississauga
3359 Mississauga Rd. N.
Mississauga ON  L5L 1C6
Ph: 905-828-5452  Fax: 905-828-3792




More information about the R-help mailing list