Skip to content

Commit 824df26

Browse files
committed
fix: align uniformity reporting with peak-based R behavior
1 parent 4338b3e commit 824df26

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

remode/remode.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ def _create_alpha_correction(
349349
self.approx_bayes_factors: np.ndarray = np.array([])
350350
self.xt: np.ndarray = np.array([])
351351
self.levels: np.ndarray = np.array([])
352-
self.uniform_distribution: bool = False
353-
self.uniformity_p_value: float = np.nan
352+
self.uniform_distribution: Optional[bool] = None
353+
self.uniformity_p_value: Optional[float] = None
354354

355355
def format_data(
356356
self, xt: Union[np.ndarray, list], levels: Optional[np.ndarray] = None
@@ -459,16 +459,18 @@ def fit(
459459
[approximate_bayes_factor(p_value) for p_value in p_values], dtype=float
460460
)
461461

462-
uniformity_p_value = np.nan
463-
uniform_distribution = False
462+
uniformity_p_value: Optional[float] = None
463+
uniform_distribution: Optional[bool] = None
464464
if self.definition == "peak_based" and np.sum(xt) > 0:
465465
uniformity_p_value = float(chisquare(xt).pvalue)
466+
uniform_distribution = bool(
467+
np.isfinite(uniformity_p_value) and uniformity_p_value > 0.05
468+
)
466469
# Match R behavior: fixed 0.05 threshold for the Pearson chi-square test.
467-
if np.isfinite(uniformity_p_value) and uniformity_p_value > 0.05:
470+
if uniform_distribution:
468471
modes = np.array([], dtype=int)
469472
p_values = np.array([], dtype=float)
470473
approx_bayes_factors = np.array([], dtype=float)
471-
uniform_distribution = True
472474

473475
if len(levels) == 0:
474476
self.levels = np.arange(len(xt))

tests/test_remode.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ def test_peak_based_definition_uniform_distribution():
156156
peak_based = ReMoDe(statistical_test="fisher", definition="peak_based").fit(x)
157157

158158
assert shape_based["nr_of_modes"] > 0
159+
assert shape_based["uniform_distribution"] is None
160+
assert shape_based["uniformity_p_value"] is None
159161
assert peak_based["nr_of_modes"] == 0
160162
assert bool(peak_based["uniform_distribution"])
161163
assert peak_based["uniformity_p_value"] > 0.05

0 commit comments

Comments
 (0)