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

2번째 줄: 2번째 줄:
;R chisq.test()
;R chisq.test()


==분할표==
<syntaxhighlight lang='r'>
<syntaxhighlight lang='r'>
t <- as.table(rbind(c(762, 327, 468), c(484, 239, 477)))
t <- as.table(rbind(c(762, 327, 468), c(484, 239, 477)))
dimnames(t) <- list(gender = c("F", "M"), party = c("Democrat","Independent", "Republican"))
dimnames(t) <- list(gender = c("F", "M"), party = c("Democrat","Independent", "Republican"))
t
t # crosstab
##      party
chisq.test(t) # p=2.954e-07
## gender Democrat Independent Republican
</syntaxhighlight>
##      F      762        327        468
##      M      484        239        477


x <- chisq.test(t)
==원자료==
x
<syntaxhighlight lang='r'>
##
df <- read.table( header=TRUE, stringsAsFactors=FALSE, text="
## Pearson's Chi-squared test
Gender Agree
##
Male  True
## data:  t
Male  False
## X-squared = 30.07, df = 2, p-value = 2.954e-07
Male   False
summary(x)
Male   False
##          Length Class  Mode   
Male   False
## statistic 1      -none- numeric 
Female True
## parameter 1      -none- numeric 
Female True
## p.value   1      -none- numeric 
Female True
## method    1      -none- character
Female False
## data.name 1      -none- character
Female False
## observed  6      table  numeric 
")
## expected  6      -none- numeric 
tbl = table(df)
## residuals 6      table  numeric 
tbl # crosstab
## stdres    6      table  numeric 
chisq.test(tbl) # p=0.5186
x$p.value
## [1] 2.953589e-07
 
x$observed
##      party
## gender Democrat Independent Republican
##      F      762        327        468
##      M      484        239        477
x$expected
##      party
## gender Democrat Independent Republican
##      F 703.6714    319.6453   533.6834
##      M 542.3286    246.3547   411.3166
x$residuals
##      party
## gender  Democrat Independent Republican
##      F  2.1988558  0.4113702 -2.8432397
##      M -2.5046695  -0.4685829  3.2386734
x$stdres
##      party
## gender  Democrat Independent Republican
##      F  4.5020535  0.6994517 -5.3159455
##      M -4.5020535  -0.6994517  5.3159455
</syntaxhighlight>
</syntaxhighlight>



2020년 12월 5일 (토) 22:12 판

1 개요

R chisq.test()

2 분할표

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

3 원자료

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

4 같이 보기

5 참고

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