[Example] For 269136 people who diagnosed with lung cancer between 2000 and 2006, 45483 survivied after 5-year. Test whether the survival rate equals 0.15 and construct confidence interval.

prop.test(x=45483, n=269136, p = 0.15,
          alternative = c("two.sided"),
          conf.level = 0.95, correct = FALSE)
## 
##  1-sample proportions test without continuity correction
## 
## data:  45483 out of 269136, null probability 0.15
## X-squared = 761.73, df = 1, p-value < 2.2e-16
## alternative hypothesis: true p is not equal to 0.15
## 95 percent confidence interval:
##  0.1675853 0.1704169
## sample estimates:
##         p 
## 0.1689963

The above provides the Wald CI. To obtain the Score CI, we need to sovle the following for \(\pi_0\).

\[ \frac{|p-\pi_0|}{\sqrt{\frac{\pi_0(1-\pi_0)}{n}}} = 1.96, \] In our case, \[ \frac{|0.169-\pi_0|}{\sqrt{\frac{\pi_0(1-\pi_0)}{269136}}} = 1.96, \] or equivalently, \[ \left(1+ \frac{3.84}{269136}\right) \pi_0^2 - \left(2\times 0.169 + \frac{3.84}{269136}\right) \pi_0 + 0.169^2 = 0. \] Solve the \(ax^2 + bx+c=0\) by \(x=\frac{-b \pm \sqrt{b^2-4ac}}{2a}\).

curve(abs(0.169-x)/sqrt(x*(1-x)/269136), 0.1, 0.2, ylab="|z|", xlab=expression(pi_0))
abline(1.96, 0)

a = 1+ 3.84/269136
b=-(2*0.169+3.84/269136)
c=0.169^2
(-b+sqrt(b^2-4*a*c))/(2*a)
## [1] 0.1704203
(-b-sqrt(b^2-4*a*c))/(2*a)
## [1] 0.1675892

In this example, the Score CI is almost the same as Wald CI.

[Example] Exact test for a trial with $n=10$ and $y=9$ successes.
binom.test(x=9,n=10,p=0.5)
## 
##  Exact binomial test
## 
## data:  9 and 10
## number of successes = 9, number of trials = 10, p-value = 0.02148
## alternative hypothesis: true probability of success is not equal to 0.5
## 95 percent confidence interval:
##  0.5549839 0.9974714
## sample estimates:
## probability of success 
##                    0.9