Skip to content

Commit

Permalink
Fix observations_threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
benjello committed Aug 11, 2023
1 parent 2ba7c42 commit b498e9b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions openfisca_survey_manager/scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def compute_winners_loosers(self, variable = None,
period = None,
absolute_minimal_detected_variation = 0,
relative_minimal_detected_variation = .01,
observations_thershold = None,
observations_threshold = None,
weighted = True,
alternative_weights = None):

Expand All @@ -370,7 +370,7 @@ def compute_winners_loosers(self, variable = None,
period = period,
absolute_minimal_detected_variation = absolute_minimal_detected_variation,
relative_minimal_detected_variation = relative_minimal_detected_variation,
observations_thershold = observations_thershold,
observations_threshold = observations_threshold,
weighted = weighted,
alternative_weights = alternative_weights,
filtering_variable_by_entity = self.filtering_variable_by_entity,
Expand Down
8 changes: 5 additions & 3 deletions openfisca_survey_manager/simulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def compute_winners_loosers(
period = None,
absolute_minimal_detected_variation = 0,
relative_minimal_detected_variation = .01,
observations_thershold = None,
observations_threshold = None,
weighted = True,
alternative_weights = None,
filtering_variable_by_entity = None,
Expand Down Expand Up @@ -589,8 +589,10 @@ def compute_winners_loosers(
after_value < absolute_minimal_detected_variation
)[almost_zero_before]

if observations_thershold is not None:
if ((above_after).sum() < observations_thershold) | ((below_after).sum() < observations_thershold):
if observations_threshold is not None:
not_legit_below = (below_after.sum() < observations_threshold) & (below_after.sum() > 0)
not_legit_above = (above_after.sum() < observations_threshold) & (above_after.sum() > 0)
if not_legit_below | not_legit_above:
raise ValueError("Not enough observations involved")

above_after_count = (above_after * weight).sum()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ def test_compute_winners_loosers():

absolute_minimal_detected_variation = .9
relative_minimal_detected_variation = .05
observations_thershold = 1
observations_threshold = 1

below, neutral, above = simulation.compute_winners_loosers(
baseline_simulation,
variable,
period = period,
absolute_minimal_detected_variation = absolute_minimal_detected_variation,
relative_minimal_detected_variation = relative_minimal_detected_variation,
observations_thershold = observations_thershold,
observations_threshold = observations_threshold,
)

below_scenario, neutral_scenario, above_scenario = survey_scenario.compute_winners_loosers(
variable,
period = period,
absolute_minimal_detected_variation = absolute_minimal_detected_variation,
relative_minimal_detected_variation = relative_minimal_detected_variation,
observations_thershold = observations_thershold,
observations_threshold = observations_threshold,
)

assert (below, neutral, above) == (1, 0, 9)
Expand Down

0 comments on commit b498e9b

Please sign in to comment.