FactorGraph function

Draws a factor graph of a (time-varying) MGM

Draws a factor graph of a (time-varying) MGM

Wrapper function around qgraph() that draws factor graphs for (time-varying) MGMs

FactorGraph(object, labels, PairwiseAsEdge = FALSE, Nodewise = FALSE, DoNotPlot = FALSE, FactorLabels = TRUE, colors, shapes, shapeSizes = c(8, 4), estpoint = NULL, negDashed = FALSE, ...)

Arguments

  • object: The output object of mgm() or tvmgm().
  • labels: A character vector of (variable) node labels.
  • PairwiseAsEdge: If TRUE, pairwise interactions are not displayed as factors but as simple edges between nodes. Defaults to PairwiseAsEdge = FALSE.
  • Nodewise: If TRUE, the estimates from the individual nodewise regressions are displayed as a directed edge towards the node on which the respective nodewise regression was performed. This is useful to identify model misspecification (e.g. moderation effects / interaction parameters with largely different values across nodewise regressions). Defaults to Nodewise = FALSE.
  • DoNotPlot: If DoNotPlot = TRUE no factorgraph is plotted. This way the computed factor graph can be obtained without plotting. Defaults to DoNotPlot = FALSE.
  • FactorLabels: If FactorLabels = TRUE the factors are labeled by their order. If FactorLabels = FALSE no label is shown. Defaults to FactorLabels = TRUE.
  • colors: A character vector of colors for nodes and factors. The first color is for variable-nodes, the second for 2-way interactions, the third for 3-way interactions, etc. Defaults to colors = c("white", "tomato", "lightblue", "orange").
  • shapes: A character vector of shapes for for nodes and factors. The first shape is for variable-nodes, the second for 2-way interactions, the third for 3-way interactions, etc. Defaults to shapes = c("circle", "square", "triangle", "diamond").
  • shapeSizes: A numeric vector of length two indicating the size of shapes for nodes and factors. Defaults to shapeSizes = c(8, 4).
  • estpoint: An integer indicating the estimation point to display if the output object of a time-varying MGM is provided.
  • negDashed: If negDashed = TRUE, edges with negative sign are dashed.
  • ...: Arguments passed to qgraph.

Details

FactorGraph() is a wrapper around qgraph() from the qgraph package. Therefore all arguments of qgraph() are available and can be provided as additional arguments.

To make time-varying factor graphs comparable across estimation points, the factor graph of each estimation point includes all factors that are estimated nonzero at least at one estimation point.

Returns

Plots the factor graph and returns a list including the arguments used to plot the factor graph using qgraph().

Specifically, a list is returned including: graph contains a weighted adjacency matrix of a (bipartide) factor graph. If p is the number of variables and E the number of interactions (factors) in the model, this matrix has dimensions (p+E) x (p+E). The factor graph is furter specified by the following objects: signs is a matrix of the same dimensions as graph that indicates the sign of each interaction, if defined (see pairwise above). edgecolor is a matrix with the same dimension as graph that provides edge colors depending on the sign as above. order is a (p+E) vector indicating the order of interaction. The first p entries are set to zero. qgraph contains the qgraph object created while plotting.

Author(s)

Jonas Haslbeck jonashaslbeck@gmail.com

See Also

mgm(), tvmgm(), qgraph()

Examples

## Not run: # Fit MGM with pairwise & threeway interactions to Autism Dataset fit_k3 <- mgm(data = autism_data$data, type = autism_data$type, level = autism_data$lev, k = 3, overparameterize = TRUE, lambdaSel = "EBIC", lambdaGam = .5) # List of estimated interactions fit_k3$interactions$indicator FactorGraph(object = fit_k3, PairwiseAsEdge = FALSE, DoNotPlot = FALSE, labels = 1:7, layout="circle") # For more examples see https://github.com/jmbh/mgmDocumentation ## End(Not run)
  • Maintainer: Jonas Haslbeck
  • License: GPL (>= 2)
  • Last published: 2025-03-16