lingam

repository·master·Indexed 19 days ago

https://github.com/cdt15/lingam

A Python library for discovering non-Gaussian linear causal models (structural equation models or linear Bayesian networks) by leveraging the non-Gaussianity of data. It provides various algorithms for causal discovery, including DirectLiNGAM, ICALiNGAM, ABICLiNGAM, and specialized models for high-dimensional data, time series (VAR-LiNGAM, VARMA-LiNGAM), longitudinal data, and datasets with latent confounders or missing values.

Tokens
69.1K
Snippets
222
Records
301
Agent score
67%

What's inside lingam

  1. Use lingam.utils for causal analysis and visualization

    master

    The lingam.utils module provides a collection of utility functions and classes for post-discovery analysis, visualization, and model evaluation. Key capabilities include:

    • Visualization: Generating DOT files for DAGs, ancestors, descendants, and paths using make_dot, make_dot_ancestors, make_dot_descendants, and make_dot_paths.
    • Causal Analysis: Calculating total effects with calculate_total_effect, finding paths with find_all_paths, and identifying exogenous or sink variables via get_exo_variables and get_sink_variables.
    • Model Evaluation: Assessing fit with evaluate_model_fit and calculating likelihoods or information criteria.
    • Graph Properties: Extracting ancestors with extract_ancestors and calculating distances from root nodes with calculate_distance_from_root_nodes.
    • Advanced Estimation: Accessing MGGD and MGGDEstimator classes for specific estimation tasks.
  2. What is GroupLiNGAM?

    master

    GroupLiNGAM (Group Linear Non-Gaussian Acyclic Model) is an extension of the basic LiNGAM model designed to handle latent confounding structures and grouped variable interactions.

    It operates under three core assumptions:

    1. Linearity: Relationships between variables are linear.
    2. Non-Gaussianity: Continuous error variables are non-Gaussian.
    3. Acyclicity: Variable subsets (blocks) are acyclic.

    Unlike standard LiNGAM, GroupLiNGAM partitions variables into ordered disjoint subsets (blocks). While variables within a single block may be mutually dependent, no variable in a later block can influence a variable in an earlier block. The algorithm determines this block ordering by recursively evaluating statistical independence between variable subsets and the residuals of the remaining variables.

  3. What is the LiM causal discovery algorithm?

    master

    The Linear Mixed (LiM) causal discovery algorithm extends the LiNGAM method to handle datasets containing both continuous and discrete (binary) variables.

    How it works

    1. Global Optimization: It first optimizes the log-likelihood function on the joint distribution of the data while enforcing an acyclicity constraint.
    2. Local Search: It then applies a local combinatorial search to output the final causal graph.

    Model Assumptions

    • Mixed Data: Supports both continuous and binary variables.
    • Linearity: Relationships between variables are linear.
    • Acyclicity: The causal graph is a Directed Acyclic Graph (DAG).
    • No Hidden Causes: Assumes no unobserved common causes (causal sufficiency).
    • Consistent Baselines: Assumes baselines are the same when predicting one binary variable from another for every pair of binary variables.

    Mathematical Model

    • Continuous Variables: $x_i = e_i + c_i + \sum_{j \in \mathrm{pa}(i) }{b_{ij} x_j}$, where $e_i$ is a non-Gaussian error term.
    • Discrete Variables: $x_i = 1$ if $e_i + c_i + \sum_{j \in \mathrm{pa}(i) }{b_{ij} x_j} > 0$, otherwise $0$, where $e_i$ follows a Logistic distribution.
  4. What is VARLiNGAM?

    master

    VARLiNGAM is an extension of the LiNGAM model designed for time series data. It combines the basic LiNGAM model with classic Vector Autoregressive (VAR) models, allowing for the analysis of both lagged and contemporaneous (instantaneous) causal relations.

    Key assumptions include:

    • Linearity
    • Non-Gaussian continuous error variables (except at most one)
    • Acyclicity of contemporaneous causal relations
    • No hidden common causes

    The model follows the equation: $x(t) = \sum_{ \tau = 0}^k B_{ \tau } x(t - \tau) + e(t)$, where $B_{\tau}$ are adjacency matrices with time lag $\tau$.

  5. What is LongitudinalRESIT?

    master

    LongitudinalRESIT is a causal discovery algorithm designed for longitudinal (time-series) data. It extends the RESIT (Regression with Subsequent Independence Test) framework to handle nonlinear relationships and temporal dependencies.

    It estimates two types of causal structures from multivariate time-series data:

    1. Instantaneous (within-time) causal graphs: Relationships between variables at the same time point.
    2. Lagged (across-time) causal graphs: Relationships between variables at different time points (past vs. present).

    The algorithm operates in three phases:

    • Phase 1: Estimating a causal order via repeated sink node detection (assumed to be shared across all time points).
    • Phase 2: Estimating instantaneous causal graphs using regression-based independence testing with edge pruning.
    • Phase 3: Identifying lagged causal relationships by testing dependencies between past and present variables.

    Key features include the use of Fisher's method to combine independence tests across time points for robust inference and support for both shared causal graphs (constant across time) and time-specific causal structures.

  6. What is BottomUpParceLiNGAM?

    master

    The BottomUpParceLiNGAM model is an extension of the basic LiNGAM model designed to handle cases with hidden common causes (latent confounders).

    Key Assumptions:

    1. Linearity: The relationships between variables are linear.
    2. Non-Gaussianity: Continuous error variables are non-Gaussian (except for at most one).
    3. Acyclicity: The causal graph contains no directed cycles.

    Handling Latent Variables: Unlike the standard latent variable LiNGAM which allows hidden common causes between any observed variables, BottomUpParceLiNGAM assumes that only exogenous observed variables may share hidden common causes. This simplifies the model while remaining robust against latent confounders.

  7. What is the DirectLiNGAM model?

    master

    DirectLiNGAM is a method for learning linear non-Gaussian structural equation models. It assumes the following:

    1. Linearity: The relationship between variables is linear.
    2. Non-Gaussian continuous error variables: Error variables are non-Gaussian (except for at most one).
    3. Acyclicity: The causal graph contains no directed cycles.
    4. No hidden common causes: All relevant causes are observed.

    Mathematically, the model for observed variables $x$ is represented as $x = Bx + e$, where $B$ is the adjacency matrix and $e$ is the vector of error variables.

  8. What is VARMALiNGAM?

    master

    VARMALiNGAM is an extension of the LiNGAM model designed for time series data. It combines the basic LiNGAM model with Vector Autoregressive Moving Average (VARMA) models.

    Unlike classic VARMA which only analyzes lagged causal relations, VARMALiNGAM enables the analysis of both lagged and contemporaneous (instantaneous) causal relations.

    Key assumptions include:

    1. Linearity
    2. Non-Gaussian continuous error variables (except at most one)
    3. Acyclicity of contemporaneous causal relations
    4. No hidden common causes between contemporaneous error variables
  9. What is RCD (Repetitive Causal Discovery)?

    master

    RCD (Repetitive Causal Discovery) is an extension of the basic LiNGAM model designed to handle cases with hidden common causes (latent variables).

    Key Assumptions:

    1. Linearity: The relationships between variables are linear.
    2. Non-Gaussianity: Continuous error variables are non-Gaussian.
    3. Acyclicity: The causal structure is a Directed Acyclic Graph (DAG).

    Output Interpretation:

    • Bi-directed arcs: Indicate a pair of variables sharing the same hidden common causes.
    • Directed arrows: Indicate a causal direction for a pair of variables not affected by the same hidden common causes.
  10. How Longitudinal LiNGAM works

    master

    Longitudinal LiNGAM is a method for causal discovery on "paired" samples collected over time. It analyzes causal structures and topological causal orders that may change across different time points.

    Core Assumptions:

    1. Linearity: The relationships between variables are linear.
    2. Non-Gaussianity: Continuous error variables are non-Gaussian (except for at most one).
    3. Acyclicity: The model is a Directed Acyclic Graph (DAG).
    4. No Hidden Common Causes: Error variables are independent.

    Mathematical Model: The observed variable matrix $X(t)$ at time $t$ is modeled as: $X(t) = \sum_{ \tau = 0}^k B (t, t-\tau) X(t - \tau) + E(t)$ where $B(t, t-\tau)$ represents adjacency matrices with time lag $\tau$, and $E(t)$ represents error variables.

  11. Configure the prior knowledge matrix

    master

    The prior knowledge matrix is used to constrain the causal discovery. The elements of the matrix are defined as follows:

    • 0: Variable $x_i$ does not have a directed path to $x_j$.
    • 1: Variable $x_i$ has a directed path to $x_j$.
    • -1: No prior knowledge is available (the relationship is unknown).

    You can use the utility function make_prior_knowledge to construct these matrices easily by specifying variable roles.

  12. Define prior knowledge values for RESIT

    master

    When constructing a prior knowledge matrix for the RESIT model, use the following integer values to represent causal relationships between variables $x_i$ and $x_j$:

    • 0: $x_i$ does not have a directed path to $x_j$.
    • 1: $x_i$ has a directed path to $x_j$.
    • -1: No prior knowledge is available (the relationship is unknown).