|
269 | 269 | " dictionary.\n", |
270 | 270 | " \"\"\"\n", |
271 | 271 | " # Only get public (user-facing) attributes.\n", |
272 | | - " attrs = [a for a in dir(self) if not a.startswith((\"_\", \"to_dict\"))]\n", |
| 272 | + " attrs = [a for a in dir(self) if not a.startswith((\"_\", \"to_dict\", \"results\"))]\n", |
273 | 273 | " out = {}\n", |
274 | 274 | " for a in attrs:\n", |
275 | 275 | " out[a] = getattr(self, a)\n", |
276 | 276 | " return out\n", |
| 277 | + " \n", |
| 278 | + " def __compute_results(self):\n", |
| 279 | + " # With some inspiration from @jungyangliao\n", |
| 280 | + " delta_delta_results_df = pd.Series(self.to_dict()).to_frame().T\n", |
| 281 | + "\n", |
| 282 | + " column_index = ['control', 'test', 'difference', 'ci', 'bca_low', 'bca_high', 'bca_interval_idx', \n", |
| 283 | + " 'pct_low', 'pct_high', 'pct_interval_idx', 'bootstraps_control', 'bootstraps_test', \n", |
| 284 | + " 'bootstraps_delta_delta', 'permutations_control', 'permutations_test', 'permutations_delta_delta',\n", |
| 285 | + " 'pvalue_permutation', 'permutation_count', 'bias_correction', 'jackknives'\n", |
| 286 | + " ]\n", |
| 287 | + " delta_delta_results_df['bootstraps_control'] = [delta_delta_results_df['bootstraps'][0][0]]\n", |
| 288 | + " delta_delta_results_df['bootstraps_test'] = [delta_delta_results_df['bootstraps'][0][1]]\n", |
| 289 | + " delta_delta_results_df['permutations_control'] = [delta_delta_results_df['permutations'][0][0]]\n", |
| 290 | + " delta_delta_results_df['permutations_test'] = [delta_delta_results_df['permutations'][0][1]]\n", |
| 291 | + " delta_delta_results_df = delta_delta_results_df.reindex(columns=column_index)\n", |
| 292 | + "\n", |
| 293 | + " self.__results = delta_delta_results_df\n", |
| 294 | + " return self.__results\n", |
277 | 295 | "\n", |
278 | 296 | " @property\n", |
279 | 297 | " def ci(self):\n", |
|
411 | 429 | " return self.__permutations_delta_delta\n", |
412 | 430 | " except AttributeError:\n", |
413 | 431 | " self.__permutation_test()\n", |
414 | | - " return self.__permutations_delta_delta" |
| 432 | + " return self.__permutations_delta_delta\n", |
| 433 | + " \n", |
| 434 | + " @property\n", |
| 435 | + " def results(self):\n", |
| 436 | + " \"\"\"\n", |
| 437 | + " Return the results of the delta-delta analysis.\n", |
| 438 | + " \"\"\"\n", |
| 439 | + " try:\n", |
| 440 | + " return self.__results\n", |
| 441 | + " except AttributeError:\n", |
| 442 | + " self.__compute_results()\n", |
| 443 | + " return self.__results" |
415 | 444 | ] |
416 | 445 | }, |
417 | 446 | { |
|
715 | 744 | " \"\"\"\n", |
716 | 745 | " # Only get public (user-facing) attributes.\n", |
717 | 746 | " attrs = [a for a in dir(self)\n", |
718 | | - " if not a.startswith((\"_\", \"to_dict\"))]\n", |
| 747 | + " if not a.startswith((\"_\", \"to_dict\", \"results\"))]\n", |
719 | 748 | " out = {}\n", |
720 | 749 | " for a in attrs:\n", |
721 | 750 | " out[a] = getattr(self, a)\n", |
722 | 751 | " return out\n", |
| 752 | + " \n", |
| 753 | + "\n", |
| 754 | + " def __compute_results(self):\n", |
| 755 | + " # With some inspiration from @jungyangliao\n", |
| 756 | + " \"\"\"\n", |
| 757 | + " Returns all attributes of the `dabest.MiniMetaDelta` object as a\n", |
| 758 | + " DataFrame.\n", |
| 759 | + " \"\"\"\n", |
| 760 | + " mini_meta_delta_results_df = pd.Series(self.to_dict()).to_frame().T\n", |
| 761 | + " column_index = ['control', 'test', 'control_N', 'test_N', 'control_var', 'test_var', 'group_var',\n", |
| 762 | + " 'difference', 'ci', 'bca_low', 'bca_high', 'bca_interval_idx', \n", |
| 763 | + " 'pct_low', 'pct_high', 'pct_interval_idx', 'bootstraps', 'bootstraps_weighted_delta', \n", |
| 764 | + " 'permutations', 'permutations_var', 'permutations_weighted_delta', 'pvalue_permutation', \n", |
| 765 | + " 'permutation_count', 'bias_correction', 'jackknives']\n", |
| 766 | + " mini_meta_delta_results_df = mini_meta_delta_results_df.reindex(columns=column_index)\n", |
| 767 | + " mini_meta_delta_results_df.rename(columns={'bootstraps': 'bootstraps_deltas'}, inplace=True)\n", |
| 768 | + "\n", |
| 769 | + " self.__results = mini_meta_delta_results_df\n", |
| 770 | + " return self.__results\n", |
723 | 771 | "\n", |
724 | 772 | "\n", |
725 | 773 | " @property\n", |
|
940 | 988 | " except AttributeError:\n", |
941 | 989 | " self.__permutation_test()\n", |
942 | 990 | " return self.__permutations_weighted_delta\n", |
943 | | - "\n" |
| 991 | + "\n", |
| 992 | + " @property\n", |
| 993 | + " def results(self):\n", |
| 994 | + " \"\"\"\n", |
| 995 | + " Return the results of the mini-meta analysis.\n", |
| 996 | + " \"\"\"\n", |
| 997 | + " try:\n", |
| 998 | + " return self.__results\n", |
| 999 | + " except AttributeError:\n", |
| 1000 | + " self.__compute_results()\n", |
| 1001 | + " return self.__results" |
944 | 1002 | ] |
945 | 1003 | }, |
946 | 1004 | { |
|
0 commit comments