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
14 changes: 12 additions & 2 deletions dabest/_delta_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,17 +435,19 @@ def __init__(self, effectsizedataframe, permutation_count,
self.__control_N,
self.__test_var,
self.__test_N)

self.__bootstraps_variance = ci2g.calculate_bootstraps_var(self.__bootstraps)

# Compute the weighted average mean differences of the bootstrap data
# using the pooled group variances of the raw data as the inverse of
# weights
self.__bootstraps_weighted_delta = ci2g.calculate_weighted_delta(
self.__group_var,
self.__bootstraps_variance,
self.__bootstraps)

# Compute the weighted average mean difference based on the raw data
self.__difference = es.weighted_delta(np.array(self.__effsizedf["difference"]),
self.__group_var)
self.__bootstraps_variance)

sorted_weighted_deltas = npsort(self.__bootstraps_weighted_delta)

Expand Down Expand Up @@ -753,6 +755,14 @@ def group_var(self):
in order.
'''
return self.__group_var

@property
def bootstraps_var(self):
'''
Return the variances of each bootstrapped mean difference distribution
in order.
'''
return self.__bootstraps_variance


@property
Expand Down
2 changes: 2 additions & 0 deletions dabest/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
'dabest/_stats_tools/confint_2group_diff.py'),
'dabest._stats_tools.confint_2group_diff.bootstrap_indices': ( 'API/confint_2group_diff.html#bootstrap_indices',
'dabest/_stats_tools/confint_2group_diff.py'),
'dabest._stats_tools.confint_2group_diff.calculate_bootstraps_var': ( 'API/confint_2group_diff.html#calculate_bootstraps_var',
'dabest/_stats_tools/confint_2group_diff.py'),
'dabest._stats_tools.confint_2group_diff.calculate_group_var': ( 'API/confint_2group_diff.html#calculate_group_var',
'dabest/_stats_tools/confint_2group_diff.py'),
'dabest._stats_tools.confint_2group_diff.calculate_weighted_delta': ( 'API/confint_2group_diff.html#calculate_weighted_delta',
Expand Down
16 changes: 12 additions & 4 deletions dabest/_stats_tools/confint_2group_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
__all__ = ['create_jackknife_indexes', 'create_repeated_indexes', 'compute_meandiff_jackknife', 'bootstrap_indices',
'compute_bootstrapped_diff', 'delta2_bootstrap_loop', 'compute_delta2_bootstrapped_diff',
'compute_meandiff_bias_correction', 'compute_interval_limits', 'calculate_group_var',
'calculate_weighted_delta']
'calculate_bootstraps_var', 'calculate_weighted_delta']

# %% ../../nbs/API/confint_2group_diff.ipynb 4
import numpy as np
Expand Down Expand Up @@ -319,15 +319,23 @@ def calculate_group_var(control_var, control_N, test_var, test_N):

return pooled_var

def calculate_bootstraps_var(bootstraps):

def calculate_weighted_delta(group_var, differences):
bootstraps_var_list = [np.var(x, ddof=1) for x in bootstraps]
bootstraps_var_array = np.array(bootstraps_var_list)

return bootstraps_var_array



def calculate_weighted_delta(bootstrap_dist_var, differences):
"""
Compute the weighted deltas.
"""

weight = 1 / group_var
weight = np.true_divide(1, bootstrap_dist_var)
denom = np.sum(weight)
num = 0.0
for i in range(len(weight)):
num += weight[i] * differences[i]
return num / denom
return np.true_divide(num, denom)
4 changes: 2 additions & 2 deletions dabest/_stats_tools/effsize.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,11 @@ def _compute_hedges_correction_factor(n1,

# %% ../../nbs/API/effsize.ipynb 13
@njit(cache=True)
def weighted_delta(difference, group_var):
def weighted_delta(difference, bootstrap_dist_var):
'''
Compute the weighted deltas where the weight is the inverse of the
pooled group difference.
'''

weight = np.true_divide(1, group_var)
weight = np.true_divide(1, bootstrap_dist_var)
return np.sum(difference*weight)/np.sum(weight)
8 changes: 4 additions & 4 deletions dabest/misc_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ def initialize_fig(
raw_label = plot_kwargs["raw_label"]
if raw_label is None:
if proportional:
raw_label = "Proportion of Success" if effect_size_type != "cohens_h" else "Value"
raw_label = "Proportion of success" if effect_size_type != "cohens_h" else "Value"
else:
raw_label = yvar

Expand All @@ -951,16 +951,16 @@ def initialize_fig(

# Set contrast axes y-label.
contrast_label_dict = {
"mean_diff": "Mean Difference",
"median_diff": "Median Difference",
"mean_diff": "Mean difference",
"median_diff": "Median difference",
"cohens_d": "Cohen's d",
"hedges_g": "Hedges' g",
"cliffs_delta": "Cliff's delta",
"cohens_h": "Cohen's h",
}

if proportional and effect_size_type != "cohens_h":
default_contrast_label = "Proportion Difference"
default_contrast_label = "Proportion difference"
else:
default_contrast_label = contrast_label_dict[effect_size_type]

Expand Down
12 changes: 6 additions & 6 deletions dabest/plot_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1333,31 +1333,31 @@ def extract_curve_data(dabest_object):
if horizontal:
current_ylabels = rawdata_axes.get_yticklabels()
if type == 'mini_meta':
current_ylabels.extend(["Weighted Delta"])
current_ylabels.extend(["Weighted delta"])
elif effect_size == "hedges_g":
current_ylabels.extend(["Delta g"])
else:
current_ylabels.extend(["Delta-Delta"])
current_ylabels.extend(["Delta-delta"])

rawdata_axes.set_yticks(np.append(rawdata_axes.get_yticks(), position))
rawdata_axes.set_yticklabels(current_ylabels)
else:
if type == 'mini_meta':
if show_pairs:
contrast_xtick_labels.extend(["Weighted\n Delta"])
contrast_xtick_labels.extend(["Weighted\n delta"])
else:
contrast_xtick_labels.extend(["Weighted Delta"])
contrast_xtick_labels.extend(["Weighted delta"])
elif effect_size == "hedges_g":
contrast_xtick_labels.extend(["Delta g"])
else:
contrast_xtick_labels.extend(["Delta-Delta"])
contrast_xtick_labels.extend(["Delta-delta"])

# Create the delta-delta axes.
if type == 'delta_delta' and not horizontal:
if plot_kwargs["delta2_label"] is not None:
delta2_label = plot_kwargs["delta2_label"]
elif effect_size == "mean_diff":
delta2_label = "Delta-Delta"
delta2_label = "Delta-delta"
else:
delta2_label = "Delta g"
fontsize_delta2label = plot_kwargs["fontsize_delta2label"]
Expand Down
14 changes: 11 additions & 3 deletions nbs/API/confint_2group_diff.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -373,18 +373,26 @@
" \n",
" return pooled_var\n",
"\n",
"def calculate_bootstraps_var(bootstraps):\n",
"\n",
"def calculate_weighted_delta(group_var, differences):\n",
" bootstraps_var_list = [np.var(x, ddof=1) for x in bootstraps]\n",
" bootstraps_var_array = np.array(bootstraps_var_list)\n",
" \n",
" return bootstraps_var_array\n",
" \n",
"\n",
"\n",
"def calculate_weighted_delta(bootstrap_dist_var, differences):\n",
" \"\"\"\n",
" Compute the weighted deltas.\n",
" \"\"\"\n",
"\n",
" weight = 1 / group_var\n",
" weight = np.true_divide(1, bootstrap_dist_var)\n",
" denom = np.sum(weight)\n",
" num = 0.0\n",
" for i in range(len(weight)):\n",
" num += weight[i] * differences[i]\n",
" return num / denom"
" return np.true_divide(num, denom)"
]
}
],
Expand Down
77 changes: 68 additions & 9 deletions nbs/API/delta_objects.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions nbs/API/effsize.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -507,13 +507,13 @@
"source": [
"#| export\n",
"@njit(cache=True)\n",
"def weighted_delta(difference, group_var):\n",
"def weighted_delta(difference, bootstrap_dist_var):\n",
" '''\n",
" Compute the weighted deltas where the weight is the inverse of the\n",
" pooled group difference.\n",
" '''\n",
"\n",
" weight = np.true_divide(1, group_var)\n",
" weight = np.true_divide(1, bootstrap_dist_var)\n",
" return np.sum(difference*weight)/np.sum(weight)"
]
}
Expand Down
2 changes: 1 addition & 1 deletion nbs/API/effsize_objects.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2403,5 +2403,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
8 changes: 4 additions & 4 deletions nbs/API/misc_tools.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@
" raw_label = plot_kwargs[\"raw_label\"]\n",
" if raw_label is None:\n",
" if proportional:\n",
" raw_label = \"Proportion of Success\" if effect_size_type != \"cohens_h\" else \"Value\"\n",
" raw_label = \"Proportion of success\" if effect_size_type != \"cohens_h\" else \"Value\"\n",
" else:\n",
" raw_label = yvar \n",
"\n",
Expand All @@ -1004,16 +1004,16 @@
"\n",
" # Set contrast axes y-label.\n",
" contrast_label_dict = {\n",
" \"mean_diff\": \"Mean Difference\",\n",
" \"median_diff\": \"Median Difference\",\n",
" \"mean_diff\": \"Mean difference\",\n",
" \"median_diff\": \"Median difference\",\n",
" \"cohens_d\": \"Cohen's d\",\n",
" \"hedges_g\": \"Hedges' g\",\n",
" \"cliffs_delta\": \"Cliff's delta\",\n",
" \"cohens_h\": \"Cohen's h\",\n",
" }\n",
"\n",
" if proportional and effect_size_type != \"cohens_h\":\n",
" default_contrast_label = \"Proportion Difference\"\n",
" default_contrast_label = \"Proportion difference\"\n",
" else:\n",
" default_contrast_label = contrast_label_dict[effect_size_type]\n",
"\n",
Expand Down
12 changes: 6 additions & 6 deletions nbs/API/plot_tools.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1384,31 +1384,31 @@
" if horizontal:\n",
" current_ylabels = rawdata_axes.get_yticklabels()\n",
" if type == 'mini_meta':\n",
" current_ylabels.extend([\"Weighted Delta\"])\n",
" current_ylabels.extend([\"Weighted delta\"])\n",
" elif effect_size == \"hedges_g\":\n",
" current_ylabels.extend([\"Delta g\"])\n",
" else:\n",
" current_ylabels.extend([\"Delta-Delta\"])\n",
" current_ylabels.extend([\"Delta-delta\"])\n",
"\n",
" rawdata_axes.set_yticks(np.append(rawdata_axes.get_yticks(), position))\n",
" rawdata_axes.set_yticklabels(current_ylabels)\n",
" else:\n",
" if type == 'mini_meta':\n",
" if show_pairs:\n",
" contrast_xtick_labels.extend([\"Weighted\\n Delta\"])\n",
" contrast_xtick_labels.extend([\"Weighted\\n delta\"])\n",
" else:\n",
" contrast_xtick_labels.extend([\"Weighted Delta\"])\n",
" contrast_xtick_labels.extend([\"Weighted delta\"])\n",
" elif effect_size == \"hedges_g\":\n",
" contrast_xtick_labels.extend([\"Delta g\"])\n",
" else:\n",
" contrast_xtick_labels.extend([\"Delta-Delta\"])\n",
" contrast_xtick_labels.extend([\"Delta-delta\"])\n",
"\n",
" # Create the delta-delta axes.\n",
" if type == 'delta_delta' and not horizontal:\n",
" if plot_kwargs[\"delta2_label\"] is not None:\n",
" delta2_label = plot_kwargs[\"delta2_label\"]\n",
" elif effect_size == \"mean_diff\":\n",
" delta2_label = \"Delta-Delta\"\n",
" delta2_label = \"Delta-delta\"\n",
" else:\n",
" delta2_label = \"Delta g\"\n",
" fontsize_delta2label = plot_kwargs[\"fontsize_delta2label\"]\n",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified nbs/tests/mpl_image_tests/baseline_images/test_113_desat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified nbs/tests/mpl_image_tests/baseline_images/test_115_invert_ylim.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified nbs/tests/mpl_image_tests/baseline_images/test_117_err_color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified nbs/tests/mpl_image_tests/baseline_images/test_119_wide_df_nan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified nbs/tests/mpl_image_tests/baseline_images/test_11_inset_plots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified nbs/tests/mpl_image_tests/baseline_images/test_120_long_df_nan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified nbs/tests/mpl_image_tests/baseline_images/test_130_zero_to_one.png
Binary file modified nbs/tests/mpl_image_tests/baseline_images/test_131_one_to_zero.png
Binary file modified nbs/tests/mpl_image_tests/baseline_images/test_18_desat.png
Binary file modified nbs/tests/mpl_image_tests/baseline_images/test_19_dot_sizes.png
Binary file modified nbs/tests/mpl_image_tests/baseline_images/test_20_change_ylims.png
Binary file modified nbs/tests/mpl_image_tests/baseline_images/test_24_wide_df_nan.png
Binary file modified nbs/tests/mpl_image_tests/baseline_images/test_325_wide_df_nan.png
Binary file modified nbs/tests/mpl_image_tests/baseline_images/test_326_long_df_nan.png
Binary file modified nbs/tests/mpl_image_tests/baseline_images/test_99_style_sheets.png
Loading