1- A)

Difference of proportions

$\hat{\pi_{1}} = \dfrac{21}{23} = 0.913$
$\hat{\pi_{2}} = \dfrac{8}{17} = 0.470$
$SE = \sqrt{\dfrac{0.913\times (1-0.913)}{23} + \dfrac{0.47\times (1-0.47)}{17}} = 0.134$
$0.913-0.470 \pm1.96 \times 0.134 = (0.7, 0.18)$

rcode

diffscoreci(21, 23, 8, 17, conf.level=0.95) #Score CI for D


data:  

95 percent confidence interval:
 0.1648695 0.6755755
relative risk

$\dfrac{\hat{\pi_{1}}}{\hat{\pi_{2}}} = \dfrac{0.91}{0.47} = 1.93$
$SE = \sqrt{\dfrac{1 – \hat{\pi_{1}}}{n_{1+}\hat{\pi_{1}}} + \dfrac{1 – \hat{\pi_{2}}}{n_{2+}\hat{\pi_{2}}}} = \sqrt{\dfrac{1-0.91}{23 \times 0.91} + \dfrac{1 – 0.47}{17 \times 0.47}} = \sqrt{0.0043 + 0.0663} = 0.265$
$\log(1.93) \pm 1.96 \times 0.265 = 0.65 \pm 0.519 = (1.169, 0.131)$
exp -> $(3.21, 1.13)$

rcode

riskscoreci(21, 23, 8, 17, conf.level=0.95) #Score CI for D

data:  

95 percent confidence interval:
 1.262382 3.524109
odds ratio

$\hat{\theta} = \dfrac{21 \times 9}{8 \times 2} = 11.81$
$SE = \sqrt{\dfrac{1}{21} + \dfrac{1}{2} + \dfrac{1}{8} + \dfrac{1}{0}} = 0.884$
$log(11.81) \pm 1.96\times 0.884 = 2.468 \pm 1.732 = (4.2, 0.736)$
exp -> $(66.6, 2.08)$

rcode

orscoreci(21, 23, 8, 17, conf.level=0.95) #Score CI for D 

data:  

95 percent confidence interval:
  2.224729 59.901676

1-B)

$\hat{\mu_{11}} = \dfrac{23 \times 29}{40} = 16.675$
$\hat{\mu_{12}} = \dfrac{23 \times 11}{40} = 6.325$
$\hat{\mu_{21}} = \dfrac{17 \times 29}{40} = 12.325$
$\hat{\mu_{22}} = \dfrac{17 \times 11}{40} = 4.675$

Pearson Chi-squared

$X^{2} = \dfrac{(n_{11} – \hat{\mu_{11}})^{2}}{\hat{\mu_{11}}} + \dfrac{(n_{12} – \hat{\mu_{12}})^{2}}{\hat{\mu_{12}}} + \dfrac{(n_{21} – \hat{\mu_{21}})^{2}}{\hat{\mu_{21}}} + \dfrac{(n_{22} – \hat{\mu_{22}})^{2}}{\hat{\mu_{22}}}$
$= \dfrac{(21 – 16.675)^{2}}{16.675} + \dfrac{(2 – 6.325)^{2}}{6.325}  + \dfrac{(8 -12.325)^{2}}{12.325} + \dfrac{(9 – 4.675)^{2}}{4.675}$
$= 9.598$

Likelihood-ratio Chi-squared

$G^{2} = 2 \times (n_{11} \times log(\dfrac{n_{11}}{\hat{\mu_{11}}}) + n_{12} \times log(\dfrac{n_{12}}{\hat{\mu_{12}}}) + n_{21} \times log(\dfrac{n_{21}}{\hat{\mu_{21}}}) + n_{22} \times log(\dfrac{n_{22}}{\hat{\mu_{22}}}))$
$= 2 \times ( 21 \times log(\dfrac{21}{16.675}) + 2 \times log(\dfrac{2}{6.325}) + 8 \times log(\dfrac{8}{12.325}) + 9 \times log(\dfrac{9}{4.675}))$
$= 2 \times (21 \times 0.230 + 2 \times (-1.151) + 8 \times (1.235) + 9 \times 0.654)$
$ = 2 \times (4.83 – 2.302 + 9.88 +  5.886) = 36.588$

1- C)

Fisher’s exact

$n_{11} = 21$
${23 \choose 21} {17 \choose 8} / {40 \choose 29} = 0.0026$
$n_{11} = 22$
${23 \choose 22} {17 \choose 7} / {40 \choose 29} = 0.00019$
$n_{11} = 23$
${23 \choose 23} {17 \choose 6} / {40 \choose 29} = 0.0000053$
$p-value = 0.0026 + 0.00019 + 0.0000053 = 0.00279$

rcode

fisher_larynx <- matrix(c(21, 8, 2, 9), ncol=2)
fisher_larynx
    [,1] [,2]
[1,]   21    2
[2,]    8    9


fisher.test(fisher_larynx)                        #Fisher's exact test
 Fisher's Exact Test for Count Data

data:  fisher_larynx
p-value = 0.003444
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
   1.755377 126.314516
sample estimates:
odds ratio 
  10.98843 


