sample_from_tree: Samples data from a Gaussian latent tree model

View source: R/wrapper.R

sample_from_treeR Documentation

Samples data from a Gaussian latent tree model

Description

Samples data from a Gaussian latent tree model

Usage

sample_from_tree(tree, m, n)

Arguments

tree

An igraph object that is a tree. It is assumed that the first m nodes correspond to oberseved nodes and that model parameters are given in the following way: V(g)$var is the variance of the observed variables and that E(g)$corr are the edge correlations.

m

Integer, number of observed nodes.

n

Integer, number of samples being sampled.

Value

Matrix with sampled data with m columns and n rows. Each row corresponds to one sample.

Examples

# Create tree
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)

# Sample data from tree
igraph::V(tree)$var = rep(1,8)
igraph::E(tree)$corr = rep(0.7,7)
sample_from_tree(tree, m=5, n=500)

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