티스토리 뷰

Polychoric, tetrachoric, polyserial, and biserial correlation는 정규 분포를 띄는 잠재변수를 가정합니다.

Polychoric, tetrachoric, polyserial, and biserial correlations assume latent variables which are normally distributed.


그리고 잠재변수가 0/1 또는 0/1/2/3/.../n 등의 이분/ordinal 변수로 관찰될 때, 잠재변수 간의 상관계수를 구합니다.

And when the observations are either 0/1 or ordinal which is manifestation of continuous latent variables,  

polychoric, tetrachoric, polyserial, and biserial correlations compute correlations between latent variables(or latent variable and observed continuous variable).


이런 상관계수를 R에서는 psych나 polycor 패키지를 사용하여 구할 수 있습니다.

We can compute those correlations in R with package psych or polycor.


# COMPARISON polycor::hetcor, psych::polychoric

R <- R[sample(1:100, 50),1:5]

colnames(R)=c("Q1","Q2","Q3","Q4","Q5")

rownames(R)=1:50


dump(c("R"))

R2 <- as.data.frame(R)

R2 <- as.data.frame(lapply(R2, ordered))

hetcor(R2, use="pairwise.complete.obs");

polychoric(R, smooth=F, correct=0)


hetcor(R2, use="complete.obs");

polychoric(R[complete.cases(R),], smooth=F, correct=0)

# polychoric doesn't support std.err

# polychoric doesn't support ML either



psych::polychoric과 polycor::hetcor는 모두 여러 변수 간의 polychoric correlation의 상관행렬을 구합니다.

psych::polychoric and polycor::hetcor both computes polychoric correlation matrix.


두 명령어의 차이점은 다음과 같습니다.

Differences between two functions(polychoric and hetcor) are these.


1. 기본값

   hetcor는 complete observation(한 행에서 NA가 전혀 없는 행만을 고름)을 쓰고, 

   polychoric은 pairwise complete observation(두 열의 상관계수를 구할 때, NA가 없는 행을 모두 사용)을 쓴다.

1. Default options

   hetcor uses complete observation by default and

   polychoric uses pairwsie complete observation by default.


2. 결과와 옵션

  가. hetcor는 SE(표준오차)를 제공하고, polychor는 그렇지 않다.

  나. hetcor는 잠재변수에 대한 Bivariate Normality를 검증하고, polychor는 그렇지 않다.

  다. hetcor는 ML 옵션을 제공하고, polychor는 그렇지 않다.

  라. polychor는 smooth와 correct 옵션을 제공하고 hetcor는 그렇지 않다.

      smooth는 pairwise complete observation에서 상관계수를 구했을 때, 전체 상관행렬이 positive definite이 아닐 때, positive definite을 바꿔주며, correct는 contingency table에서 0인 cell을 0.5로 바꿔준다.


2. Results and options

  A. hetcor provides SE and polychor doesn't

  B. hetcor provides test of bivariate normality and polychor doesn't

  C. hetcor provides ML option and polychor doesn't

  D. polychor provides options <smooth> and <correct>

     <smooth> when the outcome matrix is not positive definite, apply simple smoothing algorithm

     <correct> when contingency table has a cell with 0, correct modifies it to 0.5(default value)


연산 속도는 polychoric가 훨씬 빠르다.

Computation speed of polychoric is much faster.

 

위의 소스 실행을 위한 데이터

Data for the source above


R <-

structure(c(4, 4, 5, 3, 4, 4, 3, 4, 4, 3, 3, 4, 3, 4, 2, 4, 4, 

4, 4, 3, 4, 5, 4, 4, 4, 4, 4, 4, 5, 4, 2, 4, 4, 2, 4, 4, 4, 5, 

4, 4, 5, 1, NA, 3, 5, 4, 5, 5, 4, 4, 4, 5, 5, 4, 4, 5, 4, 4, 

5, 5, 4, 5, 4, 4, 5, 4, 5, 5, 5, 3, 5, 5, 5, 5, 4, 5, 5, 4, 5, 

NA, 4, 5, 5, 4, 5, 5, 5, 5, 4, 3, 5, 4, NA, 3, 5, 4, 5, 5, 5, 

5, 3, 3, 4, 2, 3, 2, 4, 2, 4, 2, 4, 3, 3, 2, 3, 5, 2, 5, 3, 3, 

4, 5, 4, 2, 4, 5, 3, 4, 5, 3, 2, 4, 3, 2, 4, 4, 5, 4, 5, 1, 3, 

1, NA, 3, 5, 4, 3, 5, 5, 5, 4, 4, 4, 5, 4, 4, 4, 3, 4, 3, 5, 

3, 4, 4, 4, 5, 5, 4, 3, 4, 4, 5, 5, 1, 4, 3, 3, 4, 5, 4, 2, 4, 

4, 4, 5, 4, 5, 5, 5, 3, 5, 4, NA, 3, 5, 4, 5, 5, 5, 2, 5, 5, 

5, 5, 5, 5, 4, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5, 5, 4, 5, 5, 4, 

5, 4, 5, 5, 4, 5, 5, 4, 4, 5, 4, 5, 5, 5, 5, 2, 4, 3, 5, NA, 

3, 5, 4, 5, 5, 4, 3), .Dim = c(50L, 5L), .Dimnames = list(c("1", 

"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", 

"14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", 

"25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", 

"36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", 

"47", "48", "49", "50"), c("Q1", "Q2", "Q3", "Q4", "Q5")))



마지막으로, stata 결과와 R 결과가 다를 수도 있는데, R 결과가 정확한 듯 하다.

Lastly, stata and R produce different results but R seems to be correct.

http://r.789695.n4.nabble.com/Tetrachoric-correlation-in-R-vs-stata-td802538.html


'차기작 : R을 배우자' 카테고리의 다른 글

Against underflow  (0) 2015.10.10
fitting data to gpcm(ltm or mirt?)  (0) 2015.09.26
rJava loading 문제  (0) 2015.05.17
training MNIST data with the package "deepnet"  (2) 2014.11.13
XOR with package "h2o"  (0) 2014.11.11
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함