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

semMatrixAlgebra

Extract or calculate with model matrices


Description

This function can be used to extract or calculate with model matrices given a "semMatriModel" object (from modelMatrices) or a "semPlotModel" object or any of the input types that can be used in semPlotModel directly.

If the model is not specified it is attempted to be identified by the given algebra.

Usage

semMatrixAlgebra(object, algebra, group, simplify = TRUE, model, endoOnly = FALSE)

Arguments

object

A "semMatriModel" object (from modelMatrices) or a "semPlotModel" object or any of the input types that can be used in semPlotModel directly.

algebra

An R expression to use.

group

Groups the algebra should be used on. If more than one a list is returned with the result for each group.

simplify

If TRUE and only one group is used, return output as is instead of in a list.

model

Model to be used in modelMatrices, "mplus", "ram" or "lisrel"

endoOnly

Only needed when the model is "lisrel", sets all variables to endogenous.

Details

The "lisrel" model uses the following matrix names: LY, TE, PS, BE, LX, TD, PH, GA, TY, TX, AL and KA.

The "mplus" model uses the following matrix names: Lambda, Nu, Theta, Kappa, Alpha, Beta, Gamma and Psi.

The "ram" model uses the following matrix names: F, A and S.

Value

A list containing output per group

Author(s)

Sacha Epskamp <mail@sachaepskamp.com>

See Also

Examples

## Mplus user guide SEM example:
outfile <- tempfile(fileext=".out")
download.file("http://www.statmodel.com/usersguide/chap5/ex5.11.out",outfile)

# Plot model:
semPaths(outfile,intercepts=FALSE)

# Obtain latent regressions (mplus)
semMatrixAlgebra(outfile, Beta)

# mplus model implied covariance:
mat1 <- semMatrixAlgebra(outfile, 
  Lambda %*% Imin(Beta, TRUE) %*% Psi %*% t(Imin(Beta, TRUE)) %*% t(Lambda) + Theta)

# Lisrel model implied covariance:
mat2 <- semMatrixAlgebra(outfile, 
  LY %*% Imin(BE, TRUE) %*% PS %*% t(Imin(BE, TRUE)) %*% t(LY) + TE, endoOnly = TRUE)

# RAM model implied covariance:
mat3 <- semMatrixAlgebra(outfile, 
                 F %*% Imin(A,TRUE) %*% S %*% t(Imin(A, TRUE)) %*% t(F))

## Not run: 
# Plot:
library("qgraph")

pdf("Models.pdf",width=15,height=5)
layout(t(1:3))
qgraph(round(cov2cor(mat1),5), maximum=1, edge.labels=TRUE, layout = "spring", 
  cut = 0.4, minimum = 0.1)
title("Mplus model")
qgraph(round(cov2cor(mat2),5), maximum=1, edge.labels=TRUE, layout = "spring", 
  cut = 0.4, minimum = 0.1)
title("LISREL model")
qgraph(round(cov2cor(mat3),5), maximum=1, edge.labels=TRUE, layout = "spring", 
  cut = 0.4, minimum = 0.1)
title("RAM model")
dev.off()

## End(Not run)
# They are the same.

semPlot

Path Diagrams and Visual Analysis of Various SEM Packages' Output

v1.1.2
GPL-2
Authors
Sacha Epskamp [aut, cre], Simon Stuber [ctb], Jason Nak [ctb], Myrthe Veenman [ctb], Terrence D. Jorgensen [ctb] (<https://orcid.org/0000-0001-5111-6773>)
Initial release

We don't support your browser anymore

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