Skip to contents

Gets information from model necessary 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 which contains the model syntax.

varlv

A logical indicating that the (residual) variance of a variable should be plotted as a seperate latent variable (with a smaller circle then ordinary latent variables). In this case covariances between two such variables will be plotted as covariance between the latent variables for the variance.

Value

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

  1. nodes

    id

    integer, autoincrement identification of the node.

    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).

    voorkeur

    character, preferred place in the plot, l(left), r(right) or m = (middle).

  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

    integer, id of the starting node.

    naar

    integer, id of the destination node.

    tiepe

    character, lavaan operator, except (residual) variance, coded here 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 voorkeur
#> 1   1  alpha    lv    0        m
#> 2   2     x1    ov    0         
#> 3   3     x2    ov    0         
#> 4   4     x3    ov    0         
#> 5   5   beta    cv    0        l
#> 6   6     x4    ov    0         
#> 7   7     x5    ov    0         
#> 8   8     x6    ov    0         
#> 9   9  gamma    lv    0        l
#> 10 10     x7    ov    0         
#> 11 11     x8    ov    0         
#> 12 12     x9    ov    0         
#> 13 13     Xi    lv    0        r
#> 14 14    x10    ov    0         
#> 15 15    x11    ov    0         
#> 16 16    x12    ov    0         
#> 17 17    x13    ov    0         
#> 18 18 1vanXi const    0        l
#> 19 19 Theta1    ov    0        l
#> 
#> $edges
#>    id label van naar tiepe
#> 1   1     1   1    2    =~
#> 2   2         1    3    =~
#> 3   3         1    4    =~
#> 4   4         6    5    <~
#> 5   5         7    5    <~
#> 6   6         8    5    <~
#> 7   7     1   9   10    =~
#> 8   8         9   11    =~
#> 9   9         9   12    =~
#> 10 10     1  13   14    =~
#> 11 11        13   15    =~
#> 12 12        13   16    =~
#> 13 13        13   17    =~
#> 14 14     v   1   13     ~
#> 15 15     t   5   13     ~
#> 16 16    cc  18   13     ~
#> 17 17    tt   5    1     ~
#> 18 18    ss   9    1     ~
#> 19 19    yy  19    1     ~
#> 20 20  cc25   7    3    ~~
#> 21 21  cc36   8    4    ~~
#> 22 22  cc34   6    4    ~~
#> 23 23  0.55   9    9   ~~~
#>