LR_test | R Documentation |
Testing the goodness of fit of a given Gaussian latent tree model to observed data.
LR_test(
X,
g,
paths,
sampling = FALSE,
nr_starts = 100,
a = 0.5,
b = 0.9,
c = 0.5,
d = 1.5,
maxiter = 10000
)
X |
Matrix with observed data. Number of columns equal to the number of leaves of the tree (i.e. number of observed variables). Each row corresponds to one sample. |
g |
An igraph object that is a tree. It is assumed that the first m nodes correspond to oberseved nodes.
It is assumed that |
paths |
Nested list with the paths between all nodes.
Should be computed with the function |
sampling |
Boolean. If TRUE, random sampling of starting values is incorporated. |
nr_starts |
Integer determining the number of different starting values. Only used if |
a |
Edge correlations are sampled from the union of intervals |
b |
Edge correlations are sampled from the union of intervals |
c |
Variances are sampled from the interval |
d |
Variances are sampled from the interval |
maxiter |
Integer, maximum number of iterations in the EM algorithm. |
Named list with three entries: Test statistic (TSTAT
), p-value (PVAL
) and number of iterations (it
).
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)
# Sample data from tree
igraph::V(tree)$var = rep(1,8)
igraph::E(tree)$corr = rep(0.7,7)
X = sample_from_tree(tree, m=5, n=500)
# Set starting values
igraph::V(tree)$var = rep(1,8)
igraph::E(tree)$corr = rep(0.7,7)
# Compute all paths
paths <- get_paths(tree)
# Call the test
LR_test(X, tree, paths)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.