cov_from_graph: Covariance matrix of observed variables

View source: R/graph-functions.R

cov_from_graphR Documentation

Covariance matrix of observed variables

Description

Given a tree and parameters (variance and edge correlations) the covariance matrix of the corresponding multivariate Gaussian distribution is computed.

Usage

cov_from_graph(g, m, paths)

Arguments

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 V(g)$type==1. It is assumed that V(g)$var is the variance of the observed variables and that E(g)$corr represents the edge correlations.

m

Integer, number of observed nodes.

paths

Nested list with the paths between all nodes. Should be computed with the function get_paths.

Value

Covarianz matrix.

Examples

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)

NilsSturma/TestGGM documentation built on June 30, 2023, 3:09 p.m.