stratified_contingency_table#

rojak.turbulence.metrics.stratified_contingency_table(effect_of, on_var, *control_var, sum_over)[source]#

Compute contingency tables stratified by one or more control variables

If a single control_var is given, the contingency table between effect_of and on_var is computed assuming the stratification is on the prescence of control_var and the abscence. In other words, two contingency tables are computed, once on the condition of control_var and another on not control_var. If more than one control_var is given, the contingency table between effect_of and on_var is instead computed once each of the control variables assuming that each represents a specific strata.

Given :math`k` strata :math`Z_{1}, dots, Z_{k}` (defined by control_var as described above), a contingency table is computed for each stratum, as defined as [Agresti2022],

\[\begin{split}\begin{array}{c|c|c|c} Z & X & Y = 1 & Y = 0 \\ \hline Z_{1} & X = 1 & n_{111} & n_{011} \\ & X = 0 & n_{101} & n_{001} \\ \hline \vdots & \vdots & \vdots & \vdots \\ \hline Z_{k} & X = 1 & n_{11k} & n_{01k} \\ & X = 0 & n_{10k} & n_{00k} \\ \end{array}\end{split}\]

where :math`X` is effect_of and :math`Y` is on_var.

Parameters:
  • effect_of (DataArray) – First binary variable (:math`x` in contingency table)

  • on_var (DataArray) – Second binary variable (:math`y` in contingency table)

  • *control_var (DataArray) – One or more binary variables to stratify by (:math`z` in contingency table)

  • sum_over (str | list[str] | None) – Dimension(s) to sum over to compute the number of observations. If None, it will sum over all dimension in the array

Returns:

List of ContingencyTable, one per stratum

Return type:

list[ContingencyTable]