Learn R Programming

nlsem (version 0.8-1)

em: Maximum likelihood estimation of structural equation mixture models

Description

Fits a structural equation model with latent interaction effects using mixture approaches (LMS, SEMM, NSEMM).

Usage

em(model, data, start, qml = FALSE, verbose = FALSE, convergence = 1e-02,
     max.iter = 100, m = 16, optimizer = c("nlminb", "optim"),
     max.mstep = 1, max.singleClass = 1, neg.hessian = TRUE, ...)

Value

An object of class emEst that consists of the following components:

model.class

class of model that was fitted, can be singleClass, semm, or nsemm.

coefficients

estimated parameters.

objective

final loglikelihood obtained with EM algorithm.

em_convergence

yes or no. Did EM algorithm converge?

Hessian

Hessian matrix for final parameter estimation.

loglikelihoods

loglikelihoods obtained during each iteration of EM algorithm.

info

list of number of exogenous (num.xi) and endogenous (num.eta) variables and of indicators (num.x and num.y). Corresponds to specifications given to specify_sem when specifiying structural equation model.

Arguments

model

a specified structural equation model of class singleClass, semm, or nsemm.

data

the data the model should be fitted to. Data needs to be a matrix and variables need to be in the order x1, x2, ..., y1, y2, ... as specified in specify_sem. Data matrix needs no column names (will be ignored anyways).

start

starting values for parameters.

qml

logical. Indicating if QML estimation should be used instead of LMS for estimation of nonlinear effects. Defaults to FALSE. QML is much faster, though.

verbose

if output of EM algorithm should be shown during fitting.

convergence

convergence threshold.

max.iter

maximum number of iterations before EM algorithm stops.

m

number of nodes for Hermite-Gaussian quadrature. Defaults to 16. See Datails.

optimizer

which optimizer should be used in maximization step of EM algorithm: nlminb or optim.

max.mstep

maximum iteration steps the optimizer should use in its mstep during one EM iteration. Defaults to 1.

max.singleClass

maximum iteration steps for singleClass model inside of NSEMM model. Defaults to 1 (and should only be changed for valid reasons).

neg.hessian

should negative Hessian be calculated in last step of iteration.

...

additional arguments. See Details.

Details

em can be used to estimate parameters for structural equation mixture models with latent interaction effects with an EM algorithm. The maximization step of the EM algorithm can use two different optimizers: optim or nlminb. Default is nlminb.

Additional arguments can be passed to ... for these optimizers. See documentation for optim and nlminb.

The LMS approach (Klein & Moosbrugger, 2000) uses Hermite-Gauss quadrature for numerical approximation. The nodes used in this approximation need to be prespecified by the user. The more nodes are used the better the numerical approximation but also the slower the calculations.

References

Jedidi, K., Jagpal, H. S., & DeSarbo, W. S. (1997). STEMM: A General Finite Mixture Structural Equation Model, Journal of Classification, 14, 23--50. doi:http://dx.doi.org/10.1007/s003579900002

Kelava, A., Nagengast, B., & Brandt, H. (2014). A nonlinear structural equation mixture modeling approach for non-normally distributed latent predictor variables. Structural Equation Modeling, 21, 468-481. doi:http://dx.doi.org/10.1080/10705511.2014.915379

Klein, A. &, Moosbrugger, H. (2000). Maximum likelihood estimation of latent interaction effects with the LMS method. Psychometrika, 65, 457--474. doi:http://dx.doi.org/10.1007/bf02296338

See Also

specify_sem

Examples

Run this code

###### Example for SEMM ######
# load data
data("PoliticalDemocracy", package = "lavaan")
dat <- as.matrix(PoliticalDemocracy[ ,c(9:11,1:8)])

# specify model of class SEMM
model <- specify_sem(num.x = 3, num.y = 8, num.xi = 1, num.eta = 2, 
  xi = "x1-x3", eta = "y1-y4,y5-y8", rel.lat = "eta1~xi1,eta2~xi1,eta2~eta1",
  num.classes = 2, constraints = "direct1")

# fit model
set.seed(911)
start <- runif(count_free_parameters(model))
if (FALSE) {
res <- em(model, dat, start, convergence = 0.1, max.iter = 200)
summary(res)
plot(res)
}

###### Example for LMS ######
model <- specify_sem(num.x = 11, num.y = 4, num.xi = 2, num.eta = 1,
  xi = "x1-x5,x6-x11", eta = "y1-y4", interaction = "eta1~xi1:xi2")

data("jordan")

set.seed(110)
start <- runif(count_free_parameters(model))
if (FALSE) {
res <- em(model, jordan, start, convergence=1, verbose=TRUE)
summary(res)
plot(res)
}

###### Example using lavaan syntax ######
lav.model <- '
  eta =~ y1 + y2 + y3 + y4
  xi1 =~ x1 + x2 + x3 + x4 + x5
  xi2 =~ x6 + x7 + x8 + x9 + x10 + x11

  eta ~ xi1 + xi2 + xi1:xi2 + xi1:xi1'

model <- lav2nlsem(lav.model)

data("jordan")

set.seed(1118)
start <- runif(count_free_parameters(model))
if (FALSE) {
res <- em(model, jordan, start, convergence=1, verbose=TRUE)
}

Run the code above in your browser using DataLab