Skip to content

Commit 99bbe6f

Browse files
authored
Merge pull request #6450 from janezd/correlations-p-values
Correlations: Add column with p-values
2 parents d055e8f + 7e3f1c0 commit 99bbe6f

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

Orange/widgets/data/owcorrelations.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -393,18 +393,24 @@ def commit(self):
393393
self.Outputs.correlations.send(None)
394394
return
395395

396-
attrs = [ContinuousVariable("Correlation"), ContinuousVariable("FDR")]
396+
attrs = [ContinuousVariable("Correlation"),
397+
ContinuousVariable("uncorrected p"),
398+
ContinuousVariable("FDR")]
397399
metas = [StringVariable("Feature 1"), StringVariable("Feature 2")]
398400
domain = Domain(attrs, metas=metas)
399401
model = self.vizrank.rank_model
400-
x = np.array([[float(model.data(model.index(row, 0), role))
401-
for role in (Qt.DisplayRole, CorrelationRank.PValRole)]
402-
for row in range(model.rowCount())])
403-
x[:, 1] = FDR(list(x[:, 1]))
402+
count = model.rowCount()
403+
index = model.index
404+
corr = np.array([float(index(row, 0).data())
405+
for row in range(count)])
406+
p = np.array([index(row, 0).data(CorrelationRank.PValRole)
407+
for row in range(count)])
408+
fdr = FDR(p)
409+
x = np.vstack((corr, p, fdr)).T
404410
# pylint: disable=protected-access
405-
m = np.array([[a.name for a in model.data(model.index(row, 0),
406-
CorrelationRank._AttrRole)]
407-
for row in range(model.rowCount())], dtype=object)
411+
m = np.array([[a.name
412+
for a in index(row, 0).data(CorrelationRank._AttrRole)]
413+
for row in range(count)], dtype=object)
408414
corr_table = Table(domain, x, metas=m)
409415
corr_table.name = "Correlations"
410416

Orange/widgets/data/tests/test_owcorrelations.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,14 @@ def test_output_correlations(self):
158158
self.assertIsInstance(correlations, Table)
159159
self.assertEqual(len(correlations), 6)
160160
self.assertEqual(len(correlations.domain.metas), 2)
161-
self.assertListEqual(["Correlation", "FDR"],
161+
self.assertListEqual(["Correlation", "uncorrected p", "FDR"],
162162
[m.name for m in correlations.domain.attributes])
163-
array = np.array([[0.963, 0], [0.872, 0], [0.818, 0], [-0.421, 0],
164-
[-0.357, 0.000009], [-0.109, 0.1827652]])
163+
array = np.array([[0.963, 0, 0],
164+
[0.872, 0, 0],
165+
[0.818, 0, 0],
166+
[-0.421, 0, 0],
167+
[-0.357, 7.52e-6, 0.000009],
168+
[-0.109, 0.1827652, 0.1827652]])
165169
npt.assert_almost_equal(correlations.X, array)
166170

167171
def test_input_changed(self):

0 commit comments

Comments
 (0)