Skip to content

Commit

Permalink
Move the t-test or anova statistic from the widget onto the plot
Browse files Browse the repository at this point in the history
  • Loading branch information
thocevar committed Jul 26, 2019
1 parent 6e7e534 commit c283965
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions Orange/widgets/visualize/owboxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ 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>")
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)
l.setFont(self._axis_font)
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)
self.box_scene.addItem(l)

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

0 comments on commit c283965

Please sign in to comment.