cfx: Creates a CausalFX Problem Instance

Description Usage Arguments Value


Set up an object describing a causal inference problem of finding the average causal effect of some treatment on some outcome. Currently, only binary data is supported. The problem specification also allows the specification of a synthetic model, for simulation studies.


cfx(x, y, latent_idx = NULL, dat = NULL, g = NULL, model = NULL,
  num_v_max = 20)



the index of the treatment variable.


the index of the outcome variable.


an array with the indices of variables which should be considered latent


a matrix of binary data, can be ignored if a model is provided.


a binary matrix encoding a causal graph, where g[i, j] == 1 if a directed edge from vertex j to i should exist, 0 otherwise. This is only required if a ground truth model exists.


if g is specified, this needs to be specified too. This argument should be a list of conditional probability tables, each encoding the conditional probability of each vertex in g given its parents. Entry model[[i]] is an array of non-negative numbers, describing the probability of random variable/vertex i being equal to 1. In particular, model[[i]][j] is the conditional probability of this event given that the parents of i are in state j. States are indexed as follows. If S is the binary string corresponding to the binary values of the parents of i in g, sorted by their index, then j is given by 1 + bin2dec(S), where bin2dec is the transformation of a binary string into a decimal number.


the maximum dimensionality in which the joint distribution implied by a model is pre-computed. Having this pre-computed can speed up some computations for methods that use the provided ground truth model. Because the space required to store a joint distribution grows exponentially with the dimensionality, this quantity cannot be too large.


A cfx object, which contains the following fields:


the index of the treatment variable in the data/graph.


the index of the outcome variable in the data/graph.


the array of latent variable indices given as input.


the data given as input.


the graph given as input.


an array of strings with the names of the variables, as given by data. If data has no column names or it is not provided, this is given a default value, where variable i is assigned the name "X".


the model given as input.


a list of arrays (if g is provided), where ancestrals[[i]] is the array of the indices of the ancestrals of i in g, excluding i itself.


a multidimensional array (if g is provided) of the same dimensionality as g, where each entry corresponds to the probability of that particular assignment of variable values. This is NULL if the dimensionality of g is greater than num_v_max.

Search within the CausalFX package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.