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

[ENH] BoxPlot: Write the anova/t-test statistic onto the plot. #3945

Merged
merged 3 commits into from
Aug 2, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions Orange/widgets/visualize/owboxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ def __init__(self):

self.mainArea.layout().addWidget(self.box_view)

e = gui.hBox(self.mainArea, addSpace=False)
self.infot1 = gui.widgetLabel(e, "<center>No test results.</center>")
gui.hBox(self.mainArea, addSpace=False)
self.stat_test = ""
self.mainArea.setMinimumWidth(300)

self.stats = self.dist = self.conts = []
Expand Down Expand Up @@ -380,7 +380,7 @@ def compute_score(attr):

def reset_all_data(self):
self.clear_scene()
self.infot1.setText("")
self.stat_test = ""
self.attrs.clear()
self.group_vars.set_domain(None)
self.group_view.setEnabled(False)
Expand Down Expand Up @@ -494,6 +494,7 @@ def layout_changed(self):
for it in chain(self.labels, self.attr_labels):
self.box_scene.addItem(it)
self.display_changed()
self.draw_stat()

def display_changed(self):
if self.dataset is None:
Expand Down Expand Up @@ -597,7 +598,7 @@ def display_changed_disc(self):
self.box_scene.setSceneRect(-self.label_width - 5,
-30 - len(self.boxes) * 40,
self.scene_width, len(self.boxes * 40) + 90)
self.infot1.setText("")
self.stat_test = ""
self.select_box_items()

def __draw_group_labels(self, y, row):
Expand Down Expand Up @@ -712,6 +713,7 @@ def stat_ANOVA():
p = 1 - scipy.special.fdtr(df_between, df_within, F)
return F, p

n = len(self.dataset)
if self.compare == OWBoxPlot.CompareNone or len(self.stats) < 2:
t = ""
elif any(s.n <= 1 for s in self.stats):
Expand All @@ -725,16 +727,16 @@ def stat_ANOVA():
# t = "Mann-Whitney's z: %.1f (p=%.3f)" % (z, p)
else:
t, p = stat_ttest()
t = "" if np.isnan(t) else f"Student's t: {t:.3f} (p={p:.3f})"
t = "" if np.isnan(t) else f"Student's t: {t:.3f} (p={p:.3f}, N={n})"
else:
if self.compare == OWBoxPlot.CompareMedians:
t = ""
# U, p = -1, -1
# t = "Kruskal Wallis's U: %.1f (p=%.3f)" % (U, p)
else:
F, p = stat_ANOVA()
t = "" if np.isnan(F) else f"ANOVA: {F:.3f} (p={p:.3f})"
self.infot1.setText("<center>%s</center>" % t)
t = "" if np.isnan(F) else f"ANOVA: {F:.3f} (p={p:.3f}, N={n})"
self.stat_test = t

def mean_label(self, stat, attr, val_name):
label = QGraphicsItemGroup()
Expand Down Expand Up @@ -816,6 +818,15 @@ def draw_axis(self):
self.box_scene.addLine(
bottom * scale_x - 4, 0, top * scale_x + 4, 0, self._pen_axis)

def draw_stat(self):
if self.stat_test:
l = QGraphicsSimpleTextItem(self.stat_test)
thocevar marked this conversation as resolved.
Show resolved Hide resolved
l.setFont(self._axis_font)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text does not render correctly on my machine -- small parentheses, and no ' in "Student's".

Screenshot 2019-07-31 at 16 10 50

It works (and also looks OK) if I remove setFont.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our _axis_font, which is just the default (_axis_font = QFont()), doesn't display some characters nicely? This is bad.

l.setPos((self.scene_min_x + self.scene_max_x)/2 - l.boundingRect().width()/2,
8 + self._axis_font.pixelSize()*2)
l.setFlags(l.flags() | QGraphicsItem.ItemIgnoresTransformations)
thocevar marked this conversation as resolved.
Show resolved Hide resolved
self.box_scene.addItem(l)

def draw_axis_disc(self):
"""
Draw the horizontal axis and sets self.scale_x for discrete attributes
Expand Down