sample_from_tree | R Documentation |
Samples data from a Gaussian latent tree model
sample_from_tree(tree, m, n)
tree |
An igraph object that is a tree.
It is assumed that the first |
m |
Integer, number of observed nodes. |
n |
Integer, number of samples being sampled. |
Matrix with sampled data with m columns and n rows. Each row corresponds to one sample.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.