dummy_expand {lazy.tools} | R Documentation |
Dummmy Expantion of Categorical Data
dummy_expand(Uc, ncat = NULL, type = NULL, zero = 1)
Uc |
Item Response matrix in Compressed Format |
ncat |
a vector consisting of # of categories of each item |
type |
NOT used. |
zero |
= 0 to exclude the zero-th category from output |
In compressed format, Uc[i,j]=k means that subject i answers to item j
by selecting option k, k=0,1,...,ncat[j].
This function expands this compressed format to uncompressed
dummy expanded format:
That is, each item takes ncat[j] colums of U[, fromP[j]:toP[j]],
and the k+fromP[j]-th colum will be 1, and 0 elsewhere.
A list of
U, ncat, type, zero, fromP, toP
# generate item response # in uncompressed format # set.seed(1701) # res <- gendataIRT( 1, paramS1, npoints=7, thmin=-3, thmax=3 ) # U=res$U # in compressed format # set.seed(1701) # res1 <- gendataIRT( 1, paramS1, npoints=7, thmin=-3, thmax=3, compress=1 ) # Uc=res1$U # # uncompressed data: ncat=c(2,2,4) U <- " Q1_0 Q1_1 Q2_0 Q2_1 Q3_0 Q3_1 Q3_2 Q3_3 1 0 1 0 1 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 1 0 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 1 "; U=cards( U, header=1 ) # # compressed data: ncat=c(2,2,4) Uc <- " Q1 Q2 Q3 0 0 0 0 0 1 0 0 0 0 0 1 0 1 2 1 1 3 1 1 3 "; Uc=cards( Uc, header=1 ) # from compressed to uncompressed U1=dummy_expand(Uc)$U # back to compressed Uc1=dummy_compress(U)$Uc Print(U-U1) Print(Uc-Uc1) # zero=0 option U2=dummy_expand(Uc, zero=0)$U Uc2=dummy_compress(U2, zero=0, ncat=c(2,2,4))$Uc Print(Uc-Uc2)