R 카이제곱검정

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