Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to extract lower and upper bounds from confidence level in R from t test function?

I used the following code to retrieve a confidence level for my data:

c <- t.test(my_data$my_col, conf.level = 0.95)
c

This returns something like:

data:  my_data$my_column
t = 30, df = 20, p-value < 2.1e-14
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
 62.23191 80.11201
sample estimates:
mean of x 
 75.10457 

I’ve tried doing:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

c[4][1]

But this returns:

$conf.int
[1]  62.23191 80.11201
attr(,"conf.level")
[1] 0.95

How do I specifically get the lower bound and upper bound from this respectively? (i.e. how do I extract 62.23191 and 80.11201 as variables?)

>Solution :

The output from t.test() is a list.

To access the confidence intervals use c$conf.int[1] & c$conf.int[2]

Example:

c<-t.test(1:10, y = c(7:20))  
out$conf.int
#[1] -11.052802  -4.947198
#attr(,"conf.level")
#[1] 0.95
out$conf.int[1]
#[1] -11.0528
out$conf.int[2]
#[1] -4.947198
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading