Skip to content
Snippets Groups Projects

Resolve "Include Mann-Whitney U rank test"

Merged Ghost User requested to merge felix_issue355-include-mann-whitney-u-rank-test into develop
All threads resolved!
2 files
+ 120
10
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -10,6 +10,7 @@ import xarray as xr
import pandas as pd
from typing import Union, Tuple, Dict, List
import itertools
from collections import OrderedDict
Data = Union[xr.DataArray, pd.DataFrame]
@@ -219,6 +220,47 @@ def calculate_error_metrics(a, b, dim):
return {"mse": mse, "rmse": rmse, "mae": mae, "n": n}
def mann_whitney_u_test(data: pd.DataFrame, reference_col_name: str, **kwargs):
"""
Calculate Mann-Whitney u-test. Uses pandas' .apply() on scipy.stats.mannwhitneyu(x, y, ...).
:param data:
:type data:
:param reference_col_name: Name of column which is used for comparison (y)
:type reference_col_name:
:param kwargs:
:type kwargs:
:return:
:rtype:
"""
res = data.apply(stats.mannwhitneyu, y=data[reference_col_name], **kwargs)
res = res.rename(index={0: "statistics", 1: "p-value"})
return res
def represent_p_values_as_asteriks(p_values: pd.Series, threshold_representation: OrderedDict = None):
"""
Represent p-values as asteriks based on its value.
:param p_values:
:type p_values:
:param threshold_representation:
:type threshold_representation:
:return:
:rtype:
"""
if threshold_representation is None:
threshold_representation = OrderedDict([(1, "ns"), (0.05, "*"), (0.01, "**"), (0.001, "***")])
if not all(x > y for x, y in zip(list(threshold_representation.keys()), list(threshold_representation.keys())[1:])):
raise ValueError(
f"`threshold_representation' keys mus be in strictly "
f"decreasing order but is: {threshold_representation.keys()}")
asteriks = pd.Series().reindex_like(p_values)
for k, v in threshold_representation.items():
asteriks[p_values < k] = v
return asteriks
class SkillScores:
r"""
Calculate different kinds of skill scores.
Loading