tam.latreg {TAM} | R Documentation |
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=FALSE, beta.inits=NULL, variance.fixed=NULL,
variance.inits=NULL, est.variance=TRUE, pweights=NULL, pid=NULL,
userfct.variance=NULL, variance.Npars=NULL, verbose=TRUE, control=list())
## S3 method for class 'tam.latreg'
summary(object,file=NULL,...)
## S3 method for class 'tam.latreg'
print(x,...)
Arguments
like |
Individual likelihood. This can be typically extracted from fitted
item response models by making use of |
theta |
Used |
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 R formula for latent regression. Transformations of predictors
in |
dataY |
An optional data frame with possible covariates |
beta.fixed |
A matrix with three columns for fixing regression coefficients.
1st column: Index of |
beta.inits |
A matrix (same format as in |
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
|
est.variance |
Should the covariance matrix be estimated? This argument
applies to estimated item slopes in |
pweights |
An optional vector of person weights |
pid |
An optional vector of person identifiers |
userfct.variance |
Optional user customized function for variance specification (See Simulated Example 17). |
variance.Npars |
Number of estimated parameters of variance matrix
if a |
verbose |
Optional logical indicating whether iteration should be displayed. |
control |
List of control parameters, see |
object |
Object of class |
file |
A file name in which the summary output will be written |
x |
Object of class |
... |
Further arguments to be passed |
Value
Subset of values of tam.mml
. In addition,
means (M_post
) and standard deviations (SD_post
) are computed.
See Also
See also tam.pv
for plausible value imputation.
Examples
## Not run:
#############################################################################
# EXAMPLE 1: Unidimensional latent regression model with fitted IRT model in
# the 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::tam.latreg( like1, theta=attr(like1, "theta"), Y=Y, pid=dat$idstud )
summary(mod2)
# plausible value imputation
pv2 <- TAM::tam.pv( mod2 )
# create list of imputed datasets
Y <- dat[, c("idstud", "idschool", "female", "hisei", "migra") ]
pvnames <- c("PVREAD")
datlist <- TAM::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, stats::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::tam.latreg( like, Y=X, pid=dat$idstud )
summary(mod2)
# plausible value imputation
pv2 <- TAM::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 <- TAM::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 <- TAM::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 <- TAM::IRTLikelihood.cfa( dat, mod1 )
str(like1)
# fit latent regression model in TAM
X <- dat[, c("urban","female") ]
mod2 <- TAM::tam.latreg( like1, Y=X )
summary(mod2)
# plausible value imputation
pv2 <- TAM::tam.pv( mod2, samp.regr=TRUE, normal.approx=TRUE )
# create list of imputed datasets
Y <- dat[, c("urban", "female" ) ]
pvnames <- c("PVSC", "PVMJ")
datlist <- TAM::tampv2datalist( pv2, pvnames=pvnames, Y=Y )
str(datlist)
## End(Not run)