File size: 3,452 Bytes
06b14a4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | # Reading direction of the deviation matrix
## The matrix is asymmetric
The block the app reads from `Results Correls` is a **deviation** matrix, not a
correlation matrix. Rows are attributes (column C), columns are the same attributes
repeated as headers in row 5. Every pair therefore appears twice — once on each side
of the diagonal — and **the two cells hold different numbers**.
Measured on a real client file (P&G FemCare, 78 attributes, block `AG92:DF169`):
- mean gap between `[A,B]` and `[B,A]`: **1.37**, maximum **13.02**
- all 78 blank cells fall exactly on the diagonal, zero blanks off it
That last point matters: the blanks are precisely the self-pairs, which proves the row
and column labels are correctly aligned. The asymmetry is real data, not a parsing
error.
## The rule
**An attribute's associations are read down its own column.** For attribute `X`,
locate its column via the row-5 header and read down the attribute rows. In code:
```python
value_for(source, target) == corr_df.loc[target, source]
```
Confirmed against the client's own expectation: for `newness` (column `BI`), the
expected top 5 matches the column reading exactly, and matches the row reading for
none of the five.
## Why the previous behaviour was wrong
`build_network.py` sorts attribute names alphabetically to assign index numbers, then
used to store only the upper triangle, taking the cell whose **row** was the
alphabetically later of the two names. So which of the two values reached the graph
depended on where the English label fell in the alphabet. On the file above, **121 of
3003 pairs (4.0%) appeared or vanished** by that accident, affecting 74 of 78
attributes, and a single attribute's edge list mixed both readings.
`newness` was the reported symptom: mid-alphabet, so 43 partners were read across its
row and 34 down its column. `contains safe materials` looked fine only because it sorts
early and none of its pairs happened to straddle the threshold.
## Consequence for the data structure
The sparse map is **directed**: keys are `"source,target"`, and both directions are
stored. The same pair legitimately shows different values depending on which node is
selected — selecting `newness` shows its column value for `makes life easier` (28.3),
selecting `makes life easier` shows its own column value for `newness` (32.9).
`getCorr(i, j)` in the generated JavaScript takes `i` as the source and `j` as the
target and looks the key up directly. Both call sites already pass the source first:
level 1 uses the selected node, level 2 uses the level-1 node.
## Open questions
Deliberately deferred, to revisit with the codeowner:
- **Level 2** currently follows the same rule (each level-1 node's own column). This is
consistent, but was not independently confirmed against an expected result.
- **Undirected framing.** The UI calls this an "association network", which implies one
value per pair. Averaging the two directions would restore that at the cost of
showing neither measured value. Directional was chosen because the underlying
statistic is directional and the UI is already ego-centric.
## Related known behaviour
Blank cells in column D (Category Index) become `0`, which renders as the smallest node
labelled `(0)` and sorts last. This is **expected**: some attributes are not asked in
the category modules the index is derived from, so no value exists. Left as-is by
decision, not oversight.
|