Specify a structural equation model with constraints.

1 2 3 | ```
specify_sem(num.x, num.y, num.xi, num.eta, xi, eta,
constraints = c("indirect", "direct1", "direct2"),
num.classes = 1, rel.lat = "default", interaction = "none")
``` |

`num.x` |
number of observed variables for xi. |

`num.y` |
number of observed variables for eta. |

`num.xi` |
number of latent exogenous variabeles. |

`num.eta` |
number of latent endognous variables. |

`xi` |
which observed variables are indicators for which exogenous variable. See Details. |

`eta` |
which observed variables are indicators for which endogenous variable. See Details. |

`constraints` |
which should be set for a model with more than one latent class. See Details. |

`num.classes` |
number of latent classes. |

`interaction` |
define which interaction terms should be included. Default is ‘none’. See Details for how to enter interaction terms. |

`rel.lat` |
define relations between latent variables. Influences Beta and Gamma matrices. For ‘defaults’ and how to define see Details. |

The notation for the `matrices`

given back by `specify_sem`

follows typical notation used in structural equation modeling. The
notation, of course, may vary dependingly. Therefore, here are examples
for typical structural equation models with the notation used by
`specify_sem`

(in matrix notation):

Structural model for LMS, QML (nonlinear SEM), and NSEMM (nonlinear SEM with latent classes):

*
eta = alpha + Gamma xi + xi' Omega xi + zeta*

Structural model for SEMM (linear SEM with latent classes):

*
B eta = alpha + Gamma xi + zeta*

Measurement model:

*
x = nu_x + lambda_x xi + delta*

*
y = nu_y + lambda_y eta + epsilon*

Which indicators belong to which latent variable is defined by
`xi`

and `eta`

. Must be specified in the following way:
`xi='x1-x2,x3-x4'`

which means that variables `x1, x2`

are
indicators for `xi1`

and `x3, x4`

are indicators for
`xi2`

. And accordingly for the endogenous variables `eta`

.

Interactions between latent exogenous variables are defined by

`interaction='eta1~xi1:xi2,eta1~xi1:xi1'`

. It is important to note,
that interactions must always start with `xi1`

and build from there.
A definition like `interaction='eta1~xi1:xi2,eta1~xi2:xi3'`

is not
feasible and must be changed to
`interaction='eta1~xi1:xi2,eta1~xi1:xi3'`

(by simple switching
`xi1`

and `xi2`

in one's definitions). `interaction`

fills
the *Omega* matrix (see above) and must always be a
triangular matrix where the lower triangle is filled with 0's (see Klein
& Moosbrugger, 2000, for details).

`rel.lat`

defines which latent variables influence each
other. It must be defined like

`rel.lat='eta1~xi1+xi2,eta2~eta1'`

. Free parameters will be
set accordingly in *Beta* and *Gamma*
matrices. When nothing is defined, *Gamma* defaults to
all `NA`

s (which means all *xi*'s influence all
*eta*'s) and *Beta* is an identity matrix.

Structural equation models with latent classes like SEMM and NSEMM can be
used in two different approaches usually called direct and indirect. When
constraints are set to `indirect`

then parameters for the latent
classes are constraint to be equal except for the parameters for the
mixture distributions (*tau*'s and *Phi*). In a
direct approach, parameters for the latent classes are estimated
independently. For `direct1`

all parameters will be estimated
independently for each latent class. For `direct2`

it is assumed
that the measurement model is equal for both groups and only the
parameters for the mixtures and the structural model are estimated
separately.

An object of class `singleClass`

, `semm`

, or `nsemm`

which can be used to estimate parameters using `em`

that
consists of the following components:

`matrices` |
list of matrices specifying the structural equation model. |

`info` |
list of informations about structural equation model. |

Jedidi, K., Jagpal, H. S., & DeSarbo, W. S. (1997). STEMM: A General
Finite Mixture Structural Equation Model, *Journal of
Classification, 14*, 23–50.

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.

Klein, A. &, Moosbrugger, H. (2000). Maximum likelihood estimation of
latent interaction effects with the LMS method. *Psychometrika, 65*,
457–474.

Klein, A. &, Muthen, B. O. (2007). Quasi-Maximum Likelihood Estimation of
Structural Equation Models With Multiple Interaction and Quadratic
Effects. *Multivariate Behavior Research, 42*, 647–673.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ```
# with default constraints
model <- specify_sem(num.x = 6, num.y = 3, num.xi = 2, num.eta = 1,
xi = "x1-x3,x4-x6", eta = "y1-y3")
# create data frame
specs <- as.data.frame(model)
# and add custom constraints
constr <- c(1, NA, NA, 0, 0, 0, 0, 0, 0, 1, NA, NA, 1, NA, NA, NA, NA, 1, NA,
0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0,
0, 0, 0, NA, 0, 0, 0, 0, 0, 0, NA, NA, 0, 0, 0, NA, 0, 0, 0, NA, NA, NA,
NA, 0, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0, 0, 0, 0, NA, 0)
specs$class1 <- constr
# create model from data frame
model.custom <- create_sem(specs)
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.