Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
292 changes: 150 additions & 142 deletions dabest/_dabest_object.py

Large diffs are not rendered by default.

106 changes: 49 additions & 57 deletions dabest/_effsize_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,14 @@ def __init__(
"cohens_h": "Cohen's h",
"hedges_g": "Hedges' g",
"cliffs_delta": "Cliff's delta",
"delta_g": "deltas' g",
}

self.__is_paired = is_paired
self.__resamples = resamples
self.__effect_size = effect_size
self.__random_seed = random_seed
self.__ci = ci
self.__proportional = proportional
self.__is_proportional = proportional
self._check_errors(control, test)

# Convert to numpy arrays for speed.
Expand Down Expand Up @@ -237,7 +236,7 @@ def __repr__(self, show_resample_count=True, define_pval=True, sigfig=3):
return "{}\n{}\n\n{}\n{}".format(out, pvalue, bs, pval_def)
elif not show_resample_count and define_pval:
return "{}\n{}\n\n{}".format(out, pvalue, pval_def)
elif show_resample_count and ~define_pval:
elif show_resample_count and not define_pval:
return "{}\n{}\n\n{}".format(out, pvalue, bs)
else:
return "{}\n{}".format(out, pvalue)
Expand All @@ -256,16 +255,15 @@ def _check_errors(self, control, test):
err1 = "`paired` is not None; therefore Cliff's delta is not defined."
raise ValueError(err1)

if self.__proportional and self.__effect_size not in ["mean_diff", "cohens_h"]:
err1 = "`proportional` is True; therefore effect size other than mean_diff and cohens_h is not defined." + \
"If you are calculating deltas' g, it's the same as delta-delta when `proportional` is True"
if self.__is_proportional and self.__effect_size not in ["mean_diff", "cohens_h"]:
err1 = "`is_proportional` is True; therefore effect size other than mean_diff and cohens_h is not defined."
raise ValueError(err1)

if self.__proportional and (
if self.__is_proportional and (
isin(control, [0, 1]).all() == False or isin(test, [0, 1]).all() == False
):
err1 = (
"`proportional` is True; Only accept binary data consisting of 0 and 1."
"`is_proportional` is True; Only accept binary data consisting of 0 and 1."
)
raise ValueError(err1)

Expand Down Expand Up @@ -333,7 +331,7 @@ def _perform_statistical_test(self):
self.__permutation_count,
)

if self.__is_paired and not self.__proportional:
if self.__is_paired and not self.__is_proportional:
# Wilcoxon, a non-parametric version of the paired T-test.
try:
wilcoxon = spstats.wilcoxon(self.__control, self.__test)
Expand All @@ -354,7 +352,7 @@ def _perform_statistical_test(self):
self.__pvalue_paired_students_t = paired_t.pvalue
self.__statistic_paired_students_t = paired_t.statistic

elif self.__is_paired and self.__proportional:
elif self.__is_paired and self.__is_proportional:
# for binary paired data, use McNemar's test
# References:
# https://en.wikipedia.org/wiki/McNemar%27s_test
Expand All @@ -368,7 +366,7 @@ def _perform_statistical_test(self):
self.__pvalue_mcnemar = _mcnemar.pvalue
self.__statistic_mcnemar = _mcnemar.statistic

elif self.__proportional:
elif self.__is_proportional:
# The Cohen's h calculation is for binary categorical data
try:
self.__proportional_difference = es.cohens_h(
Expand Down Expand Up @@ -544,8 +542,8 @@ def is_paired(self):
return self.__is_paired

@property
def proportional(self):
return self.__proportional
def is_proportional(self):
return self.__is_proportional

@property
def ci(self):
Expand Down Expand Up @@ -842,12 +840,12 @@ def __init__(
self.__resamples = resamples
self.__permutation_count = permutation_count
self.__random_seed = random_seed
self.__proportional = proportional
self.__is_proportional = proportional
self.__x1_level = x1_level
self.__experiment_label = experiment_label
self.__x2 = x2
self.__delta2 = delta2
self.__mini_meta = mini_meta
self.__is_mini_meta = mini_meta

def __pre_calc(self):
from .misc_tools import print_greeting, get_varname
Expand Down Expand Up @@ -885,7 +883,7 @@ def __pre_calc(self):
self.__is_paired,
self.__resamples,
self.__random_seed,
self.__proportional,
self.__is_proportional,
)

for j, current_tuple in enumerate(idx):
Expand All @@ -903,7 +901,7 @@ def __pre_calc(self):
control,
test,
self.__effect_size,
self.__proportional,
self.__is_proportional,
self.__is_paired,
self.__ci,
self.__resamples,
Expand All @@ -917,10 +915,10 @@ def __pre_calc(self):
r_dict["test_N"] = int(len(test))
out.append(r_dict)
if j == len(idx) - 1 and ix == len(current_tuple) - 2:
if self.__delta2 and self.__effect_size in ["mean_diff", "delta_g"]:
if self.__delta2 and self.__effect_size in ["mean_diff", "hedges_g"]:
resamp_count = False
def_pval = False
elif self.__mini_meta and self.__effect_size == "mean_diff":
elif self.__is_mini_meta and self.__effect_size == "mean_diff":
resamp_count = False
def_pval = False
else:
Expand Down Expand Up @@ -1001,32 +999,33 @@ def __pre_calc(self):
)

# Create and compute the delta-delta statistics
if self.__delta2:
if self.__delta2 and self.__effect_size not in ["mean_diff", "hedges_g"]:
self.__delta_delta = "Delta-delta is not supported for {}.".format(
self.__effect_size
)
elif self.__delta2:
self.__delta_delta = DeltaDelta(
self, self.__permutation_count, bootstraps_delta_delta, self.__ci
)
reprs.append(self.__delta_delta.__repr__(header=False))
elif self.__delta2 and self.__effect_size not in ["mean_diff", "delta_g"]:
self.__delta_delta = "Delta-delta is not supported for {}.".format(
self.__effect_size
)

else:
self.__delta_delta = (
"`delta2` is False; delta-delta is therefore not calculated."
)

# Create and compute the weighted average statistics
if self.__mini_meta and self.__effect_size == "mean_diff":
self.__mini_meta_delta = MiniMetaDelta(
if self.__is_mini_meta and self.__effect_size == "mean_diff":
self.__mini_meta = MiniMetaDelta(
self, self.__permutation_count, self.__ci
)
reprs.append(self.__mini_meta_delta.__repr__(header=False))
elif self.__mini_meta and self.__effect_size != "mean_diff":
self.__mini_meta_delta = "Weighted delta is not supported for {}.".format(
reprs.append(self.__mini_meta.__repr__(header=False))
elif self.__is_mini_meta and self.__effect_size != "mean_diff":
self.__mini_meta = "Weighted delta is not supported for {}.".format(
self.__effect_size
)
else:
self.__mini_meta_delta = (
self.__mini_meta = (
"`mini_meta` is False; weighted delta is therefore not calculated."
)

Expand Down Expand Up @@ -1300,7 +1299,7 @@ def plot(
passed to plot() : {'linewidth':1, 'alpha':0.5, 'jitter':0, 'jitter_seed':9876543210}.
sankey_kwargs: dict, default None
Whis will change the appearance of the sankey diagram used to depict
paired proportional data when `show_pairs=True` and `proportional=True`.
paired proportional data when `show_pairs=True` and `is_proportional=True`.
Pass any keyword arguments accepted by plot_tools.sankeydiag() function
here, as a dict. If None, the following keywords are passed to sankey diagram:
{"width": 0.5, "align": "center", "alpha": 0.4, "bar_width": 0.1, "rightColor": False}
Expand All @@ -1320,8 +1319,7 @@ def plot(
legend_kwargs : dict, default None
Pass any keyword arguments accepted by the matplotlib Axes
`legend` command here, as a dict. If None, the following keywords
are passed to matplotlib.Axes.legend : {'loc':'upper left',
'frameon':False}.
are passed to matplotlib.Axes.legend : {'frameon':False}.
title : string, default None
Title for the plot. If None, no title will be displayed. Pass any
keyword arguments accepted by the matplotlib.pyplot.suptitle `t` command here,
Expand Down Expand Up @@ -1372,7 +1370,7 @@ def plot(
Whether or not to display the delta dots on paired or repeated measure plots.
delta_dot_kwargs : dict, default None
Pass relevant keyword arguments. If None, the following keywords are passed:
{"color": 'k', "marker": "^", "alpha": 0.5, "zorder": -1, "size": 3, "side": "right"}
{"color": 'k', "marker": "^", "alpha": 0.5, "zorder": 2, "size": 3, "side": "right"}

horizontal_table_kwargs : dict, default None
{'show: True, 'color' : 'yellow', 'alpha' :0.2, 'fontsize' : 12, 'text_color' : 'black',
Expand Down Expand Up @@ -1437,9 +1435,6 @@ def plot(
if self.__delta2 and not empty_circle:
color_col = self.__x2

# if self.__proportional:
# raw_marker_size = 0.01

# Modification incurred due to update of Seaborn
ci = ("ci", ci) if ci is not None else None

Expand All @@ -1450,12 +1445,12 @@ def plot(
return out

@property
def proportional(self):
def is_proportional(self):
"""
Returns the proportional parameter
class.
"""
return self.__proportional
return self.__is_proportional

@property
def results(self):
Expand Down Expand Up @@ -1537,10 +1532,6 @@ def x2(self):
def experiment_label(self):
return self.__experiment_label

@property
def delta2(self):
return self.__delta2

@property
def resamples(self):
"""
Expand Down Expand Up @@ -1568,13 +1559,6 @@ def dabest_obj(self):
"""
return self.__dabest_obj

@property
def proportional(self):
"""
Returns the proportional parameter
class.
"""
return self.__proportional

@property
def lqrt(self):
Expand All @@ -1590,33 +1574,41 @@ def lqrt(self):
return self.__lqrt_results

@property
def mini_meta(self):
def is_mini_meta(self):
"""
Returns the mini_meta boolean parameter.
"""
return self.__mini_meta
return self.__is_mini_meta

@property
def mini_meta_delta(self):
def mini_meta(self):
"""
Returns the mini_meta results.
"""
try:
return self.__mini_meta_delta
return self.__mini_meta
except AttributeError:
self.__pre_calc()
return self.__mini_meta_delta
return self.__mini_meta

@property
def delta_delta(self):
"""
Returns the mini_meta results.
Returns the delta_delta results.
"""
try:
return self.__delta_delta
except AttributeError:
self.__pre_calc()
return self.__delta_delta

@property
def delta2(self):
return self.__delta2

@property
def is_delta_delta(self):
return self.__delta2

# %% ../nbs/API/effsize_objects.ipynb 29
class PermutationTest:
Expand All @@ -1630,7 +1622,7 @@ class PermutationTest:
These should be numerical iterables.
effect_size : string.
Any one of the following are accepted inputs:
'mean_diff', 'median_diff', 'cohens_d', 'hedges_g', 'delta_g" or 'cliffs_delta'
'mean_diff', 'median_diff', 'cohens_d', 'hedges_g', or 'cliffs_delta'
is_paired : string, default None
permutation_count : int, default 10000
The number of permutations (reshuffles) to perform.
Expand Down
Loading