dowhy package

Submodules

dowhy.causal_estimator module

class dowhy.causal_estimator.CausalEstimate(estimate, target_estimand, realized_estimand_expr, **kwargs)[source]

Bases: object

TODO.

add_params(**kwargs)[source]
add_significance_test_results(test_results)[source]
class dowhy.causal_estimator.CausalEstimator(data, identified_estimand, treatment, outcome, test_significance, params=None)[source]

Bases: object

Base class for an estimator of causal effect.

estimate_effect()[source]

TODO.

More description.

Parameters:arg1
Returns:
test_significance(estimate, num_simulations=1000)[source]

Test statistical significance of obtained estimate.

Uses resampling to create a non-parametric significance test. A general procedure. Individual estimators can override this method.

Parameters:
  • self – object instance of class Estimator
  • estimate – obtained estimate
Returns:

class dowhy.causal_estimator.RealizedEstimand(identified_estimand, estimator_name)[source]

Bases: object

update_assumptions(estimator_assumptions)[source]
update_estimand_expression(estimand_expression)[source]

dowhy.causal_graph module

class dowhy.causal_graph.CausalGraph(treatment_name, outcome_name, graph=None, common_cause_names=None, instrument_names=None, observed_node_names=None)[source]

Bases: object

add_node_attributes(observed_node_names)[source]
add_unobserved_common_cause(observed_node_names)[source]
all_observed(node_names)[source]
build_graph(common_cause_names, instrument_names)[source]
do_surgery(node_names, remove_outgoing_edges=False, remove_incoming_edges=False)[source]
filter_unobserved_variables(node_names)[source]
get_ancestors(node_name)[source]
get_common_causes(node1, node2)[source]
get_descendants(node_name)[source]
get_instruments(treatment_node, outcome_node)[source]
get_parents(node_name)[source]
view_graph(layout='dot')[source]

dowhy.causal_identifier module

class dowhy.causal_identifier.CausalIdentifier(graph, estimand_type)[source]

Bases: object

construct_backdoor_estimand(estimand_type, treatment_name, outcome_name, common_causes)[source]
construct_iv_estimand(estimand_type, treatment_name, outcome_name, instrument_names)[source]
identify_effect()[source]
class dowhy.causal_identifier.IdentifiedEstimand(treatment_variable, outcome_variable, estimand_type=None, estimands=None, backdoor_variables=None, instrumental_variables=None)[source]

Bases: object

set_identifier_method(identifier_name)[source]

dowhy.causal_refuter module

class dowhy.causal_refuter.CausalRefutation(estimated_effect, new_effect, refutation_type)[source]

Bases: object

class dowhy.causal_refuter.CausalRefuter(data, identified_estimand, estimate, **kwargs)[source]

Bases: object

dowhy.data_transformer module

class dowhy.data_transformer.DimensionalityReducer(data_array, ndims, **kwargs)[source]

Bases: object

reduce(target_dimensions=None)[source]

dowhy.datasets module

dowhy.datasets.choice(a, size=None, replace=True, p=None)

Generates a random sample from a given 1-D array

New in version 1.7.0.

a : 1-D array-like or int
If an ndarray, a random sample is generated from its elements. If an int, the random sample is generated as if a was np.arange(n)
size : int or tuple of ints, optional
Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.
replace : boolean, optional
Whether the sample is with or without replacement
p : 1-D array-like, optional
The probabilities associated with each entry in a. If not given the sample assumes a uniform distribution over all entries in a.
samples : 1-D ndarray, shape (size,)
The generated random samples
ValueError
If a is an int and less than zero, if a or p are not 1-dimensional, if a is an array-like of size 0, if p is not a vector of probabilities, if a and p have different lengths, or if replace=False and the sample size is greater than the population size

randint, shuffle, permutation

Generate a uniform random sample from np.arange(5) of size 3:

>>> np.random.choice(5, 3)
array([0, 3, 4])
>>> #This is equivalent to np.random.randint(0,5,3)

Generate a non-uniform random sample from np.arange(5) of size 3:

>>> np.random.choice(5, 3, p=[0.1, 0, 0.3, 0.6, 0])
array([3, 3, 0])

Generate a uniform random sample from np.arange(5) of size 3 without replacement:

>>> np.random.choice(5, 3, replace=False)
array([3,1,0])
>>> #This is equivalent to np.random.permutation(np.arange(5))[:3]

Generate a non-uniform random sample from np.arange(5) of size 3 without replacement:

>>> np.random.choice(5, 3, replace=False, p=[0.1, 0, 0.3, 0.6, 0])
array([2, 3, 0])

Any of the above can be repeated with an arbitrary array-like instead of just integers. For instance:

>>> aa_milne_arr = ['pooh', 'rabbit', 'piglet', 'Christopher']
>>> np.random.choice(aa_milne_arr, 5, p=[0.5, 0.1, 0.1, 0.3])
array(['pooh', 'pooh', 'pooh', 'Christopher', 'piglet'],
      dtype='|S11')
dowhy.datasets.linear_dataset(beta, num_common_causes, num_samples, num_instruments=0, treatment_is_binary=True)[source]
dowhy.datasets.sigmoid(x)[source]
dowhy.datasets.stochastically_convert_to_binary(x)[source]
dowhy.datasets.xy_dataset(num_samples, effect=True, sd_error=1)[source]

dowhy.do_why module

Module containing the main model class for the dowhy package.

class dowhy.do_why.CausalModel(data, treatment, outcome, graph=None, common_causes=None, instruments=None, estimand_type='ate', **kwargs)[source]

Bases: object

Main class for storing the causal model state.

estimate_effect(identified_estimand, method_name=None, test_significance=None, method_params=None)[source]

Estimate the identified causal effect.

If method_name is provided, uses the provided method. Else, finds a suitable method to be used.

Parameters:
  • identified_estimand – a probability expression that represents the effect to be estimated. Output of CausalModel.identify_effect method
  • method_name – (optional) name of the estimation method to be used.
Returns:

an instance of the CausalEstimate class, containing the causal effect estimate and other method-dependent information

identify_effect()[source]

Identify the causal effect to be estimated, using properties of the causal graph.

Returns:a probability expression for the causal effect if identified, else NULL
refute_estimate(estimand, estimate, method_name=None, **kwargs)[source]

Refute an estimated causal effect.

If method_name is provided, uses the provided method. Else, finds a suitable method to use.

Parameters:estimate – an instance of the CausalEstimate class.
Returns:an instance of the RefuteResult class
summary()[source]

Print a text summary of the model.

Returns:None
view_model(layout='dot')[source]

View the causal DAG.

Returns:a visualization of the graph

dowhy.plotter module

dowhy.plotter.plot_causal_effect(estimate, treatment, outcome)[source]
dowhy.plotter.plot_treatment_outcome(treatment, outcome, time_var)[source]

Module contents