Skip to content

Commit

Permalink
move add_covariates logic to hypothesis test
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovico-lanni committed Oct 4, 2024
1 parent 05be002 commit ccba301
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 2 additions & 7 deletions cluster_experiments/inference/analysis_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,7 @@ def analyze(
analysis_results = EmptyAnalysisPlanResults()

for test in self.tests:
if test.is_cupac:
exp_data = test.cupac_handler.add_covariates(
df=exp_data, pre_experiment_df=pre_exp_data
)

target_col = test.metric.target_column
exp_data = test.add_covariates(exp_data, pre_exp_data)

for treatment_variant in self.treatment_variants:
for dimension in test.dimensions:
Expand All @@ -128,7 +123,7 @@ def analyze(
)

test._prepare_analysis_config(
target_col=target_col,
target_col=test.metric.target_column,
treatment_col=self.variant_col,
treatment=treatment_variant.name,
)
Expand Down
13 changes: 13 additions & 0 deletions cluster_experiments/inference/hypothesis_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,16 @@ def prepare_data(
).query(f"{dimension_name} == '{dimension_value}'")

return prepared_df

def add_covariates(
self, exp_data: pd.DataFrame, pre_exp_data: pd.DataFrame
) -> pd.DataFrame:
"""
If the test is a cupac test, adds the covariates to the experimental data.
"""
if self.is_cupac:
exp_data = self.cupac_handler.add_covariates(
df=exp_data, pre_experiment_df=pre_exp_data
)

return exp_data

0 comments on commit ccba301

Please sign in to comment.