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
63 changes: 60 additions & 3 deletions dabest/_delta_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,29 @@ def to_dict(self):
dictionary.
"""
# Only get public (user-facing) attributes.
attrs = [a for a in dir(self) if not a.startswith(("_", "to_dict"))]
attrs = [a for a in dir(self) if not a.startswith(("_", "to_dict", "results"))]
out = {}
for a in attrs:
out[a] = getattr(self, a)
return out

def __compute_results(self):
# With some inspiration from @jungyangliao
delta_delta_results_df = pd.Series(self.to_dict()).to_frame().T

column_index = ['control', 'test', 'difference', 'ci', 'bca_low', 'bca_high', 'bca_interval_idx',
'pct_low', 'pct_high', 'pct_interval_idx', 'bootstraps_control', 'bootstraps_test',
'bootstraps_delta_delta', 'permutations_control', 'permutations_test', 'permutations_delta_delta',
'pvalue_permutation', 'permutation_count', 'bias_correction', 'jackknives'
]
delta_delta_results_df['bootstraps_control'] = [delta_delta_results_df['bootstraps'][0][0]]
delta_delta_results_df['bootstraps_test'] = [delta_delta_results_df['bootstraps'][0][1]]
delta_delta_results_df['permutations_control'] = [delta_delta_results_df['permutations'][0][0]]
delta_delta_results_df['permutations_test'] = [delta_delta_results_df['permutations'][0][1]]
delta_delta_results_df = delta_delta_results_df.reindex(columns=column_index)

self.__results = delta_delta_results_df
return self.__results

@property
def ci(self):
Expand Down Expand Up @@ -352,6 +370,17 @@ def permutations_delta_delta(self):
except AttributeError:
self.__permutation_test()
return self.__permutations_delta_delta

@property
def results(self):
"""
Return the results of the delta-delta analysis.
"""
try:
return self.__results
except AttributeError:
self.__compute_results()
return self.__results

# %% ../nbs/API/delta_objects.ipynb 10
class MiniMetaDelta(object):
Expand Down Expand Up @@ -575,11 +604,30 @@ def to_dict(self):
"""
# Only get public (user-facing) attributes.
attrs = [a for a in dir(self)
if not a.startswith(("_", "to_dict"))]
if not a.startswith(("_", "to_dict", "results"))]
out = {}
for a in attrs:
out[a] = getattr(self, a)
return out


def __compute_results(self):
# With some inspiration from @jungyangliao
"""
Returns all attributes of the `dabest.MiniMetaDelta` object as a
DataFrame.
"""
mini_meta_delta_results_df = pd.Series(self.to_dict()).to_frame().T
column_index = ['control', 'test', 'control_N', 'test_N', 'control_var', 'test_var', 'group_var',
'difference', 'ci', 'bca_low', 'bca_high', 'bca_interval_idx',
'pct_low', 'pct_high', 'pct_interval_idx', 'bootstraps', 'bootstraps_weighted_delta',
'permutations', 'permutations_var', 'permutations_weighted_delta', 'pvalue_permutation',
'permutation_count', 'bias_correction', 'jackknives']
mini_meta_delta_results_df = mini_meta_delta_results_df.reindex(columns=column_index)
mini_meta_delta_results_df.rename(columns={'bootstraps': 'bootstraps_deltas'}, inplace=True)

self.__results = mini_meta_delta_results_df
return self.__results


@property
Expand Down Expand Up @@ -801,4 +849,13 @@ def permutations_weighted_delta(self):
self.__permutation_test()
return self.__permutations_weighted_delta