fisher.test(fisher_larynx, alternative="greater") #Fisher's exact test (one-sided)
 Fisher's Exact Test for Count Data

data:  fisher_larynx
p-value = 0.002859
alternative hypothesis: true odds ratio is greater than 1
95 percent confidence interval:
 2.194549      Inf
sample estimates:
odds ratio 
  10.98843 


library(epitools)
ormidp.test(21, 8, 2, 9, or=1) #Mid P-value
    one.sided  two.sided
1 0.001529065 0.00305813

2-A)

$\hat{\mu_{11}} = \dfrac{29 \times 76}{273} = 8.07$
$\hat{\mu_{12}} = \dfrac{29 \times 108}{273} = 11.47$
$\hat{\mu_{13}} = \dfrac{29 \times 89}{273} = 9.45$
$\hat{\mu_{21}} = \dfrac{137 \times 76}{273} = 38.13$
$\hat{\mu_{22}} = \dfrac{137 \times 108}{273} = 54.19$
$\hat{\mu_{23}} = \dfrac{137 \times 89}{273} = 44.66$
$\hat{\mu_{31}} = \dfrac{48 \times 76}{273} = 13.36$
$\hat{\mu_{32}} = \dfrac{48 \times 108}{273} = 18.98$
$\hat{\mu_{33}} = \dfrac{48 \times 89}{273} = 15.64$
$\hat{\mu_{41}} = \dfrac{59 \times 76}{273} = 16.42$
$\hat{\mu_{42}} = \dfrac{59 \times 108}{273} = 23.34$
$\hat{\mu_{43}} = \dfrac{59 \times 89}{273} = 19.23$

Pearson Chi-squared

$X^{2} = \dfrac{(9 – 8.07)^{2}}{8.07} + \dfrac{(11 – 11.47)^{2}}{11.47} +\dfrac{(9 – 9.45)^{2}}{9.45} +\dfrac{(44 – 38.13)^{2}}{38.13}$
$+ \dfrac{(52 – 54.19)^{2}}{54.19} + \dfrac{(41 – 44.66)^{2}}{44.66}+ \dfrac{(13 – 13.36)^{2}}{13.36} + \dfrac{(23 – 18.98)^{2}}{18.98}$
$+ \dfrac{(12 – 15.64)^{2}}{15.64} + \dfrac{(10 – 16.42)^{2}}{16.42}+ \dfrac{(22 – 23.34)^{2}}{23.34} + \dfrac{(27 – 19.23)^{2}}{19.23} = 8.873$

Likelihood-ratio Chi-squared

$G^{2} = 2 \times (9 \times log(\dfrac{9}{8.07}) + 11 \times log(\dfrac{11}{11.47}) + 9 \times log(\dfrac{9}{9.45})$
$+ 44 \times log(\dfrac{44}{38.13}) + 52 \times log(\dfrac{52}{54.19}) + 41 \times log(\dfrac{41}{44.66})$
$+ 13 \times log(\dfrac{13}{13.36}) + 23 \times log(\dfrac{23}{18.98}) + 12 \times log(\dfrac{12}{15.64})$
$+ 10 \times log(\dfrac{10}{16.42}) + 22 \times log(\dfrac{22}{23.34}) + 27 \times log(\dfrac{27}{19.23}))$
$= 2 \times (0.981 – 0.460 – 0.439 + 6.300 – 2.14 – 3.505 – 0.355 + 4.418 – 3.179 – 4.959 – 1.3 + 9.162) = 9.048$

2-B)

$(8.07, 0.40), (19.23,2.43)$
잔차가 2보다 커 기각된다.

2-C)

$\theta = \dfrac{9 \times 27}{9 \times 10} = 2.7$
$log(2.7) \pm 1.96 \times \sqrt{\dfrac{1}{9} + \dfrac{1}{9} + \dfrac{1}{10} + \dfrac{1}{27}}$
$= 0.993 \pm 1.112 = (2.105, -0.119)$

3-A)

Chisq = 4.7489, p-value  : 0.01465852
increasing trand

test<-matrix(c(9, 44, 13, 10, 11, 52, 23, 22, 9, 41, 12, 27), ncol=3)

test
     [,1] [,2] [,3]
[1,]    9   11    9
[2,]   44   52   41
[3,]   13   23   12
[4,]   10   22   27

CMHtest(test, rscores=c(1, 2, 3, 4), cscore=c(1,2,3)) #M-test#####END
Cochran-Mantel-Haenszel Statistics 

                 AltHypothesis  Chisq Df     Prob
cor        Nonzero correlation 4.7489  1 0.029317
rmeans  Row mean scores differ 7.2240  3 0.065090
cmeans  Col mean scores differ 4.8673  2 0.087717
general    General association 8.8384  6 0.182870

sqrt(4.7489)
2.179197

1-pnorm(2.179197)
0.01465852

3-B)

Chisq = 4.7489, p-value  : 0.01465852
결과는 A와 같다.

3-C)

Chisq = 6.0867, p-value  : 0.006810159
결과는 다르게 나온다.


0개의 댓글

답글 남기기

이메일 주소는 공개되지 않습니다.