impact_statistics#

rojak.atmosphere.feature_composite.impact_statistics(counts, *, min_count=10, haldane=False)[source]#

How the feature changes traffic and the probability of each event, relative to the controls.

The counts are summed over chunk first; every other dimension, including control, is kept. Each event e with a pair of variables feature_n_<e> and control_n_<e> gets its own measures, from the 2x2 table

  • n_11 = E_feat: events about the feature,

  • n_10 = N_feat - E_feat: observations about the feature that are not events,

  • n_01 = E_ctl: events in the control,

  • n_00 = N_ctl - E_ctl: observations in the control that are not events,

where N is feature_n_obs or control_n_obs and E is feature_n_<e> or control_n_<e>.

A zero in a denominator gives NaN, never infinity, while a zero in a numerator is a real 0.

Parameters:
  • counts (xarray.Dataset) – Per-chunk counts as returned by the pipeline, with feature_n_obs, control_n_obs, n_centres, n_controls and any event pairs. Computed here if lazy.

  • min_count (float) – Bins where the observations summed over chunks are fewer than this, about the feature or in the control, are NaN: in p_feature_<e> or p_control_<e> for that side, and in the ratios for either side. traffic_per_centre and traffic_per_control are not masked.

  • haldane (bool) – If True, add 0.5 to every cell of the table before the odds ratio (the Haldane correction), so that it is finite where a cell is zero. The other measures are not corrected.

Returns:

In memory, with:

  • traffic_per_centre: N_feat / n_centres, observations per bin per centre.

  • traffic_per_control: N_ctl / n_controls, observations per bin per control.

  • traffic_ratio: their ratio. Above 1 means more traffic about the feature than without it.

  • p_feature_<e> / p_control_<e>: E / N, probability of the event per observation.

  • relative_risk_<e>: p_feature_<e> / p_control_<e>, from relative_risk_from_table().

  • odds_ratio_<e>: n_11 n_00 / (n_10 n_01), from odds_ratio_from_table().

Return type:

xarray.Dataset