View source: R/graph-functions.R
cov_from_graph | R Documentation |
Given a tree and parameters (variance and edge correlations) the covariance matrix of the corresponding multivariate Gaussian distribution is computed.
cov_from_graph(g, m, paths)
g |
An igraph object that is a tree. It is assumed that the first m nodes correspond to oberseved nodes.
Type 1 indicates that a node is observed. Should be set via |
m |
Integer, number of observed nodes. |
paths |
Nested list with the paths between all nodes.
Should be computed with the function |
Covarianz matrix.
vertices <- data.frame(name=seq(1,8), type=c(rep(1,5), rep(2,3))) # 1=observed, 2=latent
edges <- data.frame(from=c(1,2,3,4,5,6,7), to=c(8,8,6,6,7,7,8))
tree <- igraph::graph_from_data_frame(edges, directed=FALSE, vertices=vertices)
plot(tree)
# Set parameters
igraph::E(tree)$corr = rep(0.7,7)
igraph::V(tree)$var = rep(1,8)
# Compute all paths
paths <- get_paths(tree)
# Call function
cov_from_graph(tree, 5, paths)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.