#Confidence interval of the mean -- multiple approaches.
#Option 1 is a basic stats function
t.test(Wk06$height, conf.level = 0.95)
##
## One Sample t-test
##
## data: Wk06$height
## t = 93.838, df = 27, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## 64.97606 67.88108
## sample estimates:
## mean of x
## 66.42857
#Option 2 is the rcompanion approach
#install.packages('rcompanion')
library(rcompanion)
groupwiseMean(height ~ 1,
data = Wk06,
conf = 0.95,
digits = 8)
## .id n Mean Conf.level Trad.lower Trad.upper
## 1 <NA> 28 66.42857 0.95 64.97606 67.88108
#Option 3 is from DescTools
MeanCI(Wk06$height,
conf.level=0.95)
## mean lwr.ci upr.ci
## 66.42857 64.97606 67.88108
#Option 4 is from Rmisc
#install.packages('Rmisc')
library(Rmisc)
## Loading required package: lattice
CI(Wk06$height,
ci=0.95)
## upper mean lower
## 67.88108 66.42857 64.97606
#Groupwise also offers bootstrapped CIs
groupwiseMean(height ~ 1,
data = Wk06,
conf = 0.95,
digits = 8,
R = 10000,
boot = TRUE,
traditional = FALSE,
normal = FALSE,
basic = FALSE,
percentile = FALSE,
bca = TRUE)
## .id n Mean Boot.mean Conf.level Bca.lower Bca.upper
## 1 <NA> 28 66.42857 66.43386 0.95 65 67.75
#Boot also offers bootstrapped confidence intervals
#install.packages('boot')
library(boot)
##
## Attaching package: 'boot'
## The following object is masked from 'package:lattice':
##
## melanoma
Mboot = boot(Wk06$height,
function(x,i) mean(x[i]),
R=10000)
mean(Mboot$t[,1])
## [1] 66.43701
boot.ci(Mboot,
conf = 0.95,
type = c("norm", "basic" ,"perc", "bca")
)
## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
## Based on 10000 bootstrap replicates
##
## CALL :
## boot.ci(boot.out = Mboot, conf = 0.95, type = c("norm", "basic",
## "perc", "bca"))
##
## Intervals :
## Level Normal Basic
## 95% (65.05, 67.79 ) (65.07, 67.82 )
##
## Level Percentile BCa
## 95% (65.04, 67.79 ) (64.93, 67.71 )
## Calculations and Intervals on Original Scale