LR_test: Likelihood ratio test for the goodness of fit of a Gaussian...

View source: R/LR_EM.R

LR_testR Documentation

Likelihood ratio test for the goodness of fit of a Gaussian latent tree model

Description

Testing the goodness of fit of a given Gaussian latent tree model to observed data.

Usage

LR_test(
  X,
  g,
  paths,
  sampling = FALSE,
  nr_starts = 100,
  a = 0.5,
  b = 0.9,
  c = 0.5,
  d = 1.5,
  maxiter = 10000
)

Arguments

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 V(g)$var is the variance of the observed variables and that E(g)$corr represents the edge correlations. Should be initialized with starting values if sampling==FAlSE.

paths

Nested list with the paths between all nodes. Should be computed with the function get_paths. This is done outside the LR test to accelerate the computation.

sampling

Boolean. If TRUE, random sampling of starting values is incorporated.

nr_starts

Integer determining the number of different starting values. Only used if sampling==TRUE.

a

Edge correlations are sampled from the union of intervals [-b,-a] and [a,b]. Only used if sampling==TRUE.

b

Edge correlations are sampled from the union of intervals [-b,-a] and [a,b]. Only used if sampling==TRUE.

c

Variances are sampled from the interval [c,d]. Only used if sampling==TRUE.

d

Variances are sampled from the interval [c,d]. Only used if sampling==TRUE.

maxiter

Integer, maximum number of iterations in the EM algorithm.

Value

Named list with three entries: Test statistic (TSTAT), p-value (PVAL) and number of iterations (it).

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)

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

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