A蟲れ 100覈 . 伎 るジ ′企 86覈企. 蟲 94%螳 るジ ′企. 蟲螻 A蟲れ れ るジ ′ 觜 螳?
> prop.test(86,100,p=0.94)
1-sample proportions test with continuity correction
data: 86 out of 100, null probability 0.94
X-squared = 9.9734, df = 1, p-value = 0.001588
alternative hypothesis: true p is not equal to 0.94
95 percent confidence interval:
0.7728837 0.9185961
sample estimates:
p
0.86
谿瑚:
http://www.r-bloggers.com/one-proportion-z-test-in-r/
z.test <- function(x,n,p=NULL,conf.level=0.95,alternative="less") {
ts.z <- NULL
cint <- NULL
p.val <- NULL
phat <- x/n
qhat <- 1 - phat
# If you have p0 from the population or H0, use it.
# Otherwise, use phat and qhat to find SE.phat:
if(length(p) > 0) {
q <- 1-p
SE.phat <- sqrt((p*q)/n)
ts.z <- (phat - p)/SE.phat
p.val <- pnorm(ts.z)
if(alternative=="two.sided") {
p.val <- p.val * 2
}
if(alternative=="greater") {
p.val <- 1 - p.val
}
} else {
# If all you have is your sample, use phat to find
# SE.phat, and don't run the hypothesis test:
SE.phat <- sqrt((phat*qhat)/n)
}
cint <- phat + c(
-1*((qnorm(((1 - conf.level)/2) + conf.level))*SE.phat),
((qnorm(((1 - conf.level)/2) + conf.level))*SE.phat) )
return(list(estimate=phat,ts.z=ts.z,p.val=p.val,cint=cint))
}
z.test(86,100,p=0.94)
> z.test(86,100,p=0.94)
$estimate
[1] 0.86
$ts.z
[1] -3.368608
$p.val
[1] 0.0003777444
$cint
[1] 0.8134534 0.9065466