tfci: Perform causal discovery using the temporal FCI algorithm...

View source: R/tfci.R

tfciR Documentation

Perform causal discovery using the temporal FCI algorithm (TFCI)

Description

Use a modification of the FCI algorithm that makes use of background knowledge in the format of a partial ordering. This may for instance come about when variables can be assigned to distinct tiers or periods (i.e., a temporal ordering).

Usage

tfci(
  data = NULL,
  order,
  sparsity = 10^(-1),
  test = regTest,
  suffStat = NULL,
  method = "stable.fast",
  methodNA = "none",
  methodOri = "conservative",
  varnames = NULL,
  ...
)

Arguments

data

A data.frame with data. All variables should be assigned to exactly one period by prefixing them with the period name (see example below).

order

A character vector with period-prefixes in their temporal order (see example below).

sparsity

The sparsity level to be used for independence testing (i.e. significance level threshold to use for each test).

test

A procedure for testing conditional independence. The default, regTest uses a regression-based information loss test. Another available option is corTest which tests for vanishing partial correlations. User supplied functions may also be used, see details below about the required syntax.

suffStat

Sufficient statistic. If this argument is supplied, the sufficient statistic is not computed from the inputted data. The format and contents of the sufficient statistic depends on which test is being used.

method

Which method to use for skeleton construction, must be "stable", "original", or "stable.fast" (the default). See skeleton for details.

methodNA

Method for handling missing information (NA values). Must be one of "none" (default, an error is thrown if NAs are present), "cc" (complete case analysis, deletes all observations that have any NA values), or "twd" (test wise deletion, omits observations with missing information test-by-test) (further details below).

methodOri

Method for handling conflicting separating sets when orienting edges, must be one of "standard", "conservative" (the default) or "maj.rule". See pc for further details.

varnames

A character vector of variable names. It only needs to be supplied if the data argument is not used, and data are hence passed exclusively through the suffStat argument.

...

Further optional arguments which are passed to skeleton for the skeleton constructing phase.

Details

The temporal/tiered background information enters several places in the TFCI algorithm: 1) In the skeleton construction phase, when looking for separating sets Z between two variables X and Y, Z is not allowed to contain variables that are strictly after both X and Y in the temporal order. 2) This also applies to the subsequent phase where the algorithm searches for possible D-SEP sets. 3) Prior to other orientation steps, any cross-tier edges get an arrowhead placed at their latest node.

After this, the usual FCI orientation rules are applied, see udag2pag for details.

Value

The default output is a tpag object. This is an S3 object, i.e., a list, with entries: $tamat (the estimated adjacency matrix), $order (character vector with the order, as inputted to this function), $psi (the significance level used for testing), and $ntests (the number of tests conducted).

The adjacency matrix A has four possible entry values: 0 (no edge), 1 (circle), 2 (arrowhead), 3 (tail). It is encoded as a "to-from" adjacency matrix, which means that e.g. A(i,j) = 1 places a circle in the directed from j to i. For example, if A(i,j) = 1 and A(j,i) = 2, we have that i o-> j. Similarly, A(i,j) = 2 and A(j,i) = 3 mean that i <- j. Note that this is a transposed version of the adjacency matrix outputted for fciAlgo objects from the pcalg package, which is "to-from". But it is consistent with the "from-to" adjacency matrices used for pcAlgo objects from the same package.

Author(s)

Anne Helby Petersen, Qixiang Chen, and Daniel Malinsky.

Examples

# simulate linear Gaussian data w unobserved variable L1
set.seed(123)
n <- 100
L1 <- rnorm(n) 
X1 <- rnorm(n)
X2 <- L1 + X1 + rnorm(n)
X3 <- X1 + rnorm(n)
X4 <- X3 + L1 + rnorm(n)
d <- data.frame(p1_X1 = X1,
                p1_X2 = X2,
                p2_X3 = X3,
                p2_X4 = X4)

# use tfci algorithm to recover tpag (conservative edge orientation)
tfci(d, test = corTest, order = c("p1", "p2"))

# use tfci with standard (non-conservative) method for edge orientation
tfci(d, test = corTest, order = c("p1", "p2"), methodOri = "standard")


causalDisco documentation built on Jan. 20, 2026, 5:09 p.m.