Content

頻度主義では例えば正規分布している母集団の真の平均値(以降“μ”)は唯一と前提しています。よってμの95%信頼区間とは『得られたその1個の信頼区間にμの含まれる確率は95%』ではなく、『同じ方法でμを100回求めた場合、そのうち少なくとも95個の信頼区間にμが含まれる』という意味。

set.seed(181212001)
Population <- rnorm(n = 10000,mean = 100,sd = 10)
trials <- 100
sampleSize <- 20
confidenceInterval <- 0.95
testData <- lapply(seq(trials),function(x)t.test(sample(Population,sampleSize),conf.level = confidenceInterval, alternative = 'two.sided'))
resultDf <- data.frame(seq(trials),Reduce(function(x,y)rbind(x,y),lapply(testData,function(x)c(x$estimate,x$conf.int[1],x$conf.int[2]))),row.names = NULL)
colnames(resultDf) <- c('x','mean','lower','upper')
resultDf$outcome <- ifelse(mean(Population)<resultDf$lower | resultDf$upper<mean(Population),'out','in')
g <- ggplot(resultDf,aes(x = x)) + geom_point(aes(y = mean,col = outcome),size = 1,show.legend = F) + geom_errorbar(aes(ymax = upper,ymin = lower,col = outcome),show.legend = F)
g <- g + geom_hline(yintercept = mean(Population),linetype=2)
g <- g + scale_color_manual(values = c('out' = 'red','in' = 'blue'))
g <- g + theme(axis.title.x = element_text(size = 0),axis.title.y = element_text(size = 0))
g <- g + annotate(geom = 'text',x =0,y=mean(Population),label = 'μ\n',vjust=0.5,hjust=1,size = 6)
g
Fig.  1: 母集団の平均値をt検定で推定

Fig. 1: 母集団の平均値をt検定で推定

data.frame(resultDf[resultDf$outcome=='out',],row.names = NULL)
   x      mean     lower     upper outcome
1 17  93.71695  87.73411  99.69979     out
2 20  96.30415  92.69342  99.91489     out
3 63 103.72376 100.22450 107.22301     out
4 83 104.58543 100.40502 108.76585     out

Fig.1は母集団(サイズは10000)の平均値(μ = 99.94)をt検定(信頼区間は95%)で100個(各サンプルサイズは20)の信頼区間を推定した例であるが、そのうち上記の4個がμを含んでいない(赤色のバー)。