Data Structures

Data structures.

class VermaConstraint(lhs_cfactor: Expression, lhs_expr: Expression, rhs_cfactor: Expression, rhs_expr: Expression, variables: Tuple[Variable, ...])[source]

Represent a Verma constraint.

Create new instance of VermaConstraint(lhs_cfactor, lhs_expr, rhs_cfactor, rhs_expr, variables)

lhs_cfactor: Expression

Alias for field number 0

lhs_expr: Expression

Alias for field number 1

rhs_cfactor: Expression

Alias for field number 2

rhs_expr: Expression

Alias for field number 3

variables: Tuple[Variable, ...]

Alias for field number 4

classmethod from_element(element) VermaConstraint[source]

Extract content from each element in the vector returned by verma.constraint.

Parameters:

element – An element in the vector returned by verma.constraint

Returns:

A Verma constraint tuple for the given element

class DSeparationJudgement(separated: bool, left: Variable, right: Variable, conditions: Tuple[Variable, ...])[source]

Record if a left/right pair are d-separated given the conditions.

By default, acts like a boolean, but also caries evidence graph.

classmethod create(left: Variable, right: Variable, conditions: Iterable[Variable] | None = None, *, separated: bool = True) DSeparationJudgement[source]

Create a d-separation judgement in canonical form.

property is_canonical: bool

Return if the conditional independency is in canonical form.

test(df: DataFrame, *, boolean: bool = False, method: Literal['pearson', 'chi-square', 'cressie_read', 'freeman_tuckey', 'g_sq', 'log_likelihood', 'modified_log_likelihood', 'power_divergence', 'neyman'] | None = None, significance_level: float | None = None, _method_checked: bool = False) bool | CITestTuple[source]

Test for conditional independence, given some data.

Parameters:
  • df – A dataframe.

  • boolean – Should results be returned as a pre-cutoff boolean?

  • method – Conditional independence from pgmpy to use. If none, defaults to pgmpy.estimators.CITests.cressie_read().

  • significance_level – The statistical tests employ this value for comparison with the p-value of the test to determine the independence of the tested variables. If none, defaults to 0.01. Only applied if boolean=True.

Returns:

Tests the null hypothesis that X is independent of Y given Zs. If boolean=False, returns a three-tuple of chi, dof, p_value. If boolean=True, make sure you also set significance_level=0.05 or your preferred value, then returns simply a boolean if the test fails.

Raises:

ValueError – if any parts of the judgement aren’t in the dataframe’s columns