"R 카이제곱검정"의 두 판 사이의 차이

(새 문서: ==개요== ;R chisq.test() <source lang='r'> M <- as.table(rbind(c(762, 327, 468), c(484, 239, 477))) dimnames(M) <- list(gender = c("F", "M"), party = c("Democra...)
 
 
(사용자 2명의 중간 판 17개는 보이지 않습니다)
2번째 줄: 2번째 줄:
;R chisq.test()
;R chisq.test()


<source lang='r'>
==분할표 입력==
M <- as.table(rbind(c(762, 327, 468), c(484, 239, 477)))
===예시: 성별 × 지지정당===
dimnames(M) <- list(gender = c("F", "M"),
<syntaxhighlight lang='r' run>
                    party = c("Democrat","Independent", "Republican"))
t <- as.table(rbind(c(762, 327, 468), c(484, 239, 477)))
M
dimnames(t) <- list(gender = c("F", "M"), party = c("Democrat","Independent", "Republican"))
##      party
t # crosstab
## gender Democrat Independent Republican
chisq.test(t) # χ²=30.07, p=0.000002954
##      F      762        327        468
</syntaxhighlight>
##      M      484        239        477
 
Xsq <- chisq.test(M)
===예시: 응답 × 학년===
Xsq
<syntaxhighlight lang='r' run>
##  
t <- as.table(rbind(c(5,8,6,4),c(10,7,8,6),c(5,4,7,8),c(5,6,4,7)))
## Pearson's Chi-squared test
dimnames(t) <- list(Response=c(1,2,3,4), Grade=c(1,2,3,4))
##
t # crosstab
## data: M
chisq.test(t) # χ²=5.2265, p=0.8141
## X-squared = 30.07, df = 2, p-value = 2.954e-07
</syntaxhighlight>
Xsq$observed
 
##      party
==원자료 입력==
## gender Democrat Independent Republican
===예시: 성별 × 찬성여부===
##      F      762        327        468
<syntaxhighlight lang='r' run>
##      M      484        239        477
df <- read.table( header=TRUE, stringsAsFactors=FALSE, text="
Xsq$expected
Gender Agree
##      party
Male   True
## gender Democrat Independent Republican
Male   False
##      F 703.6714    319.6453   533.6834
Male  False
##      M 542.3286    246.3547   411.3166
Male  False
Xsq$residuals
Male   False
##      party
Female True
## gender   Democrat Independent Republican
Female True
##      F  2.1988558  0.4113702 -2.8432397
Female True
##      M -2.5046695  -0.4685829  3.2386734
Female False
Xsq$stdres
Female False
##      party
")
## gender  Democrat Independent Republican
tbl = table(df)
##      F  4.5020535  0.6994517 -5.3159455
tbl # crosstab
##      M -4.5020535  -0.6994517  5.3159455
chisq.test(tbl) # χ²=0.41667, p=0.5186
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==
* [[R t.test()]]
* [[R t.test()]]
* [[R 분할표]]
* [[R 피셔의 정확검정]]
* [[R 맥니머의 검정]]
* [[카이제곱 검정]]
* [[카이제곱 검정]]



2020년 12월 6일 (일) 02:57 기준 최신판

1 개요[ | ]

R chisq.test()

2 분할표 입력[ | ]

2.1 예시: 성별 × 지지정당[ | ]

t <- as.table(rbind(c(762, 327, 468), c(484, 239, 477)))
dimnames(t) <- list(gender = c("F", "M"), party = c("Democrat","Independent", "Republican"))
t # crosstab
chisq.test(t) # χ²=30.07, p=0.000002954

2.2 예시: 응답 × 학년[ | ]

t <- as.table(rbind(c(5,8,6,4),c(10,7,8,6),c(5,4,7,8),c(5,6,4,7)))
dimnames(t) <- list(Response=c(1,2,3,4), Grade=c(1,2,3,4))
t # crosstab
chisq.test(t) # χ²=5.2265, p=0.8141

3 원자료 입력[ | ]

3.1 예시: 성별 × 찬성여부[ | ]

df <- read.table( header=TRUE, stringsAsFactors=FALSE, text="
Gender Agree
Male   True
Male   False
Male   False
Male   False
Male   False
Female True
Female True
Female True
Female False
Female False
")
tbl = table(df)
tbl # crosstab
chisq.test(tbl) # χ²=0.41667, p=0.5186

4 같이 보기[ | ]

5 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}