Learn R Programming

SEMgraph (version 1.2.2)

extractClusters: Cluster extraction utility

Description

Extract and fit clusters from an input graph.

Usage

extractClusters(
  graph,
  data,
  group = NULL,
  membership = NULL,
  map = FALSE,
  verbose = FALSE,
  ...
)

Value

A list of 3 objects:

  1. "clusters", list of clusters as igraph objects;

  2. "fit", list of fitting results for each cluster as a lavaan object;

  3. "dfc", data.frame of summary results.

Arguments

graph

Input network as an igraph object.

data

A matrix or data.frame. Rows correspond to subjects, and columns to graph nodes (variables).

group

A binary vector. This vector must be as long as the number of subjects. Each vector element must be 1 for cases and 0 for control subjects. Group specification enables node perturbation testing. By default, group = NULL.

membership

A vector of cluster membership IDs. If NULL, clusters will be automatically generated with clusterGraph using the edge betweenness clustering ("ebc") algorithm.

map

Logical value. If TRUE, the plot of the input graph (coloured by cluster membership) will be generated along with independent module plots. If the input graph is very large, plotting could be computationally intensive (by default, map = FALSE).

verbose

Logical value. If TRUE, a plot will be showed for each cluster.

...

Currently ignored.

Author

Fernando Palluzzi fernando.palluzzi@gmail.com

Examples

Run this code

# \donttest{
# Nonparanormal(npn) transformation
als.npn <- transformData(alsData$exprs)$data

adjdata <- SEMbap(alsData$graph, als.npn)$data

# Clusters creation
clusters <- extractClusters(alsData$graph, adjdata, alsData$group)
print(clusters$dfc)
head(parameterEstimates(clusters$fit$HM1))
head(parameterEstimates(clusters$fit$HM2))
head(parameterEstimates(clusters$fit$HM4))
gplot(clusters$clusters$HM2)

# Map cluster on the input graph
g <- alsData$graph
c <- clusters$clusters$HM2
V(g)$color <- ifelse(V(g)$name %in% V(c)$name, "gold", "white")
gplot(g)
# }

Run the code above in your browser using DataLab