EVToGraphFull: # transfrorm EVs to a weighted undirected graph #' @export...

View source: R/helper.R

EVToGraphFullR Documentation

# transfrorm EVs to a weighted undirected graph #' @export EVToGraph = function(V, varProp = NULL, k = NULL, eigenvalues = NULL, returnFull = FALSE) edgeList = list() if(class(V) != "list") r = min(dim(V)) edgeList = EVToGraphHelper(V = V, edgeList = edgeList, varProp = varProp, k = k, eigenvalues = eigenvalues) else r = min(dim(V[[1]])) for(i in 1:length(V)) edgeList = EVToGraphHelper(V = V[[i]], edgeList = edgeList, varProp = varProp, k = k, eigenvalues = eigenvalues) # construct graphs if(length(edgeList) == 0)print("no edge"); return(NULL) weight = table(unlist(edgeList))/r; if(class(V) == "list")weight = weight/length(V) edge = unlist(strsplit(names(weight),split = ";")); g = igraph::graph(edge) # isolates not needed names(weight) = NULL; igraph::E(g)$weight = weight g = igraph::as.undirected(g, mode= "collapse",edge.attr.comb=list(weight="sum", "ignore")) if(!returnFull)return(g) else result = list(); result$g = g; result$edge = edge; result$weight = weight; return(result) #' @export weightToGraph = function(weightMatrix, mode = "undirected") diag(weightMatrix) = 0 g = igraph::graph_from_adjacency_matrix(weightMatrix, mode = mode, weighted = TRUE) g = igraph::as.undirected(g, mode= "collapse",edge.attr.comb=list(weight="sum", "ignore")) return(g)

Description

# transfrorm EVs to a weighted undirected graph #' @export EVToGraph = function(V, varProp = NULL, k = NULL, eigenvalues = NULL, returnFull = FALSE) edgeList = list() if(class(V) != "list") r = min(dim(V)) edgeList = EVToGraphHelper(V = V, edgeList = edgeList, varProp = varProp, k = k, eigenvalues = eigenvalues) else r = min(dim(V[[1]])) for(i in 1:length(V)) edgeList = EVToGraphHelper(V = V[[i]], edgeList = edgeList, varProp = varProp, k = k, eigenvalues = eigenvalues) # construct graphs if(length(edgeList) == 0)print("no edge"); return(NULL) weight = table(unlist(edgeList))/r; if(class(V) == "list")weight = weight/length(V) edge = unlist(strsplit(names(weight),split = ";")); g = igraph::graph(edge) # isolates not needed names(weight) = NULL; igraph::E(g)$weight = weight g = igraph::as.undirected(g, mode= "collapse",edge.attr.comb=list(weight="sum", "ignore")) if(!returnFull)return(g) else result = list(); result$g = g; result$edge = edge; result$weight = weight; return(result) #' @export weightToGraph = function(weightMatrix, mode = "undirected") diag(weightMatrix) = 0 g = igraph::graph_from_adjacency_matrix(weightMatrix, mode = mode, weighted = TRUE) g = igraph::as.undirected(g, mode= "collapse",edge.attr.comb=list(weight="sum", "ignore")) return(g)

Usage

EVToGraphFull(
  U,
  V,
  kU = NULL,
  kV = NULL,
  gp.weight = 1,
  pp.weight = 1,
  gg.weight = 1,
  returnFull = FALSE,
  weightMatrixBootstrap = NULL
)

ZijunGao/latentMediator documentation built on April 24, 2022, 12:12 a.m.