Skip to content

feat: add Split class for segmented analysis and cluster aggregation#265

Open
ludovicolc wants to merge 6 commits into
mainfrom
split-class
Open

feat: add Split class for segmented analysis and cluster aggregation#265
ludovicolc wants to merge 6 commits into
mainfrom
split-class

Conversation

@ludovicolc

Copy link
Copy Markdown
Collaborator

This PR introduces the Split class and its default implementation DefaultSplit. This new feature allows for segmented analysis (e.g., by User Status, Market, etc.) while ensuring correct statistical treatment of clustered data.

Why was Split added? (Difference from Dimension)

The Split class was introduced to handle a specific analytical use case that Dimension does not cover:

  • Dimension (Static/Pre-experiment attributes): Used for attributes that do not change during the test period for a given unit.
  • Split (Dynamic): Used for attributes that can change during the test (e.g., User Status like "Prime" vs "Non-Prime").

The Core Benefit of Split:

When using a Split, the logic in HypothesisTest ensures that even if a user changes status during the experiment, the data is correctly aggregated at the cluster level before performing the inference. This prevents statistical bias and ensures that the "Total" result correctly reflects the weighted contribution of these dynamic segments.

Using Dimensions and Splits Together

The implementation allows Dimension and Split to be used simultaneously within the same AnalysisPlan.
When both are provided, the AnalysisPlan performs a nested iteration.
This enables a granular breakdown (e.g., analyzing the experiment results by Country and then further segmenting by User Status within each country). For every combination, the system correctly handles the cluster aggregation required by the Split logic while maintaining the categorical filtering of the Dimension.

Key Changes

  • New Split and DefaultSplit classes: Implemented in cluster_experiments/inference/split.py.
  • Updated AnalysisPlan: Added logic to iterate over both dimensions and splits, providing a "Total" view as the base case for each split.
  • Refactored AnalysisResults.to_dataframe(): introduced a drop_empty parameter (defaulting to False). When drop_empty=True and no dimension or split is provided by the user, columns containing default or placeholder values (such as __total_split or __total_dimension) are automatically removed, resulting in a cleaner and more concise final report.
  • Enhanced HypothesisTest: Updated get_test_results to correctly populate split information in the results object.

@ludovicolc ludovicolc requested a review from david26694 March 31, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant