[R] How to generate table output of t-test
Peter Dalgaard
P.Dalgaard at biostat.ku.dk
Tue Feb 5 10:59:23 CET 2008
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
More information about the R-help
mailing list