@property
def results(self):
"""
Return the results of the mini-meta analysis.
"""
try:
return self.__results
except AttributeError:
self.__compute_results()
return self.__results
13 changes: 10 additions & 3 deletions dabest/misc_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ def get_params(
# Disable Gardner-Altman plotting if any of the idxs comprise of more than
# two groups or if it is a delta-delta plot.
float_contrast = plot_kwargs["float_contrast"]
effect_size_type = effectsize_df.effect_size
# effect_size_type = effectsize_df.effect_size
if len(idx) > 1 or len(idx[0]) > 2:
float_contrast = False

if effect_size_type in ["cliffs_delta"]:
if effect_size in ["cliffs_delta"]:
float_contrast = False

if show_delta2 or show_mini_meta:
Expand Down Expand Up @@ -176,7 +176,7 @@ def get_params(
show_baseline_ec = plot_kwargs["show_baseline_ec"]

return (dabest_obj, plot_data, xvar, yvar, is_paired, effect_size, proportional, all_plot_groups, idx,
show_delta2, show_mini_meta, float_contrast, show_pairs, effect_size_type, group_summaries, err_color, horizontal,
show_delta2, show_mini_meta, float_contrast, show_pairs, group_summaries, err_color, horizontal,
results, halfviolin_alpha, ci_type, x1_level, experiment_label, show_baseline_ec)

def get_kwargs(
Expand Down Expand Up @@ -486,6 +486,7 @@ def get_color_palette(
idx: list,
all_plot_groups: list,
delta2: bool,
sankey: bool
):
"""
Create the color palette to be used in the plotter function.
Expand All @@ -506,6 +507,8 @@ def get_color_palette(
A list of all the group names.
delta2 : bool
A boolean flag to determine if the plot will have a delta-delta effect size.
sankey : bool
A boolean flag to determine if the plot is for a Sankey diagram.
"""
# Create color palette that will be shared across subplots.
color_col = plot_kwargs["color_col"]
Expand Down Expand Up @@ -560,6 +563,10 @@ def get_color_palette(
groups_in_palette = {
k: custom_pal[k] for k in color_groups
}
elif sankey:
groups_in_palette = {
k: custom_pal[k] for k in [1, 0]
}
elif color_col is None:
groups_in_palette = {
k: custom_pal[k] for k in all_plot_groups if k in color_groups
Expand Down
12 changes: 7 additions & 5 deletions dabest/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def effectsize_df_plotter(effectsize_df: object, **plot_kwargs) -> matplotlib.fi

# Extract parameters and set kwargs
(dabest_obj, plot_data, xvar, yvar, is_paired, effect_size, proportional, all_plot_groups, idx,
show_delta2, show_mini_meta, float_contrast, show_pairs, effect_size_type, group_summaries, err_color, horizontal,
show_delta2, show_mini_meta, float_contrast, show_pairs, group_summaries, err_color, horizontal,
results, halfviolin_alpha, ci_type, x1_level, experiment_label, show_baseline_ec) = get_params(
effectsize_df = effectsize_df,
plot_kwargs = plot_kwargs,
Expand Down Expand Up @@ -152,7 +152,8 @@ def effectsize_df_plotter(effectsize_df: object, **plot_kwargs) -> matplotlib.fi
show_pairs = show_pairs,
idx = idx,
all_plot_groups = all_plot_groups,
delta2 = effectsize_df.delta2
delta2 = effectsize_df.delta2,
sankey = True if proportional and show_pairs else False,
)

# Initialise the figure.
Expand All @@ -165,7 +166,7 @@ def effectsize_df_plotter(effectsize_df: object, **plot_kwargs) -> matplotlib.fi
show_pairs = show_pairs,
proportional = proportional,
float_contrast = float_contrast,
effect_size_type = effect_size_type,
effect_size_type = effect_size,
yvar = yvar,
horizontal = horizontal,
show_table = table_kwargs['show']
Expand Down Expand Up @@ -197,7 +198,8 @@ def effectsize_df_plotter(effectsize_df: object, **plot_kwargs) -> matplotlib.fi

# Add delta dots to the contrast axes for paired plots.
show_delta_dots = plot_kwargs["delta_dot"]
if show_delta_dots and is_paired is not None:
unavailable_effect_sizes = ["hedges_g", "delta_g", "cohens_d"]
if show_delta_dots and is_paired and not any([es in effect_size for es in unavailable_effect_sizes]):
DeltaDotsPlotter(
plot_data = plot_data,
contrast_axes = contrast_axes,
Expand Down Expand Up @@ -423,7 +425,7 @@ def effectsize_df_plotter(effectsize_df: object, **plot_kwargs) -> matplotlib.fi
if float_contrast and not horizontal:
# For Gardner-Altman plots only.
Gardner_Altman_Plot_Aesthetic_Adjustments(
effect_size_type = effect_size_type,
effect_size_type = effect_size,
plot_data = plot_data,
xvar = xvar,
yvar = yvar,
Expand Down
66 changes: 62 additions & 4 deletions nbs/API/delta_objects.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,29 @@
" dictionary.\n",
" \"\"\"\n",
" # Only get public (user-facing) attributes.\n",
" attrs = [a for a in dir(self) if not a.startswith((\"_\", \"to_dict\"))]\n",
" attrs = [a for a in dir(self) if not a.startswith((\"_\", \"to_dict\", \"results\"))]\n",
" out = {}\n",
" for a in attrs:\n",
" out[a] = getattr(self, a)\n",
" return out\n",
" \n",
" def __compute_results(self):\n",
" # With some inspiration from @jungyangliao\n",
" delta_delta_results_df = pd.Series(self.to_dict()).to_frame().T\n",
"\n",
" column_index = ['control', 'test', 'difference', 'ci', 'bca_low', 'bca_high', 'bca_interval_idx', \n",
" 'pct_low', 'pct_high', 'pct_interval_idx', 'bootstraps_control', 'bootstraps_test', \n",
" 'bootstraps_delta_delta', 'permutations_control', 'permutations_test', 'permutations_delta_delta',\n",
" 'pvalue_permutation', 'permutation_count', 'bias_correction', 'jackknives'\n",
" ]\n",
" delta_delta_results_df['bootstraps_control'] = [delta_delta_results_df['bootstraps'][0][0]]\n",
" delta_delta_results_df['bootstraps_test'] = [delta_delta_results_df['bootstraps'][0][1]]\n",
" delta_delta_results_df['permutations_control'] = [delta_delta_results_df['permutations'][0][0]]\n",
" delta_delta_results_df['permutations_test'] = [delta_delta_results_df['permutations'][0][1]]\n",
" delta_delta_results_df = delta_delta_results_df.reindex(columns=column_index)\n",
"\n",
" self.__results = delta_delta_results_df\n",
" return self.__results\n",
"\n",
" @property\n",
" def ci(self):\n",
Expand Down Expand Up @@ -411,7 +429,18 @@
" return self.__permutations_delta_delta\n",
" except AttributeError:\n",
" self.__permutation_test()\n",
" return self.__permutations_delta_delta"
" return self.__permutations_delta_delta\n",
" \n",
" @property\n",
" def results(self):\n",
" \"\"\"\n",
" Return the results of the delta-delta analysis.\n",
" \"\"\"\n",
" try:\n",
" return self.__results\n",
" except AttributeError:\n",
" self.__compute_results()\n",
" return self.__results"
]
},
{
Expand Down Expand Up @@ -715,11 +744,30 @@
" \"\"\"\n",
" # Only get public (user-facing) attributes.\n",
" attrs = [a for a in dir(self)\n",
" if not a.startswith((\"_\", \"to_dict\"))]\n",
" if not a.startswith((\"_\", \"to_dict\", \"results\"))]\n",
" out = {}\n",
" for a in attrs:\n",
" out[a] = getattr(self, a)\n",
" return out\n",
" \n",
"\n",
" def __compute_results(self):\n",
" # With some inspiration from @jungyangliao\n",
" \"\"\"\n",
" Returns all attributes of the `dabest.MiniMetaDelta` object as a\n",
" DataFrame.\n",
" \"\"\"\n",
" mini_meta_delta_results_df = pd.Series(self.to_dict()).to_frame().T\n",
" column_index = ['control', 'test', 'control_N', 'test_N', 'control_var', 'test_var', 'group_var',\n",
" 'difference', 'ci', 'bca_low', 'bca_high', 'bca_interval_idx', \n",
" 'pct_low', 'pct_high', 'pct_interval_idx', 'bootstraps', 'bootstraps_weighted_delta', \n",
" 'permutations', 'permutations_var', 'permutations_weighted_delta', 'pvalue_permutation', \n",
" 'permutation_count', 'bias_correction', 'jackknives']\n",
" mini_meta_delta_results_df = mini_meta_delta_results_df.reindex(columns=column_index)\n",
" mini_meta_delta_results_df.rename(columns={'bootstraps': 'bootstraps_deltas'}, inplace=True)\n",
"\n",
" self.__results = mini_meta_delta_results_df\n",
" return self.__results\n",
"\n",
"\n",
" @property\n",
Expand Down Expand Up @@ -940,7 +988,17 @@
" except AttributeError:\n",
" self.__permutation_test()\n",
" return self.__permutations_weighted_delta\n",
"\n"
"\n",
" @property\n",
" def results(self):\n",
" \"\"\"\n",
" Return the results of the mini-meta analysis.\n",
" \"\"\"\n",
" try:\n",
" return self.__results\n",
" except AttributeError:\n",
" self.__compute_results()\n",
" return self.__results"
]
},
{
Expand Down
13 changes: 10 additions & 3 deletions nbs/API/misc_tools.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@
" # Disable Gardner-Altman plotting if any of the idxs comprise of more than\n",
" # two groups or if it is a delta-delta plot.\n",
" float_contrast = plot_kwargs[\"float_contrast\"]\n",
" effect_size_type = effectsize_df.effect_size\n",
" # effect_size_type = effectsize_df.effect_size\n",
" if len(idx) > 1 or len(idx[0]) > 2:\n",
" float_contrast = False\n",
"\n",
" if effect_size_type in [\"cliffs_delta\"]:\n",
" if effect_size in [\"cliffs_delta\"]:\n",
" float_contrast = False\n",
"\n",
" if show_delta2 or show_mini_meta:\n",
Expand Down Expand Up @@ -229,7 +229,7 @@
" show_baseline_ec = plot_kwargs[\"show_baseline_ec\"]\n",
" \n",
" return (dabest_obj, plot_data, xvar, yvar, is_paired, effect_size, proportional, all_plot_groups, idx, \n",
" show_delta2, show_mini_meta, float_contrast, show_pairs, effect_size_type, group_summaries, err_color, horizontal,\n",
" show_delta2, show_mini_meta, float_contrast, show_pairs, group_summaries, err_color, horizontal,\n",
" results, halfviolin_alpha, ci_type, x1_level, experiment_label, show_baseline_ec)\n",
"\n",
"def get_kwargs(\n",
Expand Down Expand Up @@ -539,6 +539,7 @@
" idx: list, \n",
" all_plot_groups: list,\n",
" delta2: bool,\n",
" sankey: bool\n",
" ):\n",
" \"\"\"\n",
" Create the color palette to be used in the plotter function.\n",
Expand All @@ -559,6 +560,8 @@
" A list of all the group names.\n",
" delta2 : bool\n",
" A boolean flag to determine if the plot will have a delta-delta effect size.\n",
" sankey : bool\n",
" A boolean flag to determine if the plot is for a Sankey diagram.\n",
" \"\"\"\n",
" # Create color palette that will be shared across subplots.\n",
" color_col = plot_kwargs[\"color_col\"]\n",
Expand Down Expand Up @@ -613,6 +616,10 @@
" groups_in_palette = {\n",
" k: custom_pal[k] for k in color_groups\n",
" }\n",
" elif sankey:\n",
" groups_in_palette = {\n",
" k: custom_pal[k] for k in [1, 0]\n",
" }\n",
" elif color_col is None:\n",
" groups_in_palette = {\n",
" k: custom_pal[k] for k in all_plot_groups if k in color_groups\n",
Expand Down
Loading
Loading