> library(mirt)
>
> #trace function for all items
> Probtrace <- function(items, Theta){
+ traces <- lapply(items, probtrace, Theta=Theta)
+ ret <- do.call(cbind, traces)
+ ret
+ }
>
> dat <- simdata(a=matrix(1,10), d=matrix(rnorm(10)), 1000, itemtype = 'dich')
> mod <- mirt(dat, 1, TOL = NaN)
>
> #structured data
> fulldata <- mod@Data$fulldata[[1L]]
> head(fulldata)
Item.1_1 Item.1_2 Item.2_1 Item.2_2 Item.3_1 Item.3_2 Item.4_1 Item.4_2 Item.5_1 Item.5_2
[1,] 1 0 1 0 1 0 1 0 1 0
[2,] 1 0 1 0 1 0 1 0 1 0
[3,] 1 0 1 0 0 1 1 0 1 0
[4,] 0 1 1 0 1 0 0 1 0 1
[5,] 0 1 0 1 0 1 0 1 0 1
[6,] 0 1 0 1 0 1 1 0 1 0
Item.6_1 Item.6_2 Item.7_1 Item.7_2 Item.8_1 Item.8_2 Item.9_1 Item.9_2 Item.10_1 Item.10_2
[1,] 1 0 1 0 0 1 0 1 1 0
[2,] 1 0 0 1 1 0 1 0 1 0
[3,] 1 0 1 0 1 0 1 0 1 0
[4,] 1 0 1 0 0 1 0 1 1 0
[5,] 1 0 1 0 0 1 0 1 0 1
[6,] 1 0 1 0 1 0 1 0 1 0
> head(dat) #compare
Item_1 Item_2 Item_3 Item_4 Item_5 Item_6 Item_7 Item_8 Item_9 Item_10
[1,] 0 0 0 0 0 0 0 1 1 0
[2,] 0 0 0 0 0 0r 1 0 0 0
[3,] 0 0 1 0 0 0 0 0 0 0
[4,] 1 0 0 1 1 0 0 1 1 0
[5,] 1 1 1 1 1 0 0 1 1 1
[6,] 1 1 1 0 0 0 0 0 0 0
>
> #latent scores
> Theta <- matrix(rnorm(nrow(fulldata)))
>
> #load items
> items <- vector('list', 10)
> for(i in 1:10) items[[i]] <- extract.item(mod, i)
>
> #compute log-like for each Theta
> traces <- Probtrace(items, Theta)
> LL <- rowSums(fulldata * log(traces))
> head(LL)
[1] -4.583083 -10.374255 -4.151897 -7.632804 -7.052407 -6.571110
>
> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C LC_TIME=en_CA.UTF-8
[4] LC_COLLATE=en_CA.UTF-8 LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_CA.UTF-8
[7] LC_PAPER=en_CA.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats4 stats graphics grDevices utils datasets methods base
other attached packages:
[1] mirt_1.4.2 lattice_0.20-29
loaded via a namespace (and not attached):
[1] GPArotation_2012.3-1 grid_3.1.0 Rcpp_0.11.2 RCurl_1.95-4.1
[5] tools_3.1.0