Skip to content

Commit 5df90f8

Browse files
committed
Bug fix and zero-dot effect size for baseline
Fixed a bug where some baseline line error curve for certain controls are wrongly plotted as the previous one. The implementation is a bit different from dabestr becuase R allows nesting DataFrame where Python doesn’t.
1 parent 994003c commit 5df90f8

File tree

86 files changed

+60
-38
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+60
-38
lines changed

dabest/plot_tools.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,15 +1292,6 @@ def plot_effect_size(tick, group, control, bootstrap, effsize, ci_low, ci_high):
12921292
fc = plot_palette_contrast[group] if bootstraps_color_by_group else "grey"
12931293
halfviolin(v, fill_color=fc, alpha=halfviolin_alpha)
12941294

1295-
# Plot the effect size
1296-
contrast_axes.plot(
1297-
[tick],
1298-
effsize,
1299-
marker="o",
1300-
color=ytick_color,
1301-
markersize=es_marker_size,
1302-
)
1303-
13041295
# Plot the confidence interval
13051296
contrast_axes.plot(
13061297
[tick, tick],
@@ -1320,21 +1311,41 @@ def plot_effect_size(tick, group, control, bootstrap, effsize, ci_low, ci_high):
13201311
current_effsize = results.difference[j]
13211312
current_ci_low = results.bca_low[j] if ci_type == "bca" else results.pct_low[j]
13221313
current_ci_high = results.bca_high[j] if ci_type == "bca" else results.pct_high[j]
1314+
1315+
# Plot the effect size
1316+
contrast_axes.plot(
1317+
[tick],
1318+
current_effsize,
1319+
marker="o",
1320+
color=ytick_color,
1321+
markersize=es_marker_size,
1322+
)
13231323

13241324
label = plot_effect_size(tick, current_group, current_control, current_bootstrap,
13251325
current_effsize, current_ci_low, current_ci_high)
13261326
contrast_xtick_labels.append(label)
13271327

1328-
if show_baseline_ec:
1329-
for j, tick in enumerate(ticks_for_baseline_ec):
1330-
bec_group = results.control[j]
1331-
bec_control = results.control[j]
1332-
bec_bootstrap = results.bec_bootstraps[j]
1333-
bec_effsize = results.bec_difference[j]
1334-
bec_ci_low = results.bec_bca_low[j] if ci_type == "bca" else results.bec_pct_low[j]
1335-
bec_ci_high = results.bec_bca_high[j] if ci_type == "bca" else results.bec_pct_high[j]
1336-
1337-
bec_label = plot_effect_size(tick, bec_group, bec_control, bec_bootstrap,
1328+
1329+
bec_results = results.drop_duplicates(subset='control', keep='first').reset_index(drop=True)
1330+
for j, tick in enumerate(ticks_for_baseline_ec):
1331+
bec_group = bec_results.control[j]
1332+
bec_control = bec_results.control[j]
1333+
bec_bootstrap = bec_results.bec_bootstraps[j]
1334+
bec_effsize = bec_results.bec_difference[j]
1335+
bec_ci_low = bec_results.bec_bca_low[j] if ci_type == "bca" else bec_results.bec_pct_low[j]
1336+
bec_ci_high = bec_results.bec_bca_high[j] if ci_type == "bca" else bec_results.bec_pct_high[j]
1337+
1338+
# Plot the effect size no matter show_baseline
1339+
contrast_axes.plot(
1340+
[tick],
1341+
bec_effsize,
1342+
marker="o",
1343+
color=ytick_color,
1344+
markersize=es_marker_size,
1345+
)
1346+
1347+
if show_baseline_ec:
1348+
_ = plot_effect_size(tick, bec_group, bec_control, bec_bootstrap,
13381349
bec_effsize, bec_ci_low, bec_ci_high)
13391350
# Baseline Curve don't need ticks text
13401351

nbs/API/plot_tools.ipynb

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,15 +1343,6 @@
13431343
" fc = plot_palette_contrast[group] if bootstraps_color_by_group else \"grey\"\n",
13441344
" halfviolin(v, fill_color=fc, alpha=halfviolin_alpha)\n",
13451345
"\n",
1346-
" # Plot the effect size\n",
1347-
" contrast_axes.plot(\n",
1348-
" [tick],\n",
1349-
" effsize,\n",
1350-
" marker=\"o\",\n",
1351-
" color=ytick_color,\n",
1352-
" markersize=es_marker_size,\n",
1353-
" )\n",
1354-
"\n",
13551346
" # Plot the confidence interval\n",
13561347
" contrast_axes.plot(\n",
13571348
" [tick, tick],\n",
@@ -1371,21 +1362,41 @@
13711362
" current_effsize = results.difference[j]\n",
13721363
" current_ci_low = results.bca_low[j] if ci_type == \"bca\" else results.pct_low[j]\n",
13731364
" current_ci_high = results.bca_high[j] if ci_type == \"bca\" else results.pct_high[j]\n",
1365+
" \n",
1366+
" # Plot the effect size\n",
1367+
" contrast_axes.plot(\n",
1368+
" [tick],\n",
1369+
" current_effsize,\n",
1370+
" marker=\"o\",\n",
1371+
" color=ytick_color,\n",
1372+
" markersize=es_marker_size,\n",
1373+
" )\n",
13741374
"\n",
13751375
" label = plot_effect_size(tick, current_group, current_control, current_bootstrap, \n",
13761376
" current_effsize, current_ci_low, current_ci_high)\n",
13771377
" contrast_xtick_labels.append(label)\n",
13781378
" \n",
1379-
" if show_baseline_ec:\n",
1380-
" for j, tick in enumerate(ticks_for_baseline_ec):\n",
1381-
" bec_group = results.control[j]\n",
1382-
" bec_control = results.control[j]\n",
1383-
" bec_bootstrap = results.bec_bootstraps[j]\n",
1384-
" bec_effsize = results.bec_difference[j]\n",
1385-
" bec_ci_low = results.bec_bca_low[j] if ci_type == \"bca\" else results.bec_pct_low[j]\n",
1386-
" bec_ci_high = results.bec_bca_high[j] if ci_type == \"bca\" else results.bec_pct_high[j]\n",
1387-
"\n",
1388-
" bec_label = plot_effect_size(tick, bec_group, bec_control, bec_bootstrap, \n",
1379+
"\n",
1380+
" bec_results = results.drop_duplicates(subset='control', keep='first').reset_index(drop=True)\n",
1381+
" for j, tick in enumerate(ticks_for_baseline_ec):\n",
1382+
" bec_group = bec_results.control[j]\n",
1383+
" bec_control = bec_results.control[j]\n",
1384+
" bec_bootstrap = bec_results.bec_bootstraps[j]\n",
1385+
" bec_effsize = bec_results.bec_difference[j]\n",
1386+
" bec_ci_low = bec_results.bec_bca_low[j] if ci_type == \"bca\" else bec_results.bec_pct_low[j]\n",
1387+
" bec_ci_high = bec_results.bec_bca_high[j] if ci_type == \"bca\" else bec_results.bec_pct_high[j]\n",
1388+
" \n",
1389+
" # Plot the effect size no matter show_baseline\n",
1390+
" contrast_axes.plot(\n",
1391+
" [tick],\n",
1392+
" bec_effsize,\n",
1393+
" marker=\"o\",\n",
1394+
" color=ytick_color,\n",
1395+
" markersize=es_marker_size,\n",
1396+
" )\n",
1397+
" \n",
1398+
" if show_baseline_ec:\n",
1399+
" _ = plot_effect_size(tick, bec_group, bec_control, bec_bootstrap, \n",
13891400
" bec_effsize, bec_ci_low, bec_ci_high)\n",
13901401
" # Baseline Curve don't need ticks text\n",
13911402
" \n",
372 Bytes
369 Bytes
497 Bytes
409 Bytes
372 Bytes
179 Bytes
345 Bytes
295 Bytes

0 commit comments

Comments
 (0)