
lavaan
package (Rosseel, 2011) and outputs a multi-page pdf file containing path diagram, graphs of the parameter estimates and graphs of the implied and observed covariance and correlation matrices.qgraph.lavaan(
fit,
...,
layout="circle",
groups=NULL,
vsize.man=3,
vsize.lat=6,
filename="qgraph",
filetype="pdf",
residuals=TRUE,
include=1:12,
curve=0,
residSize=0.2,
onefile=TRUE,
width=12,
height=8,
titles=TRUE)
qgraph
. This is both for the path diagram and for the correlation/covariance plots.qgraph
"lavaan "
object and outputs a multi-page pdf file.
The function reads the 'lavaan' object and creates a residual variable for each variable present
in the model. Layout options include a tree-layout (layout="tree") in which each variable is
placed as a node on one of four vertical levels. At the bottom are the residuals of the
manifest variables placed, Above that the manifest variables, above that the latent variables
and at the top the residuals of the latent variables. The nodes are evenly spaced horizontally
in order of appearance in the model (residuals are placed at the same horizontal position of
their corresponding variable). So the order of specifying in the model defines the order of
placement in the path diagram. If the 'residuals' argument is FALSE then residuals are omitted
and this diagram will only contain two levels.Alternatively the 'spring' layout can be used (layout="spring"). This will use the Fruchterman-reingold algorithm (Fruchterman & Reingold, 1991), which has been ported from the 'sna' package (Butts, 2010). This is a force-directed algorithm. It is best to use this in combination with residuals=FALSE. Another option is a circular layout (default), which is the same as the tree except that the levels are placed in inner circles rather than horizontal lines. Names for variables used in the model specification are passed to the path diagram. To keep the model readable it is advised to limit these names to 3 characters.
Carter T. Butts
Yves Rosseel
qgraph
qgraph.cfa
qgraph.sem
sem
## Example from lavaan::sem help file:
require("lavaan")
## The industrialization and Political Democracy Example
## Bollen (1989), page 332
model <- '
# latent variable definitions
ind60 =~ x1 + x2 + x3
dem60 =~ y1 + y2 + y3 + y4
dem65 =~ y5 + equal("dem60=~y2")*y6
+ equal("dem60=~y3")*y7
+ equal("dem60=~y4")*y8
# regressions
dem60 ~ ind60
dem65 ~ ind60 + dem60
# residual correlations
y1 ~~ y5
y2 ~~ y4 + y6
y3 ~~ y7
y4 ~~ y8
y6 ~~ y8
'
fit <- sem(model, data=PoliticalDemocracy)
# Plot standardized model (numerical):
qgraph.lavaan(fit,layout="tree",vsize.man=5,vsize.lat=10,
filetype="",include=4,curve=-0.4,edge.label.cex=0.6)
# Plot standardized model (graphical):
qgraph.lavaan(fit,layout="tree",vsize.man=5,vsize.lat=10,
filetype="",include=8,curve=-0.4,edge.label.cex=0.6)
# Create output document:
qgraph.lavaan(fit,layout="spring",vsize.man=5,vsize.lat=10,
filename="lavaan")
Run the code above in your browser using DataLab