|
75 | 75 | "def load_plot_data(\n", |
76 | 76 | " data: List, \n", |
77 | 77 | " effect_size: str = \"mean_diff\", \n", |
78 | | - " contrast_type: str = 'delta2',\n", |
| 78 | + " contrast_type: str = None,\n", |
79 | 79 | " idx: Optional[List[int]] = None\n", |
80 | 80 | ") -> List:\n", |
81 | 81 | " \"\"\"\n", |
|
88 | 88 | " effect_size: str\n", |
89 | 89 | " Type of effect size ('mean_diff', 'median_diff', etc.).\n", |
90 | 90 | " contrast_type: str\n", |
91 | | - " Type of dabest object to plot ('delta2' or 'mini-meta')\n", |
| 91 | + " Type of dabest object to plot ('delta2' or 'mini-meta' or 'delta').\n", |
92 | 92 | " idx: Optional[List[int]], default=None\n", |
93 | 93 | " List of indices to select from the contrast objects if delta-delta experiment. \n", |
94 | 94 | " If None, only the delta-delta objects are plotted.\n", |
|
99 | 99 | " \"\"\"\n", |
100 | 100 | " # Effect size and contrast types\n", |
101 | 101 | " effect_attr = \"hedges_g\" if effect_size == 'delta_g' else effect_size\n", |
102 | | - " contrast_attr = {\"delta2\": \"delta_delta\", \"mini_meta\": \"mini_meta\"}.get(contrast_type)\n", |
103 | 102 | "\n", |
104 | | - " if idx is not None:\n", |
105 | | - " bootstraps, differences, bcalows, bcahighs = [], [], [], []\n", |
106 | | - " for current_idx, index_group in enumerate(idx):\n", |
107 | | - " current_contrast = data[current_idx]\n", |
108 | | - " if len(index_group)>0:\n", |
109 | | - " for index in index_group:\n", |
110 | | - " if index == 2:\n", |
111 | | - " current_plot_data = getattr(getattr(current_contrast, effect_attr), contrast_attr)\n", |
112 | | - " bootstraps.append(current_plot_data.bootstraps_delta_delta)\n", |
113 | | - " differences.append(current_plot_data.difference)\n", |
114 | | - " bcalows.append(current_plot_data.bca_low)\n", |
115 | | - " bcahighs.append(current_plot_data.bca_high)\n", |
116 | | - " elif index == 0 or index == 1:\n", |
| 103 | + " if contrast_type == \"delta\":\n", |
| 104 | + " if idx is not None:\n", |
| 105 | + " bootstraps, differences, bcalows, bcahighs = [], [], [], []\n", |
| 106 | + " for current_idx, index_group in enumerate(idx):\n", |
| 107 | + " current_contrast = data[current_idx]\n", |
| 108 | + " if len(index_group)>0:\n", |
| 109 | + " for index in index_group:\n", |
117 | 110 | " current_plot_data = getattr(current_contrast, effect_attr)\n", |
118 | 111 | " bootstraps.append(current_plot_data.results.bootstraps[index])\n", |
119 | 112 | " differences.append(current_plot_data.results.difference[index])\n", |
120 | 113 | " bcalows.append(current_plot_data.results.bca_low[index])\n", |
121 | 114 | " bcahighs.append(current_plot_data.results.bca_high[index])\n", |
122 | | - " else:\n", |
123 | | - " raise ValueError(\"The selected indices must be 0, 1, or 2.\")\n", |
| 115 | + " else:\n", |
| 116 | + " contrast_plot_data = [getattr(contrast, effect_attr) for contrast in data]\n", |
| 117 | + " bootstraps_nested = [result.results.bootstraps.to_list() for result in contrast_plot_data]\n", |
| 118 | + " differences_nested = [result.results.difference.to_list() for result in contrast_plot_data]\n", |
| 119 | + " bcalows_nested = [result.results.bca_low.to_list() for result in contrast_plot_data]\n", |
| 120 | + " bcahighs_nested = [result.results.bca_high.to_list() for result in contrast_plot_data]\n", |
| 121 | + " \n", |
| 122 | + " bootstraps = [element for innerList in bootstraps_nested for element in innerList]\n", |
| 123 | + " differences = [element for innerList in differences_nested for element in innerList]\n", |
| 124 | + " bcalows = [element for innerList in bcalows_nested for element in innerList]\n", |
| 125 | + " bcahighs = [element for innerList in bcahighs_nested for element in innerList]\n", |
124 | 126 | " else:\n", |
125 | | - " contrast_plot_data = [getattr(getattr(contrast, effect_attr), contrast_attr) for contrast in data]\n", |
| 127 | + " contrast_attr = {\"delta2\": \"delta_delta\", \"mini_meta\": \"mini_meta\"}.get(contrast_type)\n", |
| 128 | + " if idx is not None:\n", |
| 129 | + " bootstraps, differences, bcalows, bcahighs = [], [], [], []\n", |
| 130 | + " for current_idx, index_group in enumerate(idx):\n", |
| 131 | + " current_contrast = data[current_idx]\n", |
| 132 | + " if len(index_group)>0:\n", |
| 133 | + " for index in index_group:\n", |
| 134 | + " if index == 2:\n", |
| 135 | + " current_plot_data = getattr(getattr(current_contrast, effect_attr), contrast_attr)\n", |
| 136 | + " bootstraps.append(current_plot_data.bootstraps_delta_delta)\n", |
| 137 | + " differences.append(current_plot_data.difference)\n", |
| 138 | + " bcalows.append(current_plot_data.bca_low)\n", |
| 139 | + " bcahighs.append(current_plot_data.bca_high)\n", |
| 140 | + " elif index == 0 or index == 1:\n", |
| 141 | + " current_plot_data = getattr(current_contrast, effect_attr)\n", |
| 142 | + " bootstraps.append(current_plot_data.results.bootstraps[index])\n", |
| 143 | + " differences.append(current_plot_data.results.difference[index])\n", |
| 144 | + " bcalows.append(current_plot_data.results.bca_low[index])\n", |
| 145 | + " bcahighs.append(current_plot_data.results.bca_high[index])\n", |
| 146 | + " else:\n", |
| 147 | + " raise ValueError(\"The selected indices must be 0, 1, or 2.\")\n", |
| 148 | + " else:\n", |
| 149 | + " contrast_plot_data = [getattr(getattr(contrast, effect_attr), contrast_attr) for contrast in data]\n", |
126 | 150 | "\n", |
127 | | - " attribute_suffix = \"weighted_delta\" if contrast_type == \"mini_meta\" else \"delta_delta\"\n", |
| 151 | + " attribute_suffix = \"weighted_delta\" if contrast_type == \"mini_meta\" else \"delta_delta\"\n", |
128 | 152 | "\n", |
129 | | - " bootstraps = [getattr(result, f\"bootstraps_{attribute_suffix}\") for result in contrast_plot_data]\n", |
130 | | - " differences = [result.difference for result in contrast_plot_data]\n", |
131 | | - " bcalows = [result.bca_low for result in contrast_plot_data]\n", |
132 | | - " bcahighs = [result.bca_high for result in contrast_plot_data]\n", |
| 153 | + " bootstraps = [getattr(result, f\"bootstraps_{attribute_suffix}\") for result in contrast_plot_data]\n", |
| 154 | + " differences = [result.difference for result in contrast_plot_data]\n", |
| 155 | + " bcalows = [result.bca_low for result in contrast_plot_data]\n", |
| 156 | + " bcahighs = [result.bca_high for result in contrast_plot_data]\n", |
133 | 157 | "\n", |
134 | 158 | " return bootstraps, differences, bcalows, bcahighs\n", |
135 | 159 | "\n", |
|
162 | 186 | " raise ValueError(\"The `data` argument must be a non-empty list of dabest objects.\")\n", |
163 | 187 | " \n", |
164 | 188 | " ## Check if all contrasts are delta-delta or all are mini-meta\n", |
165 | | - " contrast_type = \"delta2\" if data[0].delta2 else \"mini_meta\"\n", |
| 189 | + "\n", |
| 190 | + " contrast_type = (\"delta2\" if data[0].delta2 \n", |
| 191 | + " else \"mini_meta\" if data[0].is_mini_meta\n", |
| 192 | + " else \"delta\"\n", |
| 193 | + " )\n", |
| 194 | + "\n", |
| 195 | + " # contrast_type = \"delta2\" if data[0].delta2 else \"mini_meta\"\n", |
166 | 196 | " for contrast in data:\n", |
167 | | - " check_contrast_type = \"delta2\" if contrast.delta2 else \"mini_meta\"\n", |
| 197 | + " check_contrast_type = (\"delta2\" if contrast.delta2 \n", |
| 198 | + " else \"mini_meta\" if contrast.is_mini_meta\n", |
| 199 | + " else \"delta\"\n", |
| 200 | + " )\n", |
168 | 201 | " if check_contrast_type != contrast_type:\n", |
169 | | - " raise ValueError(\"Each dabest object supplied must be the same experimental type (mini-meta or delta-delta)\")\n", |
| 202 | + " raise ValueError(\"Each dabest object supplied must be the same experimental type (mini-meta or delta-delta or neither.)\")\n", |
170 | 203 | "\n", |
171 | 204 | " # Idx\n", |
172 | 205 | " if idx is not None:\n", |
|
485 | 518 | " )\n", |
486 | 519 | "\n", |
487 | 520 | " # Adjust figure size based on orientation\n", |
488 | | - " number_of_curves_to_plot = sum([len(i) for i in idx]) if idx is not None else len(data)\n", |
| 521 | + " number_of_curves_to_plot = len(bootstraps)\n", |
| 522 | + " # number_of_curves_to_plot = sum([len(i) for i in idx]) if idx is not None else len(data)\n", |
489 | 523 | " if ax is not None:\n", |
490 | 524 | " fig = ax.figure\n", |
491 | 525 | " else:\n", |
|
0 commit comments