# NOT RUN {
data(LSAT7)
head(LSAT7) # frequency in right-most column
LSAT7full <- expand.table(LSAT7)
head(LSAT7full)
dim(LSAT7full)
# randomly switch rows in the expanded response table
LSAT7samp <- expand.table(LSAT7, sample = TRUE)
head(LSAT7samp)
colMeans(LSAT7full)
colMeans(LSAT7samp) #equal
#--------
# }
# NOT RUN {
# Generate data from separate response pattern matrix and freq vector
# The following uses Table 2.1 from de Ayala (2009)
f <- c(691,2280,242,235,158,184,1685,1053,134,462,92,65,571,79,87,41,1682,702,
370,63,626,412,166,52,28,15,2095,1219,500,187,40,3385)
pat <- matrix(c(
0, 0, 0, 0, 0,
1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0,
0, 0, 0, 0, 1,
1, 1, 0, 0, 0,
1, 0, 1, 0, 0,
0, 1, 1, 0, 0,
1, 0, 0, 1, 0,
0, 1, 0, 1, 0,
0, 0, 1, 1, 0,
1, 0, 0, 0, 1,
0, 1, 0, 0, 1,
0, 0, 1, 0, 1,
0, 0, 0, 1, 1,
1, 1, 1, 0, 0,
1, 1, 0, 1, 0,
1, 0, 1, 1, 0,
0, 1, 1, 1, 0,
1, 1, 0, 0, 1,
1, 0, 1, 0, 1,
1, 0, 0, 1, 1,
0, 1, 1, 0, 1,
0, 1, 0, 1, 1,
0, 0, 1, 1, 1,
1, 1, 1, 1, 0,
1, 1, 1, 0, 1,
1, 1, 0, 1, 1,
1, 0, 1, 1, 1,
0, 1, 1, 1, 1,
1, 1, 1, 1, 1), ncol=5, byrow=TRUE)
colnames(pat) <- paste0('Item.', 1:5)
head(pat)
table2.1 <- expand.table(pat, freq = f)
dim(table2.1)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab