Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
e10v committed Aug 18, 2024
1 parent fead1b1 commit c6c97ab
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions src/tea_tasting/multiplicity.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from collections.abc import Callable


NULL_COMPARISON = "-"
NO_NAME_COMPARISON = "-"


class MultipleComparisonsResults(
Expand All @@ -43,6 +43,12 @@ def to_dicts(self) -> tuple[dict[str, Any], ...]:
)


def _to_str(x: Any, seq_sep: str = ", ") -> str:
if not isinstance(x, str) and isinstance(x, Sequence):
return seq_sep.join(str(v) for v in x)
return str(x)


def adjust_fdr(
experiment_results: tea_tasting.experiment.ExperimentResult | dict[
Any, tea_tasting.experiment.ExperimentResult],
Expand Down Expand Up @@ -106,30 +112,6 @@ def adjust_fdr(
return MultipleComparisonsResults(results)


def _adjust_stepup(
metric_results: Sequence[dict[str, Any]],
adjust: Callable[[float, int], tuple[float, float]],
) -> None:
pvalue_adj_prev = 1
alpha_adj_min = 0
k = len(metric_results)
for metric_result in sorted(metric_results, key=lambda d: -d["pvalue"]):
pvalue = metric_result["pvalue"]
pvalue_adj, alpha_adj = adjust(pvalue, k)

if pvalue <= alpha_adj and alpha_adj_min == 0:
alpha_adj_min = alpha_adj
alpha_adj = max(alpha_adj, alpha_adj_min)
pvalue_adj = pvalue_adj_prev = min(pvalue_adj, pvalue_adj_prev)

metric_result.update(
pvalue_adj=pvalue_adj,
alpha_adj=alpha_adj,
null_rejected=int(pvalue <= alpha_adj),
)
k -= 1


def _copy_results(
experiment_results: tea_tasting.experiment.ExperimentResult | dict[
Any, tea_tasting.experiment.ExperimentResult],
Expand All @@ -139,7 +121,7 @@ def _copy_results(
list[dict[str, Any]],
]:
if not isinstance(experiment_results, dict):
experiment_results = {NULL_COMPARISON: experiment_results}
experiment_results = {NO_NAME_COMPARISON: experiment_results}

if metrics is not None:
if isinstance(metrics, str):
Expand All @@ -166,10 +148,28 @@ def _copy_results(
return copy_of_experiment_results, copy_of_metric_results


def _to_str(x: Any, seq_sep: str = ", ") -> str:
if not isinstance(x, str) and isinstance(x, Sequence):
return seq_sep.join(str(v) for v in x)
return str(x)
def _adjust_stepup(
metric_results: Sequence[dict[str, Any]],
adjust: Callable[[float, int], tuple[float, float]],
) -> None:
pvalue_adj_max = 1
alpha_adj_min = 0
k = len(metric_results)
for metric_result in sorted(metric_results, key=lambda d: -d["pvalue"]):
pvalue = metric_result["pvalue"]
pvalue_adj, alpha_adj = adjust(pvalue, k)

if alpha_adj_min == 0 and pvalue <= alpha_adj:
alpha_adj_min = alpha_adj
alpha_adj = max(alpha_adj, alpha_adj_min)
pvalue_adj = pvalue_adj_max = min(pvalue_adj, pvalue_adj_max)

metric_result.update(
pvalue_adj=pvalue_adj,
alpha_adj=alpha_adj,
null_rejected=int(pvalue <= alpha_adj),
)
k -= 1


class _Adjustment(abc.ABC):
Expand Down

0 comments on commit c6c97ab

Please sign in to comment.