티스토리 뷰

차기작 : R을 배우자

fitting RSM

quantlab 2016. 1. 30. 22:15

RSM은 library mirt로 적합할 수 없다. 내가 하나 만들까 했는데 library TAM으로 가능하다. 추정방법도 MML으로 mirt와 동일하다.

RSM(Rating Scale Model) can not be fitted through library mirt. So I considered implementing it in the library myself but library TAM already implemented it. The estimation method is MML, the same as mirt.


mirt의 simdata를 활용하여 data를 생성한 후, TAM으로 적합하려 했는데, mirt와 TAM은 계수 표현 방법이 살짝 다르다.

For testing, I thought of generating response data with mirt::simdata and fitting RSM with TAM but mirt and TAM have different way of expressing coefficients.


좀 살펴보면 비교할 수 있겠지만, 귀찮다. 사실 나이가 들어갈 수록 뭐든지 귀찮고, 그냥 누구에게 물어보고 싶다.

I would eventually figure out how to convert ones to the others but it's kinda bothering and wasting my brain power. So I wanted to ask someone.


그래서 물어봤는데, 별로 도움이 되지 않았다. 

https://groups.google.com/forum/#!topic/mirt-package/bBVAwLfQ8SM

So I asked, but it was not so useful or I didn't understand it. Either way it's again bothering.


그래서 그냥 data 생성 함수를 만들었다. 이런 건 실수하지 않도록 해야 한다. 그뿐이다.

So I just created data-generating function. This kinda of task is very prone to mistakes. But that's all about it.


TAM을 돌려보니 item 추정이 얼추 비슷하게 된다. TAM에서 tau가 모두 합해서 0이 되도록 하기 때문에 마지막 반응 범주의 역치는 나타나지 않는다. 

(사실 이것때문에 또 한 30분 동안 고민했다.)

I ran tam.mml and the estimation is satisfactory. Taus in TAM for an item sums to 0. I didn't know it so I kinda wandered for about 30 mins.


또 다른 방법은 mixRasch 패키지를 이용하는 것이다. 여기서 주의할 점은 matrix를 입력할 때 colnames를 꼭 지정해 줘야 한다. 

Another option is to use mixRasch. One thing to be taken care of is that colnames should not be NULL for the matrix you give to mixRasch.


mixRasch의 단점은 1차원의 잠재변수만을 다룰 수 있다는 것이다.

mixRasch can only fit 1-dimensional model.


#install.packages("mirt")

rm(list=ls())


library(sirt)

library(TAM)


matR.RSM=function(th, ds) {

  stopifnot(is.vector(th))

  stopifnot(is.matrix(ds))

  apply(ds, 1, function(d) {generateR.RSM(th, d)}) }


generateR.RSM = function(th, d) {

  

  P1 <- outer(th, d, FUN = "-" )

  P2 <- t(apply(P1, 1, cumsum))

  P3 <- cbind(1, exp(P2))

  P3.sum <- apply(P3, 1, sum)

  P4 <- sweep(P3, 1, P3.sum, "/")

  #round(P4, 02)

  P5 <- t(apply(P4, 1, cumsum))

  #round(P5, 02)

  

  ranN <- runif(length(th), 0, 1)

  R1 <- sweep(P5, 1, ranN, function(x, y) { x>y })

  R2 <- apply(R1, 1, function(x) min(which(x)))

  R2 - 1 # 0 - n.cat-1 

}



n.item = 10;

delta = c(3, 2, 1, 0, 1, -1, -2, 1, -1, 0); # difficulties

tau = c(-2, -1, 0, 1, 2); #threshold


tau.rstrc <- tau - mean(tau)


th <- rnorm(1000, 0, 1)

ds <- outer(delta, tau, "+")


R <- matR.RSM(th, ds)


mod1a <- TAM::tam.mml( resp=R, control=list(maxiter=5000, progress=F, nodes=seq(-6,6,len=61),

                                              convD = .0001), irtmodel="RSM" )


tam2mirt(mod1a) # I told you, mirt doesn't support RSM


mod1a$xsi # COMPARE Cat1$xsi~Cat4$xsi WITH tau.rstrc


summary(mod1a$xsi)


mR1 <- mixRasch(R, max.iter=1000, steps=5, maxrange = c(-6,6), model="RSM", n.c=1)

summary(mR1)







공지사항
최근에 올라온 글
최근에 달린 댓글
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
글 보관함