R 피셔의 정확검정

1 개요[ | ]

R 피셔의 정확검정
  • fisher.test()
  • alternative 옵션을 생략하면 기본값은 "two.sided" (양측 검정)

2 분할표 입력[ | ]

2.1 예시 1: 차 마시는 사람[ | ]

## Agresti (1990, p. 61f; 2002, p. 91) Fisher's Tea Drinker
# 영국 여성은 우유와 차 중 어느 것을 먼저 컵에 부었는지 구별할 수 있다고 주장했다.
# 테스트를 위해 그녀는 8컵의 차를 받는데, 그 중 4잔에는 우유를 먼저 부었다.
# 영가설은 실제 부은 순서와 여성의 추측 사이에 연관성이 없다는 것이다.
# 대립가설은 긍정적 연관성이 있다는 것이다 (승산비가 1보다 크다는 것).
TeaTasting <-
  matrix(c(3, 1, 1, 3),
         nrow = 2,
         dimnames = list(Guess = c("Milk", "Tea"),
                         Truth = c("Milk", "Tea")))
fisher.test(TeaTasting, alternative = "greater") # p=0.2429

2.2 예시 2: 동성 쌍둥이의 범죄 유죄판결[ | ]

## Fisher (1962, 1970), Criminal convictions of like-sex twins
Convictions <- matrix(c(2, 10, 15, 3), nrow = 2,
                      dimnames =
                        list(c("Dizygotic", "Monozygotic"),
                             c("Convicted", "Not convicted")))
Convictions
fisher.test(Convictions, alternative = "less")
fisher.test(Convictions, conf.int = FALSE)
fisher.test(Convictions, conf.level = 0.95)$conf.int
fisher.test(Convictions, conf.level = 0.99)$conf.int

2.3 예시 3: 직업 만족도[ | ]

## A r x c table  Agresti (2002, p. 57) Job Satisfaction
Job <- matrix(c(1,2,1,0, 3,3,6,1, 10,10,14,9, 6,7,12,11), 4, 4,
              dimnames = list(income = c("< 15k", "15-25k", "25-40k", "> 40k"),
                              satisfaction = c("VeryD", "LittleD", "ModerateS", "VeryS")))
fisher.test(Job) # 0.7827
fisher.test(Job, simulate.p.value = TRUE, B = 1e5) # also close to 0.78

2.4 예시 4[ | ]

## 6th example in Mehta & Patel's JASA paper
MP6 <- rbind(
  c(1,2,2,1,1,0,1),
  c(2,0,0,2,3,0,0),
  c(0,1,1,1,2,7,3),
  c(1,1,2,0,0,0,1),
  c(0,1,1,1,1,0,0))
fisher.test(MP6)
# Exactly the same p-value, as Cochran's conditions are never met:
fisher.test(MP6, hybrid=TRUE)

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

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
fisher.test(t) # p=3.027e-07

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
fisher.test(tbl) # p=0.5238

4 같이 보기[ | ]

5 참고[ | ]

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