Skip to contents

Computes the maximum a posteriori (MAP), also called empirical Bayes modal (EBM), estimate of latent traits for one binary / ordinal response pattern under a Thurstonian IRT parameterization.

Missing responses are allowed and are ignored in the likelihood.

Usage

score_tirt_pattern(
  pattern,
  lambda,
  theta_diag,
  tau,
  Psi,
  nu = NULL,
  init = NULL,
  control = list()
)

Arguments

pattern

Numeric vector of observed responses for one person, typically coded 0/1, with optional NA values for missing responses. Its order must match the row order of lambda (or be pre-aligned before calling).

lambda

Matrix of factor loadings with rows as observed indicators and columns as latent traits.

theta_diag

Numeric vector of residual variances (diagonal of theta), aligned to rows of lambda.

tau

Numeric vector of thresholds, aligned to rows of lambda.

Psi

Latent covariance matrix (traits x traits), positive definite.

nu

Optional numeric vector of indicator intercepts aligned to rows of lambda. If NULL, a zero vector is used.

init

Optional numeric vector of starting values for optimization. If NULL, starts at zeros.

control

Named list of control arguments passed to optim, merged with defaults reltol = 1e-10 and maxit = 500.

Value

Named numeric vector of latent trait MAP estimates, with names taken from colnames(lambda).

Details

The function maximizes the posterior: likelihood from a probit measurement model plus a multivariate normal prior on traits with covariance Psi. Optimization uses BFGS via optim with an analytic gradient.

Examples

library(thurstonianIRT)
data("triplets")
# define the blocks of items
blocks <-
  set_block(c("i1", "i2", "i3"), traits = c("t1", "t2", "t3"),
            signs = c(1, 1, 1)) +
  set_block(c("i4", "i5", "i6"), traits = c("t1", "t2", "t3"),
            signs = c(-1, 1, 1)) +
  set_block(c("i7", "i8", "i9"), traits = c("t1", "t2", "t3"),
            signs = c(1, 1, -1)) +
  set_block(c("i10", "i11", "i12"), traits = c("t1", "t2", "t3"),
            signs = c(1, -1, 1))
# generate the data to be understood by 'thurstonianIRT'
triplets_long <- make_TIRT_data(
  data = triplets, blocks = blocks, direction = "larger",
  format = "pairwise", family = "bernoulli", range = c(0, 1)
)
# fit the data using lavaan
fit <- fit_TIRT_lavaan(triplets_long)
pars <- extract_tirt_params(fit)
pattern<-as.numeric(triplets[1,])
score_tirt_pattern(pattern,lambda=pars$lambda,theta_diag=pars$theta_diag,
                   tau=pars$tau,Psi=pars$Psi,nu=NULL,init=NULL,
                   control=list())
#>   trait1   trait2   trait3 
#> -0.25847  0.09162 -0.65732