Contents

1 z 糾
2 觜襯 れ姶 螻
3 modified wald method 襦 襤郁規螳 蟲蠍
4 1-sample 觜 蟆
5 n螳 讌 觜 蟆
6 覦(Exact Poisson tests)


1 z 糾 #

  • 90% 襤郁規螳 z=1.645
  • 95% 襤郁規螳 z=1.960
  • 99% 襤郁規螳 z=1.2.576

2 觜襯 れ姶 螻 #

A 襦 蟲覩朱 1000覈 譴 300覈 谿燕. れ姶?
  • 1/sqrt(1000) --> 賊3.2%

3 modified wald method 襦 襤郁規螳 蟲蠍 #

  • z * sqrt(p * (1-p) / (n+z^2))
  • .. 1.96 * sqrt(0.3 * (1-0.3) / (1000+1.96^2))

4 1-sample 觜 蟆 #

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 
  • 譴 0.05 襴所 豈.



谿瑚: 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

5 n螳 讌 觜 蟆 #

A 300覈 譴 100覈, B 400覈 譴 170覈 D覲企ゼ 讌讌り 譟一. A B D覿 讌讌 觜 螳り 螳?

覿 <- c(100, 170)
覿覈 <- c(300, 400)
prop.test(覿, 覿覈)

> prop.test(覿, 覿覈)

	2-sample test for equality of proportions with continuity correction

data:  覿 out of 覿覈
X-squared = 5.6988, df = 1, p-value = 0.01698
alternative hypothesis: two.sided
95 percent confidence interval:
 -0.16664176 -0.01669158
sample estimates:
   prop 1    prop 2 
0.3333333 0.4250000 

蟆郁骸伎
  • 讌 企 蟇伎 觜 螳り 讌 蟆.

    • 蠏覓願: 谿願 .
    • 襴所: 谿願 . --> 譴 0.05 襴所 讌讌, 譴 0.01 襴所 蠍郁
  • 95% 襤郁規螳: 0.4250000-0.16664176 ~ 0.4250000-0.01669158 = 0.2583582 ~ 0.4083084, 蠍一 100/300

襦 覃..
prop.test.excel.png

6 覦(Exact Poisson tests) #

豺伎危 一危一 ..
> poisson.test(覿, 覿覈)

	Comparison of Poisson rates

data:  覿 time base: 覿覈
count1 = 100, expected count1 = 115.71, p-value = 0.05656
alternative hypothesis: true rate ratio is not equal to 1
95 percent confidence interval:
 0.6064139 1.0099403
sample estimates:
rate ratio 
 0.7843137 

1覲
> poisson.test(83, 100)

	Exact Poisson test

data:  83 time base: 100
number of events = 83, time base = 100, p-value = 0.09854
alternative hypothesis: true event rate is not equal to 1
95 percent confidence interval:
 0.6610904 1.0289099
sample estimates:
event rate 
      0.83 
  • 蠏覓願: 覈讌 覦襯(了) 蠏覓 螳れ 覦襯螻 螳.
  • 襴所: 覈讌 覦襯(了) 蠏覓 螳れ 覦襯螻 るゴ.
  • 譴 0.05 蠏覓願 讌讌