hltm2: Hierarchical Latent Trait Models with Known Item Parameters.

Description Usage Arguments Value Examples

View source: R/hltm2.R

Description

hltm2 fits a hierarchical latent trait model where the item parameters are known and supplied by the user.

Usage

1
hltm2(y, x = NULL, z = NULL, item_coefs, control = list())

Arguments

y

A data frame or matrix of item responses.

x

An optional model matrix, including the intercept term, that predicts the mean of the latent preference. If not supplied, only the intercept term is included.

z

An optional model matrix, including the intercept term, that predicts the variance of the latent preference. If not supplied, only the intercept term is included.

item_coefs

A list of known item parameters. The parameters of item j are given by the jth element, which should be a vector of length 2, containing the item difficulty parameter and item discrimination parameter.

control

A list of control values

max_iter

The maximum number of iterations of the EM algorithm. The default is 150.

eps

Tolerance parameter used to determine convergence of the EM algorithm. Specifically, iterations continue until the Euclidean distance between β_{n} and β_{n-1} falls under eps, where β is the vector of item discrimination parameters. eps=1e-4 by default.

max_iter2

The maximum number of iterations of the conditional maximization procedures for updating γ and λ. The default is 15.

eps2

Tolerance parameter used to determine convergence of the conditional maximization procedures for updating γ and λ. Specifically, iterations continue until the Euclidean distance between two consecutive log likelihoods falls under eps2. eps2=1e-3 by default.

K

Number of Gauss-Legendre quadrature points for the E-step. The default is 21.

C

[-C, C] sets the range of integral in the E-step. C=3 by default.

Value

An object of class hltm.

coefficients

A data frame of parameter estimates, standard errors, z values and p values.

scores

A data frame of EAP estimates of latent preferences and their approximate standard errors.

vcov

Variance-covariance matrix of parameter estimates.

log_Lik

The log-likelihood value at convergence.

N

Number of units.

J

Number of items.

H

A vector denoting the number of response categories for each item.

ylevels

A list showing the levels of the factorized response categories.

p

The number of predictors for the mean equation.

q

The number of predictors for the variance equation.

control

List of control values.

call

The matched call.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
y <- nes_econ2008[, -(1:3)]
x <- model.matrix( ~ party * educ, nes_econ2008)
z <- model.matrix( ~ party, nes_econ2008)
dichotomize <- function(x) findInterval(x, c(mean(x, na.rm = TRUE)))
y_bin <- y
y_bin[] <- lapply(y, dichotomize)

n <- nrow(nes_econ2008)
id_train <- sample.int(n, n/4)
id_test <- setdiff(1:n, id_train)

y_bin_train <- y_bin[id_train, ]
x_train <- x[id_train, ]
z_train <- z[id_train, ]

mod_train <- hltm(y_bin_train, x_train, z_train)

y_bin_test <- y_bin[id_test, ]
x_test <- x[id_test, ]
z_test <- z[id_test, ]

item_coefs <- lapply(coef_item(mod_train), `[[`, "Estimate")

model_test <- hltm2(y_bin_test, x_test, z_test, item_coefs = item_coefs)

xiangzhou09/hIRT documentation built on Dec. 25, 2021, 5:27 a.m.