Skip to contents

Calculate confidence intervals of mean or difference between means

Usage

meanCI(x, ...)

Arguments

x

An object of class data.frame or vector

...

Further arguments

Value

An object of class "meanCI" which is a list containing at least the following components:

data

A tibble containing raw data or a list of numeric vector

result

A data.frame consist of summary statistics

call

the matched call

attr(*,"measure")

character. One of c("mean","unpaired","paired")

Examples

meanCI(mtcars$mpg)
#> 
#> call: meanCI.default(x = mtcars$mpg) 
#> method: One sample t-test 
#> alternative hypothesis:
#>    true mean  is not equal to  0 
#> 
#> Results
#> # A tibble: 1 × 7
#>   m        se     DF    lower    upper    t      p        
#>   <chr>    <chr>  <chr> <chr>    <chr>    <chr>  <chr>    
#> 1 20.09062 1.0654 31    17.91768 22.26357 18.857 < 2.2e-16
meanCI(n=150,m=115,s=10,alpha=0.01)
#> 
#> call: meanCI.default(n = 150, m = 115, s = 10, alpha = 0.01) 
#> method: One sample t-test 
#> alternative hypothesis:
#>    true mean  is not equal to  0 
#> 
#> Results
#> # A tibble: 1 × 7
#>   m     se     DF    lower    upper    t      p        
#>   <chr> <chr>  <chr> <chr>    <chr>    <chr>  <chr>    
#> 1 115   0.8165 149   112.8696 117.1304 140.85 < 2.2e-16
meanCI(n=50,m=295,s=20,mu=300)
#> 
#> call: meanCI.default(n = 50, m = 295, s = 20, mu = 300) 
#> method: One sample t-test 
#> alternative hypothesis:
#>    true mean  is not equal to  300 
#> 
#> Results
#> # A tibble: 1 × 7
#>   m     se     DF    lower    upper    t       p      
#>   <chr> <chr>  <chr> <chr>    <chr>    <chr>   <chr>  
#> 1 295   2.8284 49    289.3161 300.6839 -1.7678 0.08333
meanCI(n=20,m=108,s=10,mu=110,alpha=0.01,alternative="less")
#> 
#> call: meanCI.default(n = 20, m = 108, s = 10, mu = 110, alpha = 0.01,      alternative = "less") 
#> method: One sample t-test 
#> alternative hypothesis:
#>    true mean  is less than  110 
#> 
#> Results
#> # A tibble: 1 × 7
#>   m     se     DF    lower upper    t        p     
#>   <chr> <chr>  <chr> <chr> <chr>    <chr>    <chr> 
#> 1 108   2.2361 19    -Inf  113.6785 -0.89443 0.1911
meanCI(mtcars,am,mpg)
#> 
#> call: meanCI.data.frame(x = mtcars, am, mpg) 
#> method: Welch Two Sample t-test 
#> alternative hypothesis:
#>    true unpaired differences in means is not equal to  0 
#> 
#> Results
#> # A tibble: 1 × 6
#>   control test  DF     CI                         t       p       
#>   <chr>   <chr> <chr>  <chr>                      <chr>   <chr>   
#> 1 0       1     18.332 -7.24 [95CI -11.28; -3.21] -3.7671 0.001374
meanCI(n1=15,n2=20,m1=1000,s1=100,m2=950,s2=90,alpha=0.1)
#> 
#> call: meanCI.default(n1 = 15, n2 = 20, m1 = 1000, s1 = 100, m2 = 950,      s2 = 90, alpha = 0.1) 
#> method: Welch Two Sample t-test 
#> alternative hypothesis:
#>    true unpaired differences in means is not equal to  0 
#> 
#> Results
#> # A tibble: 1 × 6
#>   control test  DF     CI                         t      p     
#>   <chr>   <chr> <chr>  <chr>                      <chr>  <chr> 
#> 1 x       y     28.442 50.00 [90CI -5.66; 105.66] 1.5274 0.1377
meanCI(n1=500,n2=1000,m1=20,s1=3,m2=15,s2=2,alpha=0.01)
#> 
#> call: meanCI.default(n1 = 500, n2 = 1000, m1 = 20, s1 = 3, m2 = 15,      s2 = 2, alpha = 0.01) 
#> method: Welch Two Sample t-test 
#> alternative hypothesis:
#>    true unpaired differences in means is not equal to  0 
#> 
#> Results
#> # A tibble: 1 × 6
#>   control test  DF     CI                     t     p        
#>   <chr>   <chr> <chr>  <chr>                  <chr> <chr>    
#> 1 x       y     727.48 5.00 [99CI 4.62; 5.38] 33.71 < 2.2e-16
meanCI(n1=30,n2=25,m1=78,s1=10,m2=85,s2=15,alpha=0.10)
#> 
#> call: meanCI.default(n1 = 30, n2 = 25, m1 = 78, s1 = 10, m2 = 85, s2 = 15,      alpha = 0.1) 
#> method: Welch Two Sample t-test 
#> alternative hypothesis:
#>    true unpaired differences in means is not equal to  0 
#> 
#> Results
#> # A tibble: 1 × 6
#>   control test  DF     CI                         t       p      
#>   <chr>   <chr> <chr>  <chr>                      <chr>   <chr>  
#> 1 x       y     40.475 -7.00 [90CI -12.91; -1.09] -1.9932 0.05301
meanCI(n1=100,n2=100,m1=200,s1=40,m2=190,s2=20,mu=7,alpha=0.05,alternative="greater")
#> 
#> call: meanCI.default(n1 = 100, n2 = 100, m1 = 200, s1 = 40, m2 = 190,      s2 = 20, mu = 7, alpha = 0.05, alternative = "greater") 
#> method: Welch Two Sample t-test 
#> alternative hypothesis:
#>    true unpaired differences in means is greater than  7 
#> 
#> Results
#> # A tibble: 1 × 6
#>   control test  DF     CI                     t       p     
#>   <chr>   <chr> <chr>  <chr>                  <chr>   <chr> 
#> 1 x       y     145.59 10.00 [95CI 2.60; Inf] 0.67082 0.2517
x=c(3.04,2.92,2.86,1.71,3.60,3.49,3.30,2.28,3.11,2.88,2.82,2.13,2.11,3.03,3.27,2.60,3.13)
y=c(2.56,3.47,2.65,2.77,3.26,3.00,2.70,3.20,3.39,3.00,3.19,2.58,2.98)
meanCI(x=x,y=y)
#> 
#> call: meanCI.default(x = x, y = y) 
#> method: Welch Two Sample t-test 
#> alternative hypothesis:
#>    true unpaired differences in means is not equal to  0 
#> 
#> Results
#> # A tibble: 1 × 6
#>   control test  DF     CI                       t        p     
#>   <chr>   <chr> <chr>  <chr>                    <chr>    <chr> 
#> 1 x       y     26.632 -0.14 [95CI -0.45; 0.17] -0.92315 0.3642
x=c(95,89,76,92,91,53,67,88,75,85,90,85,87,85,85,68,81,84,71,46,75,80)
y=c(90,85,73,90,90,53,68,90,78,89,95,83,83,83,82,65,79,83,60,47,77,83)
meanCI(x=x,y=y,paired=TRUE,alpha=0.1)
#> 
#> call: meanCI.default(x = x, y = y, paired = TRUE, alpha = 0.1) 
#> method: Paired t-test 
#> alternative hypothesis:
#>    true paired differences in means is not equal to  0 
#> 
#> Results
#> # A tibble: 1 × 6
#>   control test  DF    CI                      t      p    
#>   <chr>   <chr> <chr> <chr>                   <chr>  <chr>
#> 1 x       y     21    1.00 [90CI -0.32; 2.32] 1.3081 0.205
meanCI(10:30,1:15)
#> 
#> call: meanCI.default(x = 10:30, 1:15) 
#> method: Welch Two Sample t-test 
#> alternative hypothesis:
#>    true unpaired differences in means is not equal to  0 
#> 
#> Results
#> # A tibble: 1 × 6
#>   control test  DF     CI                       t      p      
#>   <chr>   <chr> <chr>  <chr>                    <chr>  <chr>  
#> 1 x       y     33.988 12.00 [95CI 8.38; 15.62] 6.7434 9.5e-08
meanCI(acs,sex,age)
#> 
#> call: meanCI.data.frame(x = acs, sex, age) 
#> method: Welch Two Sample t-test 
#> alternative hypothesis:
#>    true unpaired differences in means is not equal to  0 
#> 
#> Results
#> # A tibble: 1 × 6
#>   control test  DF     CI                     t      p        
#>   <chr>   <chr> <chr>  <chr>                  <chr>  <chr>    
#> 1 Female  Male  596.99 8.07 [95CI 6.52; 9.62] 10.222 < 2.2e-16
meanCI(iris$Sepal.Width,iris$Sepal.Length)
#> 
#> call: meanCI.default(x = iris$Sepal.Width, iris$Sepal.Length) 
#> method: Welch Two Sample t-test 
#> alternative hypothesis:
#>    true unpaired differences in means is not equal to  0 
#> 
#> Results
#> # A tibble: 1 × 6
#>   control test  DF     CI                        t       p        
#>   <chr>   <chr> <chr>  <chr>                     <chr>   <chr>    
#> 1 x       y     225.68 -2.79 [95CI -2.94; -2.64] -36.463 < 2.2e-16
meanCI(iris$Sepal.Width,iris$Sepal.Length,paired=TRUE)
#> 
#> call: meanCI.default(x = iris$Sepal.Width, iris$Sepal.Length, paired = TRUE) 
#> method: Paired t-test 
#> alternative hypothesis:
#>    true paired differences in means is not equal to  0 
#> 
#> Results
#> # A tibble: 1 × 6
#>   control test  DF    CI                        t       p        
#>   <chr>   <chr> <chr> <chr>                     <chr>   <chr>    
#> 1 x       y     149   -2.79 [95CI -2.94; -2.63] -34.815 < 2.2e-16