Learn R Programming

TAM (version 1.6-0)

tam.latreg: Latent Regression Model

Description

This function fits a latent regression model $\bold{\theta} = \bold{Y} \bold{\beta} + \bold{\varepsilon}$. Only the individual likelihood evaluated at a $\bold{\theta}$ grid is needed as the input. Like in tam.mml a multivariate normal distribution is posed on the residual distribution. Plausible values can be drawn by subsequent application of tam.pv (see Example 1).

Usage

tam.latreg(like, theta=NULL, Y = NULL, group = NULL, formulaY = NULL, dataY = NULL, 
   beta.fixed = NULL, beta.inits = NULL, variance.fixed = NULL, 
   variance.inits = NULL, est.variance = TRUE, pweights = NULL, pid = NULL, 
   userfct.variance = NULL, variance.Npars = NULL, control = list())
   
## S3 method for class 'tam.latreg':
summary(object,file=NULL,\dots)

Arguments

like
Individual likelihood. This can be typically extracted from fitted item response models by making use of IRT.likelihood.
theta
Used $\bold{\theta}$ grid in the fitted IRT model. If like is generated by the IRT.likelihood function, then theta is automatically extracted as an attribute.
Y
A matrix of covariates in latent regression. Note that the intercept is automatically included as the first predictor.
group
An optional vector of group identifiers
formulaY
An Rformula for latent regression. Transformations of predictors in $Y$ (included in dataY) can be easily spcified, e. g. female*race or I(age^2).
dataY
An optional data frame with possible covariates $Y$ in latent regression. This data frame will be used if an Rformula in formulaY is specified.
beta.fixed
A matrix with three columns for fixing regression coefficients. 1st column: Index of $Y$ value, 2nd column: dimension, 3rd column: fixed $\beta$ value. If no constraints should be inposed on $\beta$, then set beta.fixed=FALSE
beta.inits
A matrix (same format as in beta.fixed) with initial $\beta$ values
variance.fixed
An optional matrix with three columns for fixing entries in covariance matrix: 1st column: dimension 1, 2nd column: dimension 2, 3rd column: fixed value
variance.inits
Initial covariance matrix in estimation. All matrix entries have to be specified and this matrix is NOT in the same format like variance.inits.
est.variance
Should the covariance matrix be estimated? This argument applies to estimated item slopes in tam.mml.2pl. The default is FALSE which means that latent variables (in the first group) are standardized in 2PL estim
pweights
An optional vector of person weights
pid
An optional vector of person identifiers
userfct.variance
Optional user customized function for variance speicification (See Simulated Example 17).
variance.Npars
Number of estimated parameters of variance matrix if a userfct.variance is provided.
control
List of control parameters, see tam.mml.
object
Object of class tam.latreg
file
A file name in which the summary output will be written
...
Further arguments to be passed

Value

See Also

See also tam.pv for plausible value imputation.

Examples

Run this code
#############################################################################
# EXAMPLE 1: Unidimensional latent regression model with fitted IRT model in
#            sirt package
#############################################################################

library(sirt)
data(data.pisaRead, package="sirt")
dat <- data.pisaRead$data

items <- grep("R4" , colnames(dat) , value=TRUE )    # select test items from data
# define testlets
testlets <- substring( items , 1 , 4 )
itemcluster <- match( testlets , unique(testlets) )
# fit Rasch copula model (only few iterations)
mod <- sirt::rasch.copula2( dat[,items] , itemcluster=itemcluster , mmliter=5)
# extract individual likelihood
like1 <- IRT.likelihood( mod )
# fit latent regression model in TAM
Y <- dat[ , c("migra" , "hisei", "female") ]
mod2 <- tam.latreg( like1 , theta=attr(like1, "theta") , Y = Y , pid=dat$idstud )
summary(mod2)
# plausible value imputation
pv2 <- tam.pv( mod2 ) 
# create list of imputed datasets
Y <- dat[ , c("idstud" , "idschool" , "female" , "hisei" , "migra") ]
pvnames <- c("PVREAD")
datlist <- tampv2datalist( pv2, pvnames = pvnames , Y=Y , Y.pid="idstud")

#--- fit some models
library(mice)
library(miceadds)
# convert data list into a mice object
mids1 <- miceadds::datalist2mids( datlist )
# perform an ANOVA
mod3a <- with( mids1 , lm(PVREAD ~ hisei*migra) )
summary( pool( mod3a ))
mod3b <- miceadds::mi.anova( mids1 , "PVREAD ~ hisei*migra" )

#############################################################################
# EXAMPLE 2: data.pisaRead - fitted IRT model in mirt package
#############################################################################

library(sirt)
library(mirt)

data(data.pisaRead, package="sirt")
dat <- data.pisaRead$data

# define dataset with item responses
items <- grep("R4" , colnames(dat) , value=TRUE )
resp <- dat[,items]
# define dataset with covariates
X <- dat[ , c("female","hisei","migra") ]

# fit 2PL model in mirt
mod <- mirt::mirt( resp , 1 , itemtype="2PL" , verbose=TRUE)
print(mod)
# extract coefficients
sirt::mirt.wrapper.coef(mod)

# extract likelihood
like <- IRT.likelihood(mod)
str(like)

# fit latent regression model in TAM
mod2 <- tam.latreg( like , Y = X , pid=dat$idstud )
summary(mod2)
# plausible value imputation
pv2 <- tam.pv( mod2 , samp.regr=TRUE , nplausible=5 ) 
# create list of imputed datasets
X <- dat[ , c("idstud" , "idschool" , "female" , "hisei" , "migra") ]
pvnames <- c("PVREAD")
datlist <- tampv2datalist( pv2, pvnames = pvnames , Y=X , Y.pid="idstud")
str(datlist)

# regression using semTools package
library(semTools)
lavmodel <- "
   PVREAD ~ hisei + female
           "                           
mod1a <- semTools::sem.mi( lavmodel , datlist)
summary(mod1a , standardized=TRUE, rsquare=TRUE)

#############################################################################
# EXAMPLE 3: data.Students - fitted confirmatory factor analysis in lavaan
#############################################################################

library(CDM)
library(sirt)
library(lavaan)

data(data.Students, package="CDM")
dat <- data.Students
vars <- scan(what="character" , nlines=1)
   urban female sc1 sc2 sc3 sc4 mj1 mj2 mj3 mj4
dat <- dat[ , vars]
dat <- na.omit(dat)

# fit confirmatory factor analysis in lavaan
lavmodel <- "
   SC =~ sc1__sc4
   SC ~~ 1*SC
   MJ =~ mj1__mj4
   MJ ~~ 1*MJ
   SC ~~ MJ
        "        
# process lavaan syntax
res <- sirt::lavaanify.IRT( lavmodel , dat )        
# fit lavaan CFA model                        
mod1 <- lavaan::cfa( res$lavaan.syntax , dat , std.lv=TRUE)
summary(mod1 , standardized=TRUE , fit.measures=TRUE )
# extract likelihood
like1 <- IRTLikelihood.cfa( dat , mod1 )
str(like1)
# fit latent regression model in TAM
X <- dat[ , c("urban","female") ]
mod2 <- tam.latreg( like1 , Y = X  )
summary(mod2)
# plausible value imputation
pv2 <- tam.pv( mod2 , samp.regr=TRUE , normal.approx=TRUE ) 
# create list of imputed datasets
Y <- dat[ , c("urban" , "female" ) ]
pvnames <- c("PVSC" , "PVMJ")
datlist <- tampv2datalist( pv2, pvnames = pvnames , Y=Y )
str(datlist)

Run the code above in your browser using DataLab