causallib.simulation.CausalSimulator3.generate_random_topology#

generate_random_topology(n_covariates, p, n_treatments=1, n_outcomes=1, n_censoring=0, given_vars=(), p_hidden=0.0)[source]#

Creates a random graph topology, suitable for describing a causal graph model. Generation is based on a G(n,p) random graph model (each edge independently generated or not by a coin toss).

Parameters:
  • n_covariates (int) – Number of simple covariates to generate

  • p (float) – Probability to generate an edge.

  • n_treatments (int) – Number of treatment variables.

  • n_outcomes (int) – Number of outcome variables.

  • n_censoring (int) – Number of censoring variables.

  • given_vars (Sequence[Any]) – Vector of names of given variables. These variables are considered independent. These suppose to mimic a situation where a partial dataset can be supplied to the generation process. Those names will correspond to the variable names in this existing baseline dataset.

  • p_hidden (float) – The probability to convert a simple covariate variable into a latent (i.e. hidden) variable.

Returns:

2-element tuple containing:

  • topology (pandas.DataFrame): A boolean matrix describing graph dependencies.

    Where T[i,j] = True iff j is a predecessor of i.

  • var_types (pandas.Series): A Series which index holds variable names and values are variable types.

    (e.g. “treatment”, “covariate”, “hidden’, “outcome”…) The given_vars will be the first variable, followed by the generated vars (covariates, then treatment, then outcome, then censors)

Return type:

(pandas.DataFrame, pandas.Series)