Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

IRTLikelihood.cfa

Individual Likelihood for Confirmatory Factor Analysis


Description

This function computes the individual likelihood evaluated at a theta grid for confirmatory factor analysis under the normality assumption of residuals. Either the item parameters (item loadings L, item intercepts nu and residual covariances psi) or a fitted cfa object from the lavaan package can be provided. The individual likelihood can be used for drawing plausible values.

Usage

IRTLikelihood.cfa(data, cfaobj=NULL, theta=NULL, L=NULL, nu=NULL,
    psi=NULL, snodes=NULL, snodes.adj=2, version=1)

Arguments

data

Dataset with item responses

cfaobj

Fitted lavaan::cfa (lavaan) object

theta

Optional matrix containing the theta values used for evaluating the individual likelihood

L

Matrix of item loadings (if cfaobj is not provided)

nu

Vector of item intercepts (if cfaobj is not provided)

psi

Matrix with residual covariances (if cfaobj is not provided)

snodes

Number of theta values used for the approximation of the distribution of latent variables.

snodes.adj

Adjustment factor for quasi monte carlo nodes for more than two latent variables.

version

Function version. version=1 is based on a Rcpp implementation while version=0 is a pure R implementation.

Value

Individual likelihood evaluated at theta

See Also

Examples

## Not run: 
#############################################################################
# EXAMPLE 1: Two-dimensional CFA data.Students
#############################################################################

library(lavaan)
library(CDM)

data(data.Students, package="CDM")
dat <- data.Students

dat2 <- dat[, c(paste0("mj",1:4), paste0("sc",1:4)) ]
# lavaan model with DO operator
lavmodel <- "
DO(1,4,1)
   mj=~ mj%
   sc=~ sc%
DOEND
   mj ~~ sc
   mj ~~ 1*mj
   sc ~~ 1*sc
     "
lavmodel <- TAM::lavaanify.IRT( lavmodel, data=dat2 )$lavaan.syntax
cat(lavmodel)

mod4 <- lavaan::cfa( lavmodel, data=dat2, std.lv=TRUE )
summary(mod4, standardized=TRUE, rsquare=TRUE )
# extract item parameters
res4 <- TAM::cfa.extract.itempars( mod4 )
# create theta grid
theta0 <- seq( -6, 6, len=15)
theta <- expand.grid( theta0, theta0 )
L <- res4$L
nu <- res4$nu
psi <- res4$psi
data <- dat2
# evaluate likelihood using item parameters
like2 <- TAM::IRTLikelihood.cfa( data=dat2, theta=theta, L=L, nu=nu, psi=psi )
# The likelihood can also be obtained by direct evaluation
# of the fitted cfa object "mod4"
like4 <- TAM::IRTLikelihood.cfa( data=dat2, cfaobj=mod4 )
attr( like4, "theta")
# the theta grid is automatically created if theta is not
# supplied as an argument

## End(Not run)

TAM

Test Analysis Modules

v3.6-45
GPL (>= 2)
Authors
Alexander Robitzsch [aut,cre] (<https://orcid.org/0000-0002-8226-3132>), Thomas Kiefer [aut], Margaret Wu [aut]
Initial release
2021-04-22 14:35:52

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.