generate.latent.ggm.data: Simulate data from a Gaussian graphical model with hidden...

Description Usage Arguments Value Examples

View source: R/simulate_data.R

Description

A partitioned inverse covariance (precision) matrix K is constructed as K := [K_X, K_{XL}; K_{XL}^T, K_L], where K_X is a p x p sparse matrix, K_{LX} is a p x h matrix connecting the h hidden variables to observed ones and K_L is a h x h diagonal matrix.

n samples are then drawn from a multivariate normal distribution: N(0, K^{-1}) and only the first p variables are observed.

This function is here to demonstrate the features of the package.

Usage

1
2
generate.latent.ggm.data(n, p, h, sparsity = 0.02,
  sparsity.latent = 0.7, outlier.fraction = 0)

Arguments

n

Number of samples.

p

Number of observed variables.

h

Number of hidden variables.

sparsity

Real between 0 and 1. The density of the sparse graph (encoded by K_X).

sparsity.latent

Real between 0 and 1. Probability of connection between any observed variable and any hidden variable (K_{LX}).

outlier.fraction

Fraction of the samples that should be drawn from a Cauchy distribution. The remaining ones are drawn from a multivariate normal with the same scale matrix.

Value

A list with keys:

obs.data

n x p data matrix of observed variables.

full.data

(n+h) x p data matrix which also contains the hidden variables.

precision.matrix

(n+h)x(n+h) matrix from which the data was sampled. Rows/Columns indexed by 1:p correspond to observed variables. The remaining h rows/cols are the hidden ones.

sparsity

Realised sparsity of the precision matrix restricted to observed variables.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
 n <- 2000 # Number of samples
 p <- 100 # Number of variables
 h <- 5 # Number of hidden variables
 sim.data <- generate.latent.ggm.data(n=n, p=p, h=h, outlier.fraction = 0.0,
                               sparsity = 0.02, sparsity.latent = 0.7)
 true.S <- sim.data$precision.matrix[-((p+1):(p+h)),-((p+1):(p+h))] # The sparse matrix
 observed.data <- sim.data$obs.data

 # Generate data with 10 of samples drawn from a Cauchy
 sim.data <- generate.latent.ggm.data(n=n, p=p, h=h, outlier.fraction = 0.1,
                               sparsity = 0.02, sparsity.latent = 0.7)
 true.S <- sim.data$precision.matrix[-((p+1):(p+h)),-((p+1):(p+h))] # The sparse matrix
 observed.data <- sim.data$obs.data

benjaminfrot/lrpsadmm documentation built on Oct. 19, 2019, 8:13 a.m.