Skip to contents

Get the values of an arbitrary attributes of selected nodes.

Usage

get_node_attribute(
  semPaths_plot,
  nodes = NULL,
  attribute_name = NULL,
  check_nodes = TRUE
)

Arguments

semPaths_plot

A qgraph::qgraph object generated by semPlot::semPaths, or a similar qgraph object modified by other semptools functions. Unlike some other functions, this function does not support a list of qgraph::qgraph objects. If semPaths_plot is a list of qgraph::qgraph objects, only the first object will be processed. Use functions such as lapply() manually to get the attribute values from a list of qgraph::qgraph objects.

nodes

A character vector of the names of nodes. If NULL, then the values of all nodes will be retrieved.

attribute_name

The name of the attribute from which the values will be retrieved.

check_nodes

Logical. If TRUE and at least one node specified in values are not in semPaths_plot.

Value

A named vector of the values.

Details

From a qgraph::qgraph object generated by semPlot::semPaths, and get the values of an attribute of selected nodes.

This function is designed to be a general one that gets the values of the attributes named by the user.

Examples

mod_pa <-
  'x1 ~~ x2
   x3 ~  x1 + x2
   x4 ~  x1 + x3
  '
fit_pa <- lavaan::sem(mod_pa, pa_example)
lavaan::parameterEstimates(fit_pa)[, c("lhs", "op", "rhs", "est", "pvalue")]
#>   lhs op rhs   est pvalue
#> 1  x1 ~~  x2 0.005  0.957
#> 2  x3  ~  x1 0.537  0.000
#> 3  x3  ~  x2 0.376  0.000
#> 4  x4  ~  x1 0.111  0.382
#> 5  x4  ~  x3 0.629  0.000
#> 6  x3 ~~  x3 0.874  0.000
#> 7  x4 ~~  x4 1.194  0.000
#> 8  x1 ~~  x1 0.933  0.000
#> 9  x2 ~~  x2 1.017  0.000
m <- matrix(c("x1",   NA,   NA,
                NA, "x3", "x4",
              "x2",   NA,   NA), byrow = TRUE, 3, 3)
p_pa <- semPlot::semPaths(fit_pa, whatLabels="est",
            style = "ram",
            nCharNodes = 0, nCharEdges = 0,
            layout = m)


get_node_attribute(
   p_pa,
   nodes = c("x1", "x3"),
   attribute_name = "color"
)
#>          x1          x3 
#> "#FFFFFFFF" "#FFFFFFFF" 
get_node_attribute(
   p_pa,
   attribute_name = "label.cex"
)
#> x3 x4 x1 x2 
#>  1  1  1  1