こちらの続き。
20回の試行を増やしてみる。
10回、100回、1000回、10000回して、それぞれ8回、80回、800回、8000回表が出たとする。
つまり、点推定ではどれも0.8。
p<- 0.8 trial<- 10^(1:4) apply(cbind(trial*p,trial*(1-p)),1,binom.test,0.5)
[[1]] Exact binomial test data: newX[, i] number of successes = 8, number of trials = 10, p-value = 0.1094 alternative hypothesis: true probability of success is not equal to 0.5 95 percent confidence interval: 0.4439045 0.9747893 sample estimates: probability of success 0.8 [[2]] Exact binomial test data: newX[, i] number of successes = 80, number of trials = 100, p-value = 1.116e-09 alternative hypothesis: true probability of success is not equal to 0.5 95 percent confidence interval: 0.7081573 0.8733444 sample estimates: probability of success 0.8 [[3]] Exact binomial test data: newX[, i] number of successes = 800, number of trials = 1000, p-value < 2.2e-16 alternative hypothesis: true probability of success is not equal to 0.5 95 percent confidence interval: 0.7738406 0.8243794 sample estimates: probability of success 0.8 [[4]] Exact binomial test data: newX[, i] number of successes = 8000, number of trials = 10000, p-value < 2.2e-16 alternative hypothesis: true probability of success is not equal to 0.5 95 percent confidence interval: 0.7920233 0.8078016 sample estimates: probability of success 0.8
試行回数が増えるに従って、p値が低く、95%信頼区間も狭くなっている。
ちなみに8000/10000回の時ではp値はとなっている。
信頼区間の幅は、標本数がn増えるとおよそになるらしく
a<- matrix(0,length(trial),2) for(i in 1:nrow(a)){ a[i,]<- apply(cbind(trial*p,trial*(1-p)),1,binom.test,0.5)[[i]]$conf.int } a_diff<- a[,2]-a[,1] sqrt(10) [1] 3.162278 a_diff[1]/a_diff[2] [1] 3.213838 a_diff[2]/a_diff[3] [1] 3.268521 a_diff[3]/a_diff[4] [1] 3.203046
となってけっこう近い。
今回は二項検定について扱ったが、分割表のカイ二乗検定でも同様にできる。