Problems from text: 3.3, 3.4
## Loading required package: PropCIs
## Warning: package 'PropCIs' was built under R version 3.4.1
The GSS to cross-classify a subject’s political party ID with their opinion about whether homosexuals should have the right to marry, for subjects having strong identification with a particular party and strong agreement or disagreement with homosexual marriage. Show that (a) \(log(\hat\theta) = 3.728\), (b) its standard error is \(0.746\), and (c) the Wald 95% confidence interval for \(\theta\) is (9.6, 179.3). Name the main factor that causes this interval estimate to be so imprecise.
A) \(\hat\theta=\frac{n11\times n22}{n12\times n21}\). So, \(\hat\theta=\frac{60\times 61}{2\times 44}=\) 41.5909091; which \(log(\hat\theta)=\) 3.7278816 \(\approx 3.7278\)
B) For the standard error \[\hat\sigma(log\ \hat\theta)=\sqrt{\frac{1}{n_{11}}+\frac{1}{n_{12}}+\frac{1}{n_{21}}+\frac{1}{n_{22}}}\] The standard error \(\hat\sigma(log\ \hat\theta)=\sqrt{1/60+1/44+1/2+1/61}=\) 0.7455115 \(\approx 0.746\)
C) Using \(log\ \hat\theta\pm z_{a/2}\hat\sigma(log\hat\theta)\) for the Wald confidence interval for \(log\ \theta\). The 95% confidence interval for \(log\ \theta=3.728\pm z_{0.05/2}\times 0.746=\) [2.26564, 5.18996] \(\approx[2.2656,\ 5.189]\). Now \(\theta=[e^{2.2656},\ e^{5.189}]=\) [9.636905, 179.2891741] \(\approx[9.6,\ 179.3]\). The main factor in the confidence interval being so imprecise is the small sample size.
Add a decimal of percision to correct numbers
For Table 2.10 on seat-belt use and results of auto accidents, find and interpret 95% confidence intervals for the conceptual population (a) odds ratio, (b) difference of proportions, and (c) relative risk.
A) The odds ratio \(\hat\theta=\frac{n11\times n22}{n12\times n21}\), which \(\hat\theta=\frac{1085\times 441,239}{703\times 55,623}=\) 12.2431705. So, \(log\ \hat\theta=\) 2.5049683 \(\approx 2.50497\).
The standard error \(\hat\sigma(log\ \hat\theta)=\sqrt{\frac{1}{n_{11}}+\frac{1}{n_{12}}+\frac{1}{n_{21}}+\frac{1}{n_{22}}}\). So, the standard error \(\hat\sigma(log\ \hat\theta)=\sqrt{1/1085+1/55,623+1/703+1/441,239}=\) 0.0486249 \(\approx 0.04862\).
The Wald 95% confidence interval \(log\ \hat\theta\pm z_{a/2}\hat\sigma(log\hat\theta)\). So, \(log\ \theta=2.50497\pm 1.96\times 0.04862=\) [2.4096748, 2.6002652] \(\approx[2.4097,\ 2.6003]\). Now \(\theta=[e^{2.4097},\ e^{2.6003}]\) [11.1306215, 13.4677778] \(\approx[11.1306,\ 13.4678]\).
The PropCIs orscoreci test returns
orscoreci(1085,56708,703,441942,conf.level = 0.95)
##
##
##
## data:
##
## 95 percent confidence interval:
## 11.13015 13.46749
B) The sample proportion \(\hat\pi=y_i/n_i\). So, for \(\hat\pi_1=\) 0.0191331 and \(\hat\pi_2=\) 0.0015907.
The standard error \[\sigma(\hat\pi_1-\hat\pi_2)=\sqrt{\frac{\pi_1(1-\pi_1)}{n_1}+\frac{\pi_2(1-\pi_2)}{n_2}}\] Then we replace \(\pi\) with \(\hat\pi\) to get \(\hat\sigma(\hat\pi_1-\hat\pi_2)\). So we have \(\hat\sigma(\hat\pi_1-\hat\pi_2)=\sqrt{\frac{0.0191(0.9809)}{56708}+\frac{0.0016(0.9984)}{441942}}=\)
sqrt(((0.0191*0.9809)/56708)+((0.0016*0.9984)/441942))
## [1] 0.0005779227
Now the 95% confidence interval \((\hat\pi_1-\hat\pi_2)=\pm z_{a/2}\hat\sigma(\hat\pi_1-\hat\pi_2)=0.0175\pm 1.96(0.0006)=\) [0.016324, 0.018676]. Using PropCIs Wald2ci test
Not Adjusted
wald2ci(1085,56708,703,441942,conf.level = 0.95, adjust = "Wald")
##
##
##
## data:
##
## 95 percent confidence interval:
## 0.01640877 0.01867602
## sample estimates:
## [1] 0.0175424
Adjusted
wald2ci(1085,56708,703,441942,conf.level = 0.95, adjust = "AC")
##
##
##
## data:
##
## 95 percent confidence interval:
## 0.0164230 0.0186912
## sample estimates:
## [1] 0.0175571
C) The sample relative risk \(r=\hat\pi_1/\hat\pi_2\) for above is 11.9375, and \(log\ r=\) 2.4796847.
The estimated standard error \(\hat\sigma(log\ r)=\sqrt{\frac{1-\hat\pi_1}{y_i}+\frac{1-\hat\pi_2}{y_2}}\) is \(\sqrt{\frac{0.9809}{1085}+\frac{0.9984}{703}}=\) 0.0482105.
The Wald 95% confidence interval \(log\ r\pm z_{a/2} \hat\sigma(log\ r)\) is \(2.4797\pm 1.96(0.0482)=\) [2.385228, 2.574172] and \([e^{2.3852}, e^{2.5742}]=\) [10.8612347, 13.1208163].
Using PropCIs riskscoreci test
riskscoreci(1085,56708,703,441294,conf.level = 0.95)
##
##
##
## data:
##
## 95 percent confidence interval:
## 10.92778 13.20003