0

I am new to R. I am using mirt package for polytomous data analysis.

I was doing the calibration for following sample data. First 5 items (v1 to v5)have 3 categories while last 5 items (v21 to v25) have 4 categories.

library(mirt)
r_data
   V1 V2 V3 V4 V5 V21 V22 V23 V24 V25
1   1  1  1  0  0   1   2   3   2   1
2   2  1  0  0  0   3   2   1   1   0
3   1  1  1  1  1   1   0   1   1   1
4   1  1  0  0  1   1   2   1   1   1
5   1  0  1  2  0   2   2   1   3   1
6   1  0  2  2  1   2   2   2   3   0
7   0  0  0  1  0   1   3   2   0   3
8   2  0  0  1  2   2   1   1   0   2
9   1  2  1  2  0   2   0   0   1   1
10  1  0  1  0  2   0   1   3   1   3
11  1  1  2  1  2   1   0   1   2   0
12  1  1  1  1  0   2   0   1   1   2
13  1  2  1  0  1   1   1   3   1   1
14  0  2  0  1  2   2   2   2   0   1
15  0  1  0  1  2   2   1   1   3   1
16  0  0  0  1  1   0   2   1   3   2
17  1  1  0  1  1   0   3   3   1   0
18  0  1  1  1  0   1   1   1   3   2
19  0  0  1  2  0   1   1   2   2   2
20  1  1  2  0  0   1   2   0   1   3

I applied

pars.1=mirt(r_data, 2, 'gpcm')
    Iteration: 380, Log-Lik: -214.027, Max-Change: 0.00009
    coef(pars.1)

and got

$V1
       a1     a2 ak0 ak1 ak2 d0    d1     d2
par -0.95 -1.049   0   1   2  0 1.101 -1.639

$V2
       a1     a2 ak0 ak1 ak2 d0    d1     d2
par -0.44 -0.576   0   1   2  0 0.493 -1.014

$V3
        a1    a2 ak0 ak1 ak2 d0    d1     d2
par -0.001 0.376   0   1   2  0 0.152 -1.047

$V4
        a1    a2 ak0 ak1 ak2 d0    d1     d2
par -0.834 2.405   0   1   2  0 1.652 -0.946

$V5
       a1     a2 ak0 ak1 ak2 d0     d1    d2
par 0.188 -0.225   0   1   2  0 -0.381 -0.62

$V21
        a1    a2 ak0 ak1 ak2 ak3 d0    d1    d2     d3
par -7.165 0.044   0   1   2   3  0 7.688 5.842 -6.525

$V22
      a1     a2 ak0 ak1 ak2 ak3 d0    d1    d2     d3
par 0.26 -0.133   0   1   2   3  0 0.478 0.759 -0.716

$V23
       a1     a2 ak0 ak1 ak2 ak3 d0   d1    d2    d3
par 0.639 -0.302   0   1   2   3  0 1.99 1.077 0.691

$V24
       a1    a2 ak0 ak1 ak2 ak3 d0    d1    d2    d3
par 0.122 0.828   0   1   2   3  0 1.573 0.471 0.505

$V25
       a1 a2 ak0 ak1 ak2 ak3 d0    d1    d2     d3
par 0.459  0   0   1   2   3  0 0.847 0.349 -0.369

$GroupPars
    MEAN_1 MEAN_2 COV_11 COV_21 COV_22
par      0      0      1      0      1

This list coef(pars.1) I need to convert to the matrix with column names as the parameters a1, a2, ak0, ak1, ak2, ak3, d0, d1, d2, d3.

How Can I do that?

p.s.

   t(sapply(coef(pars.1)[1:ncol(r_data)], '[', 1:max(sapply(coef(pars.1)[1:ncol(r_data)], length))))

above code is not working as the parameter values are getting mixed.

Thank you in advance.

Artiga
  • 776
  • 2
  • 16
  • 37
  • @Henrik, df <- data.frame(matrix(unlist(coef(pars.1)), nrow=10, byrow=T)) This is not helping. As it is throwing a warning message. as I mentioned in the question the values are not coming under the columns which they are suppose to, – Artiga Feb 12 '15 at 12:08
  • 1
    Sorry, my mistake. I was to quick when choosing the duplicate. It's should be a dupe of posts with e.g. `data.table::rbindlist`, `dplyr::bind_rows` or `plyr::rbind.fill.matrix`. – Henrik Feb 12 '15 at 12:16
  • Henrik, 'dplyr::bind_rows' was helpful. Thank you. :) – Artiga Feb 12 '15 at 12:26
  • Note that in `coef()` there is also a `simplify = TRUE` logical flag to do what you want here internally. – philchalmers Jun 11 '18 at 16:45

0 Answers0