From 7306329a1b698e9aca8d6d91589e3d49ff525914 Mon Sep 17 00:00:00 2001 From: pciturri Date: Tue, 27 Aug 2024 21:15:24 +0200 Subject: [PATCH] refactor: t-test EvaluationResult() now includes value of alpha, so it is not necessary to set it again when plotting. plot_comparison_test() includes a default legend that explains the symbology therein. --- csep/core/poisson_evaluations.py | 2 +- csep/utils/plots.py | 3 ++- tests/test_plots.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/csep/core/poisson_evaluations.py b/csep/core/poisson_evaluations.py index 6c0f5e22..4725bcbb 100644 --- a/csep/core/poisson_evaluations.py +++ b/csep/core/poisson_evaluations.py @@ -47,7 +47,7 @@ def paired_t_test(forecast, benchmark_forecast, observed_catalog, result.name = 'Paired T-Test' result.test_distribution = (out['ig_lower'], out['ig_upper']) result.observed_statistic = out['information_gain'] - result.quantile = (out['t_statistic'], out['t_critical']) + result.quantile = (out['t_statistic'], out['t_critical'], alpha) result.sim_name = (forecast.name, benchmark_forecast.name) result.obs_name = observed_catalog.name result.status = 'normal' diff --git a/csep/utils/plots.py b/csep/utils/plots.py index c1634a6a..84bdc8f5 100644 --- a/csep/utils/plots.py +++ b/csep/utils/plots.py @@ -773,7 +773,8 @@ def plot_comparison_test( if plot_args["legend"]: # Add custom legend to explain results legend_elements = [ - Line2D([0], [0], color="red", lw=2, label="T-test rejected"), + Line2D([0], [0], color="red", lw=2, + label=f"T-test rejected ($\\alpha = {results_t[0].quantile[-1]}$)"), Line2D([0], [0], color="green", lw=2, label="T-test non-rejected"), Line2D([0], [0], color="gray", lw=2, label="T-test indistinguishable"), Line2D( diff --git a/tests/test_plots.py b/tests/test_plots.py index 35802ea7..66ccc5da 100644 --- a/tests/test_plots.py +++ b/tests/test_plots.py @@ -662,7 +662,7 @@ def rand(limit=10, offset=0.0): t_result.observed_statistic - rand(5), t_result.observed_statistic + rand(5), ] - + t_result.quantile = (None, None, 0.05) if numpy.random.random() < 0.05: # sim possible infinite values t_result.observed_statistic = -numpy.inf t_tests.append(t_result)