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

Are the confidence intervals in compareGroups R package accurate?

I’ve been using R package "compareGroups" for a while now.
But I’ve been curious and playing with it and I don’t understand how compareGroups computes confidence intervals.

data <- data.frame(a = c(1:20, 1:20), b = c(rep("A",20), rep("B",20)))

I get (with conf.level = 0.95 as default)

> compareGroups(b~a , data = data.frame(a = c(1:20, 1:20), b = c(rep("A",20), rep("B",20)))) %>% 
+   createTable(digits = 2, show.ci = T)

--------Summary descriptives table by 'b'---------

_________________________________________________ 
          A                  B          p.overall 
         N=20               N=20                  
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ 
a 10.50 [7.73;13.27] 10.50 [7.73;13.27]   1.000   
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ 

But then, if i try manually, I get those results :

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

> mean(1:20) - qnorm(0.975)*sd(1:20)/sqrt(20)
[1] 7.907211
> mean(1:20) + qnorm(0.975)*sd(1:20)/sqrt(20)
[1] 13.09279

Which are somehow different than what I got from the compareGroups %>% createTable function

Does any of you know how this package works ? Or maybe am I wrong somewhere calculating my confidence interval ?

Thank you for your help.

>Solution :

I think compareGroups calculates the confidence interval using a t-test by default, so it assumes a t-distribution rather than the normal distribution.

If you use:

mean(1:20) - qt(0.975, df = 19)*sd(1:20)/sqrt(20)
[1] 7.731189

mean(1:20) + qt(0.975, df = 19)*sd(1:20)/sqrt(20)
[1] 13.26881

You get the same values as from compareGroups.

See this for more information.

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