Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add results attribute for DeltaDelta and MiniMetaDelta to return attributes in a DataFrame format #150

Open
wants to merge 9 commits into
base: vnbdev
Choose a base branch
from
38 changes: 34 additions & 4 deletions dabest/_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ def __init__(self, effectsizedataframe, permutation_count,bootstraps_delta_delta
self.__bootstraps = np.array(self.__effsizedf["bootstraps"])
self.__control = self.__dabest_obj.experiment_label[0]
self.__test = self.__dabest_obj.experiment_label[1]
self.__results = pd.DataFrame({})


# Compute the bootstrap delta-delta or deltas' g and the true dela-delta based on the raw data
Expand Down Expand Up @@ -809,9 +810,8 @@ def __init__(self, effectsizedataframe, permutation_count,bootstraps_delta_delta
self.__pct_interval_idx = (pct_idx_low, pct_idx_high)
self.__pct_low = sorted_delta_delta[pct_idx_low]
self.__pct_high = sorted_delta_delta[pct_idx_high]




def __permutation_test(self):
"""
Perform a permutation test and obtain the permutation p-value
Expand Down Expand Up @@ -897,7 +897,10 @@ def to_dict(self):
for a in attrs:
out[a] = getattr(self, a)
return out


def configure_results(self, __results: pd.DataFrame, column_names):
self.__results = __results
self.__results.columns = column_names

@property
def ci(self):
Expand Down Expand Up @@ -1057,6 +1060,15 @@ def permutations_delta_delta(self):
return self.__permutations_delta_delta


@property
def results(self):
"""
Returns the attributes of the DeltaDelta object as a
Dataframe.
"""
return self.__results



# %% ../nbs/API/class.ipynb 32
class MiniMetaDelta(object):
Expand Down Expand Up @@ -1091,6 +1103,7 @@ def __init__(self, effectsizedataframe, permutation_count,
self.__test = np.array(self.__effsizedf["test"])
self.__control_N = np.array(self.__effsizedf["control_N"])
self.__test_N = np.array(self.__effsizedf["test_N"])
self.__results = pd.DataFrame({})


idx = self.__dabest_obj.idx
Expand Down Expand Up @@ -1298,6 +1311,11 @@ def to_dict(self):
for a in attrs:
out[a] = getattr(self, a)
return out

def configure_results(self, __results: pd.DataFrame, column_names):
self.__results = __results
self.__results.columns = column_names



@property
Expand Down Expand Up @@ -1519,7 +1537,13 @@ def permutations_weighted_delta(self):
self.__permutation_test()
return self.__permutations_weighted_delta


@property
def results(self):
"""
Returns the attributes of the MiniMetaDelta object as a
Dataframe.
"""
return self.__results

# %% ../nbs/API/class.ipynb 37
class TwoGroupsEffectSize(object):
Expand Down Expand Up @@ -2374,6 +2398,9 @@ def __pre_calc(self):
self.__permutation_count,
bootstraps_delta_delta,
self.__ci)
delta_delta_results_dict = self.__delta_delta.to_dict()
delta_delta_results_df = pd.DataFrame.from_dict(delta_delta_results_dict, orient='index').reset_index()
self.__delta_delta.configure_results(delta_delta_results_df, ['Attribute', 'Value'])
reprs.append(self.__delta_delta.__repr__(header=False))
elif self.__delta2 is True and self.__effect_size not in ["mean_diff", "delta_g"]:
self.__delta_delta = "Delta-delta is not supported for {}.".format(self.__effect_size)
Expand All @@ -2385,6 +2412,9 @@ def __pre_calc(self):
self.__mini_meta_delta = MiniMetaDelta(self,
self.__permutation_count,
self.__ci)
mini_meta_results_dict = self.__mini_meta_delta.to_dict()
mini_meta_results_df = pd.DataFrame.from_dict(mini_meta_results_dict, orient='index').reset_index()
self.__mini_meta_delta.configure_results(mini_meta_results_df, ['Attribute', 'Value'])
reprs.append(self.__mini_meta_delta.__repr__(header=False))
elif self.__mini_meta is True and self.__effect_size != "mean_diff":
self.__mini_meta_delta = "Weighted delta is not supported for {}.".format(self.__effect_size)
Expand Down