Learn R Programming

CDM (version 8.2-6)

eval_likelihood: Evaluation of Likelihood

Description

The function eval_likelihood evaluates the likelihood given item responses and item response probabilities.

The function prep_data_long_format stores the matrix of item responses in a long format omitted all missing responses.

Usage

eval_likelihood(data, irfprob, prior=NULL, normalization=FALSE, N=NULL)

prep_data_long_format(data)

Value

Numeric matrix

Arguments

data

Dataset containing item responses in wide format or long format (generated by prep_data_long_format).

irfprob

Array containing item responses probabilities, format see IRT.irfprob

prior

Optional prior (matrix or vector)

normalization

Logical indicating whether posterior should be normalized

N

Number of persons (optional)

Examples

Run this code
if (FALSE) {
#############################################################################
# EXAMPLE 1: Likelihood data.ecpe
#############################################################################

data(data.ecpe, package="CDM")
dat <- data.ecpe$dat[,-1]
Q <- data.ecpe$q.matrix

#*** store data matrix in long format
data_long <- CDM::prep_data_long_format(data)
str(data_long)

#** estimate GDINA model
mod <- CDM::gdina(dat, q.matrix=Q)
summary(mod)

#** extract data, item response functions and prior
data <- CDM::IRT.data(mod)
irfprob <- CDM::IRT.irfprob(mod)
prob_theta <- attr( irfprob, "prob.theta")

#** compute likelihood
lmod <- CDM::eval_likelihood(data=data, irfprob=irfprob)
max( abs( lmod - CDM::IRT.likelihood(mod) ))

#** compute posterior
pmod <- CDM::eval_likelihood(data=data, irfprob=irfprob, prior=prob.theta,
            normalization=TRUE)
max( abs( pmod - CDM::IRT.posterior(mod) ))
}

Run the code above in your browser using DataLab