|
105 | 105 | " \"\"\"\n", |
106 | 106 | " # Effect size and contrast types\n", |
107 | 107 | " effect_attr = \"hedges_g\" if effect_size == 'delta_g' else effect_size\n", |
| 108 | + " contrast_attr = {\"delta2\": \"delta_delta\", \"mini_meta\": \"mini_meta\"}.get(contrast_type)\n", |
108 | 109 | "\n", |
109 | | - " if contrast_type == \"delta\":\n", |
110 | | - " if idx is not None:\n", |
111 | | - " bootstraps, differences, bcalows, bcahighs = [], [], [], []\n", |
112 | | - " for current_idx, index_group in enumerate(idx):\n", |
113 | | - " current_contrast = data[current_idx]\n", |
114 | | - " if len(index_group)>0:\n", |
115 | | - " for index in index_group:\n", |
116 | | - " current_plot_data = getattr(current_contrast, effect_attr)\n", |
117 | | - " bootstraps.append(current_plot_data.results.bootstraps[index])\n", |
118 | | - " differences.append(current_plot_data.results.difference[index])\n", |
119 | | - " bcalows.append(current_plot_data.results.get(ci_type+'_low')[index])\n", |
120 | | - " bcahighs.append(current_plot_data.results.get(ci_type+'_high')[index])\n", |
121 | | - " else:\n", |
| 110 | + " # Testing\n", |
| 111 | + " if idx is not None:\n", |
| 112 | + " bootstraps, differences, bcalows, bcahighs = [], [], [], []\n", |
| 113 | + " for current_idx, index_group in enumerate(idx):\n", |
| 114 | + " current_contrast = data[current_idx]\n", |
| 115 | + " if len(index_group)>0:\n", |
| 116 | + " for index in index_group:\n", |
| 117 | + " current_plot_data = getattr(current_contrast, effect_attr)\n", |
| 118 | + " if contrast_type == 'delta2':\n", |
| 119 | + " if index == 2:\n", |
| 120 | + " current_plot_data = getattr(current_plot_data, contrast_attr)\n", |
| 121 | + " bootstrap_name, index_val = \"bootstraps_delta_delta\", 0\n", |
| 122 | + " elif index == 0 or index == 1:\n", |
| 123 | + " bootstrap_name, index_val = \"bootstraps\", index\n", |
| 124 | + " else:\n", |
| 125 | + " raise ValueError(\"The selected indices must be 0, 1, or 2.\")\n", |
| 126 | + " elif contrast_type == \"mini_meta\":\n", |
| 127 | + " num_of_groups = len(getattr(current_contrast, effect_attr).results)\n", |
| 128 | + " if index == num_of_groups:\n", |
| 129 | + " current_plot_data = getattr(getattr(current_contrast, effect_attr), contrast_attr)\n", |
| 130 | + " bootstrap_name, index_val = \"bootstraps_weighted_delta\", 0\n", |
| 131 | + " elif index < num_of_groups:\n", |
| 132 | + " bootstrap_name, index_val = \"bootstraps\", index\n", |
| 133 | + " else:\n", |
| 134 | + " msg1 = \"There are only {} groups (starting from zero) in this dabest object. \".format(num_of_groups)\n", |
| 135 | + " msg2 = \"The idx given is {}.\".format(index)\n", |
| 136 | + " raise ValueError(msg1+msg2) \n", |
| 137 | + " else: # contrast_type == 'delta'\n", |
| 138 | + " bootstrap_name, index_val = \"bootstraps\", index \n", |
| 139 | + "\n", |
| 140 | + " bootstraps.append(getattr(current_plot_data.results, bootstrap_name)[index_val])\n", |
| 141 | + " differences.append(current_plot_data.results.difference[index_val])\n", |
| 142 | + " bcalows.append(current_plot_data.results.get(ci_type+'_low')[index_val])\n", |
| 143 | + " bcahighs.append(current_plot_data.results.get(ci_type+'_high')[index_val]) \n", |
| 144 | + " else:\n", |
| 145 | + " if contrast_type == 'delta':\n", |
122 | 146 | " contrast_plot_data = [getattr(contrast, effect_attr) for contrast in data]\n", |
123 | 147 | " bootstraps_nested = [result.results.bootstraps.to_list() for result in contrast_plot_data]\n", |
124 | 148 | " differences_nested = [result.results.difference.to_list() for result in contrast_plot_data]\n", |
|
129 | 153 | " differences = [element for innerList in differences_nested for element in innerList]\n", |
130 | 154 | " bcalows = [element for innerList in bcalows_nested for element in innerList]\n", |
131 | 155 | " bcahighs = [element for innerList in bcahighs_nested for element in innerList]\n", |
132 | | - " else:\n", |
133 | | - " contrast_attr = {\"delta2\": \"delta_delta\", \"mini_meta\": \"mini_meta\"}.get(contrast_type)\n", |
134 | | - " if idx is not None:\n", |
135 | | - " bootstraps, differences, bcalows, bcahighs = [], [], [], []\n", |
136 | | - " for current_idx, index_group in enumerate(idx):\n", |
137 | | - " current_contrast = data[current_idx]\n", |
138 | | - " if len(index_group)>0:\n", |
139 | | - " for index in index_group:\n", |
140 | | - " if contrast_type == 'delta2':\n", |
141 | | - " if index == 2:\n", |
142 | | - " current_plot_data = getattr(getattr(current_contrast, effect_attr), contrast_attr)\n", |
143 | | - " bootstrap_name, index_val = \"bootstraps_delta_delta\", 0\n", |
144 | | - " elif index == 0 or index == 1:\n", |
145 | | - " current_plot_data = getattr(current_contrast, effect_attr)\n", |
146 | | - " bootstrap_name, index_val = \"bootstraps\", index\n", |
147 | | - " else:\n", |
148 | | - " raise ValueError(\"The selected indices must be 0, 1, or 2.\")\n", |
149 | | - " else:\n", |
150 | | - " num_of_groups = len(getattr(current_contrast, effect_attr).results)\n", |
151 | | - " if index == num_of_groups:\n", |
152 | | - " current_plot_data = getattr(getattr(current_contrast, effect_attr), contrast_attr)\n", |
153 | | - " bootstrap_name, index_val = \"bootstraps_weighted_delta\", 0\n", |
154 | | - " elif index < num_of_groups:\n", |
155 | | - " current_plot_data = getattr(current_contrast, effect_attr)\n", |
156 | | - " bootstrap_name, index_val = \"bootstraps\", index\n", |
157 | | - " else:\n", |
158 | | - " msg1 = \"There are only {} groups (starting from zero) in this dabest object. \".format(num_of_groups)\n", |
159 | | - " msg2 = \"The idx given is {}.\".format(index)\n", |
160 | | - " raise ValueError(msg1+msg2)\n", |
161 | | - "\n", |
162 | | - " bootstraps.append(getattr(current_plot_data.results, bootstrap_name)[index_val])\n", |
163 | | - " differences.append(current_plot_data.results.difference[index_val])\n", |
164 | | - " bcalows.append(current_plot_data.results.get(ci_type+'_low')[index_val])\n", |
165 | | - " bcahighs.append(current_plot_data.results.get(ci_type+'_high')[index_val]) \n", |
166 | | - " else:\n", |
| 156 | + "\n", |
| 157 | + " else: # contrast_type == 'delta2' or 'mini_meta'\n", |
167 | 158 | " contrast_plot_data = [getattr(getattr(contrast, effect_attr), contrast_attr) for contrast in data]\n", |
168 | 159 | " attribute_suffix = \"weighted_delta\" if contrast_type == \"mini_meta\" else \"delta_delta\"\n", |
169 | 160 | "\n", |
|
181 | 172 | " raise ValueError(\"The `data` argument must be a non-empty list of dabest objects.\")\n", |
182 | 173 | " \n", |
183 | 174 | " ## Check if all contrasts are delta-delta or all are mini-meta\n", |
184 | | - "\n", |
185 | 175 | " contrast_type = (\"delta2\" if data[0].delta2 \n", |
186 | 176 | " else \"mini_meta\" if data[0].is_mini_meta\n", |
187 | 177 | " else \"delta\"\n", |
|
459 | 449 | " else:\n", |
460 | 450 | " summary_bars_kwargs = merge_two_dicts(default_summary_bars_kwargs, summary_bars_kwargs)\n", |
461 | 451 | "\n", |
462 | | - "\n", |
463 | 452 | " return (violin_kwargs, zeroline_kwargs, marker_kwargs, errorbar_kwargs, \n", |
464 | 453 | " delta_text_kwargs, contrast_bars_kwargs, summary_bars_kwargs)\n", |
465 | 454 | "\n", |
|
0 commit comments