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

From: Spencer Graves <spencer.graves_at_pdf.com>
Date: Thu 29 Jul 2004 - 16:20:58 EST

      The function "as.vector" will remove the names:

 > t.test(1:9)$statistic

       t
5.477226
 > as.vector(t.test(1:9)$statistic)
[1] 5.477226

      Is this what you want? spencer graves

Michael Rennie wrote:

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

>
>



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jul 29 16:40:29 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:55:20 EST