Skip to contents

Extracts the information from a model that is needed to produce a plot.

Usage

lav_model_plotinfo(model = NULL, infile = NULL, varlv = FALSE)

Arguments

model

A character vector specifying the model in lavaan syntax or a list (or data.frame) with at least members lhs, op, rhs, label and fixed or a fitted lavaan object (in which case the ParTable object is extracted and column est is used as value to show). Should be NULL if infile is given.

infile

A character string specifying the file that contains the model syntax.

varlv

A logical indicating that the (residual) variance of a variable should be plotted as a separate latent variable (with a smaller circle than ordinary latent variables). In this case, a covariance between two such variables is plotted as a covariance between their variance latent variables.

Value

A structure 'plotinfo', which is a list with members nodes and edges. These are data.frames containing the data needed to create a diagram.

  1. nodes

    id

    character, identification of the node consisting of blok and naam.

    naam

    character, name of the node as specified in the model. For intercepts the name is "1vanXXXX", with XXXX the name of the regressed variable.

    tiepe

    character, type of node: ov (observed variable), lv (latent variable), varlv (variance as latent variable), cv (composite variable), wov (within level variable in multilevel model), bov (between level variable in multilevel model), const (intercept of regression).

    blok

    integer, level (0 if not a multilevel model).

  2. edges

    id

    integer, autoincrement identification of the edge.

    label

    character, label for the edge, made from the label specified in the model and the fixed (or estimated) value if present.

    van

    character, id of the starting node.

    naar

    character, id of the destination node.

    tiepe

    character, lavaan operator, with two exceptions: a (residual) variance is coded here as '~~~', and a regression introduced by varlv = TRUE is coded as '~.'.

Examples

model <- 'alpha  =~ 1 * x1 + x2 + x3        # latent variable
          beta <~ x4 + x5 + x6              # composite
          gamma =~ 1 * x7 + x8 + x9         # latent variable
          Xi =~ 1 * x10 + x11 + x12 + x13   # latent variable
          # regressions
          Xi ~ v * alpha + t * beta + cc * 1
          alpha ~ tt * beta + ss * gamma + yy * Theta1
          # variances and covariances
          x2 ~~ cc25 * x5
          x3 ~~ cc36 * x6
          x3 ~~ cc34 * x4
          gamma ~~ 0.55 * gamma
          '
(test <- lav_model_plotinfo(model))
#> $nodes
#>        id   naam tiepe blok
#> 1   alpha  alpha    lv    0
#> 2      x1     x1    ov    0
#> 3      x2     x2    ov    0
#> 4      x3     x3    ov    0
#> 5    beta   beta    cv    0
#> 6      x4     x4    ov    0
#> 7      x5     x5    ov    0
#> 8      x6     x6    ov    0
#> 9   gamma  gamma    lv    0
#> 10     x7     x7    ov    0
#> 11     x8     x8    ov    0
#> 12     x9     x9    ov    0
#> 13     Xi     Xi    lv    0
#> 14    x10    x10    ov    0
#> 15    x11    x11    ov    0
#> 16    x12    x12    ov    0
#> 17    x13    x13    ov    0
#> 18 1vanXi 1vanXi const    0
#> 19 Theta1 Theta1    ov    0
#> 
#> $edges
#>    id label    van  naar tiepe
#> 1   1     1  alpha    x1    =~
#> 2   2        alpha    x2    =~
#> 3   3        alpha    x3    =~
#> 4   4           x4  beta    <~
#> 5   5           x5  beta    <~
#> 6   6           x6  beta    <~
#> 7   7     1  gamma    x7    =~
#> 8   8        gamma    x8    =~
#> 9   9        gamma    x9    =~
#> 10 10     1     Xi   x10    =~
#> 11 11           Xi   x11    =~
#> 12 12           Xi   x12    =~
#> 13 13           Xi   x13    =~
#> 14 14     v  alpha    Xi     ~
#> 15 15     t   beta    Xi     ~
#> 16 16    cc 1vanXi    Xi     ~
#> 17 17    tt   beta alpha     ~
#> 18 18    ss  gamma alpha     ~
#> 19 19    yy Theta1 alpha     ~
#> 20 20  cc25     x5    x2    ~~
#> 21 21  cc36     x6    x3    ~~
#> 22 22  cc34     x4    x3    ~~
#> 23 23  0.55  gamma gamma   ~~~
#>