Etienne Stockhausen
2010-Aug-09 18:39 UTC
[R] How to extract the conf.level out of t.test() data
Good afternoon everybody, I'm writing a little function to visualise hypothesis testing. Therefore I need to extract the confidence level of a t-test. Here a little example: x <- str(t.test(1:10) gives List of 9 $ statistic : Named num 5.74 ..- attr(*, "names")= chr "t" $ parameter : Named num 9 ..- attr(*, "names")= chr "df" $ p.value : num 0.000278 $ conf.int : atomic [1:2] 3.33 7.67 ..- attr(*, "conf.level")= num 0.95 $ estimate : Named num 5.5 ..- attr(*, "names")= chr "mean of x" $ null.value : Named num 0 ..- attr(*, "names")= chr "mean" $ alternative: chr "two.sided" $ method : chr "One Sample t-test" $ data.name : chr "1:10" - attr(*, "class")= chr "htest" Now I can use x$conf.int what gives [1] 496.9141 499.6276 attr(,"conf.level") [1] 0.95 In the example I try to extract the value 0.95 but I have no Idea how. I hope somebody can help me. Thanks in advance an greetings from Berlin Etienne
Romain Francois
2010-Aug-10 07:42 UTC
[R] How to extract the conf.level out of t.test() data
Le 09/08/10 20:39, Etienne Stockhausen a ?crit :> > Good afternoon everybody, > > I'm writing a little function to visualise hypothesis testing. Therefore > I need to extract the confidence level of a t-test. Here a little example: > > x <- str(t.test(1:10) > > gives > > List of 9 > $ statistic : Named num 5.74 > ..- attr(*, "names")= chr "t" > $ parameter : Named num 9 > ..- attr(*, "names")= chr "df" > $ p.value : num 0.000278 > $ conf.int : atomic [1:2] 3.33 7.67 > ..- attr(*, "conf.level")= num 0.95 > $ estimate : Named num 5.5 > ..- attr(*, "names")= chr "mean of x" > $ null.value : Named num 0 > ..- attr(*, "names")= chr "mean" > $ alternative: chr "two.sided" > $ method : chr "One Sample t-test" > $ data.name : chr "1:10" > - attr(*, "class")= chr "htest" > > Now I can use > > x$conf.int > > what gives > > [1] 496.9141 499.6276 > attr(,"conf.level") > [1] 0.95 > > In the example I try to extract the value 0.95 but I have no Idea how. I > hope somebody can help me. > Thanks in advance an greetings from Berlin > > EtienneYou need the conf.level attribute, as in : x <- t.test(1:10) attr( x$conf.int, "conf.level" ) Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/aAyra4 : highlight 0.2-2 |- http://bit.ly/94EBKx : inline 0.3.6 `- http://bit.ly/aryfrk : useR! 2010
Dimitris Rizopoulos
2010-Aug-10 07:42 UTC
[R] How to extract the conf.level out of t.test() data
try this: x <- t.test(1:10) x$conf.int attr(x$conf.int, "conf.level") I hope it helps. Best, Dimitris On 8/9/2010 8:39 PM, Etienne Stockhausen wrote:> Good afternoon everybody, > > I'm writing a little function to visualise hypothesis testing. Therefore > I need to extract the confidence level of a t-test. Here a little example: > > x <- str(t.test(1:10) > > gives > > List of 9 > $ statistic : Named num 5.74 > ..- attr(*, "names")= chr "t" > $ parameter : Named num 9 > ..- attr(*, "names")= chr "df" > $ p.value : num 0.000278 > $ conf.int : atomic [1:2] 3.33 7.67 > ..- attr(*, "conf.level")= num 0.95 > $ estimate : Named num 5.5 > ..- attr(*, "names")= chr "mean of x" > $ null.value : Named num 0 > ..- attr(*, "names")= chr "mean" > $ alternative: chr "two.sided" > $ method : chr "One Sample t-test" > $ data.name : chr "1:10" > - attr(*, "class")= chr "htest" > > Now I can use > > x$conf.int > > what gives > > [1] 496.9141 499.6276 > attr(,"conf.level") > [1] 0.95 > > In the example I try to extract the value 0.95 but I have no Idea how. I > hope somebody can help me. > Thanks in advance an greetings from Berlin > > Etienne > > ______________________________________________ > 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. >-- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014