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

10번째 줄: 10번째 줄:
chisq.test(t) # p=2.954e-07
chisq.test(t) # p=2.954e-07
</syntaxhighlight>
</syntaxhighlight>
===예시: 응답 × 학년===
<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)))
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
<syntaxhighlight>


==원자료 입력==
==원자료 입력==

2020년 12월 6일 (일) 02:56 판

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) # p=2.954e-07

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
<syntaxhighlight>

==원자료 입력==
===예시: 성별 × 찬성여부===
<syntaxhighlight lang='r' run>
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) # p=0.5186

3 같이 보기

4 참고

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