Re: [R] How to generate table output of t-test

From: Peter Dalgaard <P.Dalgaard_at_biostat.ku.dk>
Date: Tue, 05 Feb 2008 10:59:23 +0100

Uwe Ligges wrote:
> Ng Stanley wrote:
>
>> Hi,
>>
>> Given
>>
>> test <- matrix(c(1, 1,2,2), 2,2)
>> t <- apply(test, 1, t.test)
>>
> >
>
>> How can I obtain a table of p-values, confidence interval etc, instead of
>>
>
> A quick hack would be:
>
> m <- t(sapply(t, function(x) c(x[["p.value"]], x[["conf.int"]])))
> colnames(m) <- c("p", "lwr", "upr")
> m
>
>
Even quicker:

> sapply(t,unlist)

                   [,1]                [,2]
statistic.t        "3"                 "3"
parameter.df       "1"                 "1"
p.value            "0.204832764699133" "0.204832764699133"
conf.int1          "-4.85310236808735" "-4.85310236808735"
conf.int2          "7.85310236808735"  "7.85310236808735"
estimate.mean of x "1.5"               "1.5"
null.value.mean    "0"                 "0"
alternative        "two.sided"         "two.sided"
method             "One Sample t-test" "One Sample t-test"
data.name          "newX[, i]"         "newX[, i]"

Or maybe

> sapply(lapply(t,"[",1:6),unlist)

                         [,1]       [,2]
statistic.t         3.0000000  3.0000000
parameter.df        1.0000000  1.0000000
p.value             0.2048328  0.2048328
conf.int1          -4.8531024 -4.8531024
conf.int2           7.8531024  7.8531024
estimate.mean of x  1.5000000  1.5000000
null.value.mean     0.0000000  0.0000000

-- 
   O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard_at_biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help_at_r-project.org 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. Received on Tue 05 Feb 2008 - 10:03:32 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 05 Feb 2008 - 15:30:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive