Я нашел решение, используя пакет ltm
, вот код:
set.seed(123877)
u.latent <- vector()
class(u.latent) <- 'try-error'
library('ltm')
while (class(u.latent)=='try-error') {
# numer of units
n <- 1000L
# age
age <- round(rnorm(n, 25, 10))
# cum laude
hon <- sample(0L:1L, n, TRUE, prob = c(.9, .1) )
# prestige of university
pres <- sample(1L:10L, n, TRUE)
# pres <-factor(pres, levels = 1L:25L, ordered = TRUE)
dat <- data.frame(age, hon, pres)
# latent variable
u.latent <- try(gpcm(dat))
}
Мы можем проверить, соответствует ли модель данным:
GoF.gpcm(u.latent)
#H0 the model fits the data
#Ha: the model does not fit the data
Оценкииз скрытых переменных прямо вперед:
u.estimates <-factor.scores(u.latent)
hist(u.estimates$score.dat$z1)