티스토리 뷰

R에서 응답자료를 gpcm 모형으로 분석하고자 할 때 ltm 또는 gpcm 패키지를 쓸 수 있다.

You can use the package <gpcm> or <ltm> to fit your data to gpcm.


두 패키지의 가장 큰 차이점은 모수를 다른 방식으로 사용한다는 점이다.

The difference between two functions, gpcm and ltm is that they use different parameterization.


이제 두 함수 ltm::gpcm과 mirt::mirt를 통해 주어진 자료를 gpcm에 적합시키자.

Now, let's see how we can fit the data to gpcm via <ltm::gpcm> and <mirt::mirt>.



library("mirt")

library("ltm")


apply(R.gpcm, 2, unique)


n.item = ncol(R.gpcm); n.subj = nrow(R.gpcm);


fit.gpcm.mirt <- mirt(data=R.gpcm, 1, itemtype="gpcm")

cf.mirt <- coef(fit.gpcm.mirt, IRTpars=T)

# coef(fit.gpcm)


cf.mirt.mat <- matrix(NA, nrow=n.item, ncol=ncat)

for (i in 1:n.item) {

  cf.mirt.mat[i,1:length(cf.mirt[[i]])] = cf.mirt[[i]]

}


cf.ltm <- coef(fit.gpcm.ltm <- gpcm(R.gpcm, 

                                    constraint="gpcm", 

                                    control=list(GHk=62, optimizer="optim",

                                                 optimMethod="BFGS", verbose=T)), IRT.param=T)


cf.ltm.mat <- matrix(NA, nrow=n.item, ncol=ncat  verbose=T)

for (i in 1:n.item) {

  cf.ltm.mat[i,1] = cf.ltm[[i]][length(cf.ltm[[i]])]

  cf.ltm.mat[i,2:length(cf.ltm[[i]])] = cf.ltm[[i]][-length(cf.ltm[[i]])]

}


cf.mirt.mat

cf.ltm.mat


cf.mirt.mat - cf.ltm.mat


fit.gpcm.mirt@logLik

fit.gpcm.ltm$log.Lik


두 함수에 의해 추정된 모수와 logLikelihood를 비교해보자. 조금 차이가 있다.

If you look at the estimated parameters and the log likelihood from the two functions,

you could notice the slight difference!




실습용 데이터

R.gpcm <-

  structure(c(2, 3, 2, 4, 4, 1, 2, 2, 2, 2, 1, 1, 2, 1, 1, 4, 1, 

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

              4, 1, 1, 4, 4, 3, 1, 1, 3, 2, 0, 1, 1, 3, 1, 1, 4, 2, 3, 1, 2, 

              1, 4, 4, 1, 1, 2, 2, 2, 1, 1, 4, 1, 2, 2, 2, 2, 4, 1, 2, 4, 1, 

              1, 0, 2, 2, 2, 4, 4, 2, 1, 4, 3, 4, 2, 1, 2, 3, 1, 4, 1, 1, 1, 

              2, 4, 1, 4, 4, 4, 4, 2, 4, 0, 4, 4, 2, 2, 4, 1, 2, 2, 4, 3, 2, 

              0, 1, 4, 0, 2, 2, 2, 0, 4, 0, 4, 1, 3, 3, 0, 2, 1, 4, 2, 2, 3, 

              4, 1, 2, 3, 2, 0, 2, 0, 0, 1, 0, 3, 2, 3, 2, 3, 1, 4, 2, 2, 1, 

              4, 2, 2, 2, 1, 4, 2, 4, 2, 4, 4, 1, 0, 2, 1, 2, 2, 3, 1, 3, 4, 

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

              1, 2, 1, 1, 1, 1, 1, 1, 1, 3, 0, 0, 1, 1, 0, 2, 1, 1, 1, 1, 4, 

              2, 1, 1, 2, 1, 3, 1, 2, 3, 0, 1, 2, 1, 1, 1, 2, 2, 0, 1, 1, 1, 

              1, 0, 1, 1, 1, 1, 3, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 3, 1, 1, 2, 

              2, 1, 2, 1, 2, 2, 3, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 3, 1, 2, 1, 

              1, 1, 1, 2, 2, 2, 1, 2, 1, 4, 3, 2, 2, 0, 3, 3, 2, 3, 3, 2, 0, 

              4, 3, 3, 0, 4, 2, 2, 3, 3, 2, 4, 3, 3, 3, 3, 4, 2, 3, 2, 4, 2, 

              3, 3, 4, 3, 0, 3, 3, 2, 2, 3, 4, 3, 2, 3, 3, 3, 0, 2, 2, 3, 4, 

              3, 3, 3, 3, 2, 2, 0, 3, 3, 3, 3, 0, 4, 3, 2, 3, 4, 3, 4, 2, 2, 

              3, 4, 0, 2, 3, 2, 0, 2, 2, 2, 2, 4, 3, 3, 3, 3, 2, 2, 3, 2, 2, 

              4, 2, 3, 0, 4, 0, 2, 2, 1, 4, 0, 2, 2, 3, 0, 2, 1, 3, 3, 1, 3, 

              1, 2, 3, 2, 1, 3, 1, 4, 4, 1, 1, 1, 4, 2, 1, 1, 4, 2, 4, 2, 0, 

              2, 1, 3, 3, 3, 2, 2, 1, 1, 2, 1, 1, 3, 1, 1, 1, 2, 2, 0, 3, 2, 

              1, 0, 1, 2, 1, 1, 1, 0, 2, 1, 2, 1, 1, 4, 1, 3, 2, 2, 1, 2, 1, 

              1, 1, 2, 3, 2, 2, 3, 2, 0, 2, 2, 3, 4, 3, 1, 3, 4, 0, 3, 0, 3, 

              2, 2, 2, 1, 2, 3, 2, 2, 2, 1, 0, 2, 2, 0, 0, 4, 0, 0, 2, 2, 1, 

              1, 0, 2, 1, 0, 3, 0, 2, 3, 2, 0, 2, 1, 2, 3, 0, 1, 2, 1, 1, 1, 

              4, 1, 0, 0, 4, 0, 0, 2, 1, 1, 1, 1, 3, 0, 3, 1, 1, 0, 2, 1, 2, 

              0, 0, 0, 4, 0, 1, 2, 0, 3, 1, 1, 1, 4, 0, 1, 2, 0, 0, 2, 0, 2, 

              2, 2, 1, 1, 3, 3, 3, 2, 2, 0, 1, 3, 1, 3, 0, 4, 0, 3, 3, 0, 3, 

              3, 0, 4, 3, 3, 1, 3, 1, 3, 1, 4, 1, 1, 3, 3, 2, 3, 2, 0, 3, 1, 

              3, 2, 3, 3, 3, 1, 3, 1, 3, 4, 0, 3, 3, 0, 0, 3, 3, 2, 0, 1, 4, 

              1, 0, 1, 0, 0, 1, 1, 3, 3, 1, 3, 1, 0, 4, 1, 1, 1, 0, 3, 1, 1, 

              2, 3, 1, 4, 2, 3, 3, 4, 0, 3, 1, 0, 1, 1, 1, 1, 1, 3, 3, 1, 1, 

              3, 3, 3, 0, 1, 1, 4, 0, 2, 0, 2, 3, 1, 1, 1, 0, 1, 1, 1, 3, 1, 

              1, 1, 0, 3, 1, 4, 1, 1, 1, 3, 4, 1, 1, 1, 2, 3, 1, 1, 3, 1, 3, 

              1, 4, 3, 1, 1, 0, 4, 1, 4, 3, 3, 4, 4, 1, 2, 4, 3, 1, 0, 1, 2, 

              1, 1, 3, 3, 1, 0, 1, 0, 3, 1, 3, 2, 0, 3, 4, 4, 3, 4, 1, 4, 2, 

              3, 1, 2, 0, 2, 4, 1, 1, 1, 4, 1, 1, 4, 3, 3, 4, 1, 2, 2, 4, 3, 

              2, 3, 1, 2, 0, 4, 1, 1, 3, 1, 4, 2, 1, 2, 2, 1, 0, 4, 1, 1, 1, 

              2, 1, 2, 0, 2, 2, 2, 2, 0, 1, 3, 4, 1, 2, 1, 2, 1, 1, 3, 4, 2, 

              2, 2, 3, 0, 2, 3, 4, 1, 1, 3, 1, 0, 2, 1, 0, 2, 1, 1, 3, 3, 1, 

              2, 3, 0, 1, 0, 1, 2, 1, 3, 4, 1, 4, 2, 3, 4, 2, 2, 3, 4, 1, 1, 

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

              1, 1, 3, 1, 1, 4, 3, 3, 4, 3, 1, 0, 2, 1, 2, 1, 4, 1, 1, 1, 3, 

              0, 1, 1, 1, 2, 1, 4, 1, 4, 2, 2, 0, 3, 1, 4, 2, 0, 1, 4, 1, 1, 

              3, 4, 3, 0, 2, 3, 2, 0, 1, 1, 1, 0, 2, 4, 1, 3, 2, 1, 0, 2, 1, 

              1, 1, 1, 2, 3, 2, 3, 4, 0, 3, 1, 1, 3, 4, 2, 3, 1, 1, 1, 1, 0, 

              3, 3, 3, 3, 0, 3, 2, 3, 3, 0, 1, 4, 4, 1, 4, 0, 4), 

            .Dim = c(100L, 10L), 

            .Dimnames = list(NULL, c("Item_1", "Item_2", "Item_3", "Item_4", "Item_5", 

                                     "Item_6", "Item_7", "Item_8", "Item_9", "Item_10")))



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

log-sum-exp trick  (0) 2015.10.15
Against underflow  (0) 2015.10.10
Polychoric correlations  (2) 2015.09.22
rJava loading 문제  (0) 2015.05.17
training MNIST data with the package "deepnet"  (2) 2014.11.13
공지사항
최근에 올라온 글
최근에 달린 댓글
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
글 보관함