반응형

4.2.2 독립성 검정

4.3) Goodman Kruskal 6,800명을 대상으로 눈색과 머리색을 조사하여 얻은 자료를 가지고 아래와 같은 관찰표를 얻엇다. 눈색과 머리색에 따라 3X4 분할표를 구성할 눈색이 머리색에 영향을 주는가? , 서로 독립저긴가?

 

B1

B2

B3

B4

A1

1768

807

189

47

2811

A2

946

1387

746

53

3132

A3

115

438

288

16

857

2829

2632

1223

116

6800


   H0 눈색과 머리색은 독립이다

   H1 눈색과 머리색인 서로관련이 있다

 

1) 데이터 입력

> out = matrix(c(1768, 807, 189, 47, 946, 1387, 746, 53, 115, 438, 288, 16), nrow=3, byrow = T)

> dimnames(out) = list (eye=c('e1','e2','e3'),hair=c('h1','h2','h3','h4'))

> out

hair

eye    h1   h2  h3 h4

e1   1768  807 189 47

e2    946 1387 746 53

e3    115  438 288 16

> addmargins(out) #분할표 만들기

hair

eye      h1   h2   h3  h4  Sum

e1     1768  807  189  47 2811

e2      946 1387  746  53 3132

e3      115  438  288  16  857

Sum   2829 2632 1223 116 6800

 

2) 데이터 시각화

> par(mfrow=c(1,2))

> dotchart(out)

> dotchart(t(out))

 

 


> par(mfrow=c(1,1))

> mosaicplot(out)


결과 해석: 눈색과 머릿색이 서로 영향을 주고 있음을 있다

 

 

3) 카이제곱 검정 

> chisq.test(out)

 

Pearson's Chi-squared test

 

data:  out

X-squared = 1073.5, df = 6, p-value < 2.2e-16

결과 해석:

  귀무가설 H0 눈색과 머리색은 독립이다.

  대립가설 H1 눈색과 머리색인 서로관련이 있다.

  p-value 2.2e-16 < 0.001

  의사결정: p-value값이 0.001보다 작으므로 눈색과 머리색이 유의하게 서로 영향을 주고 있음을 알 수 있다.



4) 카이제곱 검정 결과 보기

> names(chisq.test(out))

[1] "statistic" "parameter" "p.value"   "method"    "data.name" "observed"  "expected"  "residuals" "stdres"  

> chisq.test(out)$observed #관찰도수

hair

eye    h1   h2  h3 h4

e1 1768  807 189 47

e2  946 1387 746 53

e3  115  438 288 16

> chisq.test(out)$expected #기대도수

hair

eye         h1        h2       h3       h4

e1 1169.4587 1088.0224 505.5666 47.95235

e2 1303.0041 1212.2682 563.2994 53.42824

e3  356.5372  331.7094 154.1340 14.61941

> chisq.test(out)$residuals #잔차

hair

eye          h1        h2         h3          h4

e1  17.502565 -8.519654 -14.079133 -0.13752858

e2  -9.890092  5.018483   7.697865 -0.05858643

e3 -12.791799  5.836008  10.782543  0.36107650

 

출처: 보건정보데이터 분석(이태림 저)



반응형
Posted by 마르띤
,