Permutation test (순열검정법) Start.

BioinformaticsAndMe


Permutation test 는 t-test 등의 일반적인 통계 검정을 수행할 만큼 샘플의 수가 크지 않은 경우에 사용할 수 있는 검정 방법. 이 경우 주어진 샘플을 무작위로 추출하여 인공적으로 샘플 숫자를 늘림으로써 전체 모수를 통계 검정이 가능한 크기만큼 키운 다음, 원래 주어진 샘플의 통계 값(ex. 평균, 분산 등)이 전체 모수와 비교하여 얼마나 유의하게 차이 나는지를 검정하는 방법이다.



#‘저체중아의 산모’ vs ‘저체중아x의 산모’ 의 체중 차이를 Permutation test 해보자


1. birthwt 데이터 로딩
source("https://bioconductor.org/biocLite.R")
biocLite("MASS") #MASS package에 있는 birthwt 데이터셋을 사용하려함
library(MASS)
data(birthwt)
View(birthwt)


2. 정상군과 실험군 분류

normal = birthwt[birthwt[,"low"]==0, "lwt"]

normal

case = birthwt[birthwt[,"low"]==1, "lwt"]

case

t.test(normal, case)


3. 두 그룹의 산모 체중에 대한 t 검정 값

real_test = t.test(normal, case)$statistic 

real_test


4. 두 그룹간의 permutation test

permfunc.R

source("permfunc.R") #첨부파일 다운하여 실행

tperm = perm.test(normal, case, n.perm=1000) #1000번 Permutation을 통해 1000개의 t value 생성

hist(tperm)

abline(v=abs(real_test), lty=2, col=2) #실제 t value 가 분포의 극단치에서 보임 (우연이 아닐 것이라고 예상)

5. Empirical p value

pvalue = mean(abs(tperm) >= abs(real_test))  #위 그래프에서 Red 점선 오른쪽에 있는 개수들의 평균을 구함

pvalue

[1] 0.011

따라서, 계산된 Emprical p-value는 0.011로 '저체중아 출산과 산모의 체중은 관련성이 있다' 라고 결론 내릴 수 있다.


# 위 내용은 BITEC (Biomedical Informatics Training and Education Center) 교육내용을 참고하였다.


6. 실습 Example (위와 같은 맥락이지만, 연습삼아 해보셔도 좋을듯하다)

1) make up some ‘true’ data

carrier <- rep(c(0,1), c(100,200))

null.y <- rnorm(300)

alt.y <- rnorm(300, mean=carrier/2)

2) t-test

t.test(null.y~carrier, var.equal=TRUE)

t.test(alt.y~carrier, var.equal=TRUE)

3) permutation test

null.diff <- mean(null.y[carrier==1])-mean(null.y[carrier==0])
alt.diff <- mean(alt.y[carrier==1])-mean(alt.y[carrier==0])
one.test <- function(x,y) {
  xstar<-sample(x)
  mean(y[xstar==1])-mean(y[xstar==0])
}
many.truenull <- replicate(1000, one.test(carrier, null.y))
many.falsenull <- replicate(1000, one.test(carrier, alt.y))
4) 귀무가설 채택
hist(many.truenull)
abline(v=null.diff, lwd=2, col="purple")
mean(abs(many.truenull) > abs(null.diff))

5) 귀무가설 기각
hist(many.falsenull)
abline(v=alt.diff, lwd=2, col="purple")
mean(abs(many.falsenull) > abs(alt.diff))



마무리하며..

Permutation test 에 대한 간단한 R 예제를 살펴보았다.

통계검정 하려는 샘플 수가 적을 때 사용할 수 있는 기법이라는 점이 핵심으로 보인다.




Permutation test (순열검정법) End.

BioinformaticsAndMe

'R' 카테고리의 다른 글

R, Command line interface Ⅱ  (0) 2018.07.20
R, Command line interface Ⅰ  (0) 2018.07.16
R, RStudio 설치  (0) 2018.07.14
Cogena-2 (CoExpression 분석)  (0) 2018.07.06
Cogena-1 (CoExpression 분석)  (0) 2018.07.05

+ Recent posts