Learn R Programming

pcalg (version 2.2-0)

LINGAM: Linear non-Gaussian Additive Models

Description

This code fits a LiNGAM to the data and outputs the corresponding DAG.

Usage

LINGAM(X, verbose = FALSE)

Arguments

X
n x p data matrix (n: sample size, p: number of variables)
verbose
boolean indicator (TRUE/FALSE) whether output should be shown.

Value

  • list of objects:
  • Adjp x p adjacency matrix. The entry (i,j) being one corresponds to a directed edge from i to j.
  • Bp x p matrix of corresponding linear coefficients.

Details

see the reference below

References

S. Shimizu, P.O. Hoyer, A. Hyv"arinen, A. Kerminen: A Linear Non-Gaussian Acyclic Model for Causal Discovery, Journal of Machine Learning Research 7, pages 2003-2030, 2006.

Examples

Run this code
##################################################
## Exp 1
##################################################
set.seed(123)
n <- 500
eps1 <- sign(rnorm(n)) * sqrt(abs(rnorm(n)))
eps2 <- runif(n) - 0.5

x2 <- eps2
x1 <- 0.9*x2 + eps1

X <- cbind(x1,x2)

trueDAG <- cbind(c(0,1),c(0,0))
## x1 <- x2 
## adjacency matrix:
## 0 0
## 1 0

estDAG <- LINGAM(X, verbose = TRUE)

cat("true DAG:
")
show(trueDAG)

cat("estimated DAG:
")
show(estDAG$Adj)

##################################################
## Exp 2
##################################################
set.seed(123)
n <- 500
eps1 <- sign(rnorm(n)) * sqrt(abs(rnorm(n)))
eps2 <- runif(n) - 0.5
eps3 <- sign(rnorm(n)) * abs(rnorm(n))^(1/3)
eps4 <- rnorm(n)^2

x2 <- eps2
x1 <- 0.9*x2 + eps1
x3 <- 0.8*x2 + eps3
x4 <- -0.9*x3 - x1 + eps4

X <- cbind(x1,x2,x3,x4)

trueDAG <- cbind(c(0,1,0,0),c(0,0,0,0),c(0,1,0,0),c(1,0,1,0))
## x4 <- x3 <- x2 -> x1 -> x4
## adjacency matrix:
## 0 0 0 1
## 1 0 1 0
## 0 0 0 1
## 0 0 0 0

estDAG <- LINGAM(X, verbose = TRUE)

cat("true DAG:
")
show(trueDAG)

cat("estimated DAG:
")
show(estDAG$Adj)

Run the code above in your browser using DataLab