Skip to main content

Graph Data Quality and Missing Relationships

Graph errors propagate: one merged identity can create a false hub, one invalid endpoint can create a phantom node, and systematic missing relationships can split a connected population. Quality checks must cover the observation process as well as CSV syntax.

Prerequisites​

Complete working with NetworkX. Keep the node, edge, weight, and time-window contract beside the fixture.

Learning goals​

  • Validate node and edge identity, endpoint membership, weights, timestamps, and duplicate policy.
  • Separate valid, missing, and malformed relationship records.
  • Explain how observation and sampling mechanisms bias graph structure.
  • Preserve rejected-record evidence without inserting invalid edges.

Quality dimensions for relational data​

Start with checks that correspond to the declared model:

  1. Identity: node IDs and relationship IDs are present and unique at their declared grain.
  2. Referential integrity: every accepted endpoint names a declared node.
  3. Attribute validity: weights follow the domain rule; timestamps parse and fall inside the observation window.
  4. Multiplicity: repeated endpoint pairs remain separate when edge identity is event-level.
  5. Coverage: nodes or edges may be absent because the collection system could not observe them.
  6. Provenance: rejected and transformed records retain reasons and source context.

The fixture has one missing record whose target was not recorded and two malformed records: an unknown target and a nonpositive weight. None becomes an edge. A missing relationship is not a negative edge, and absence of an edge is not evidence that two people did not interact.

Worked example​

import csv
from pathlib import Path

fixture = Path("tests/fixtures/graph-data-science")
with (fixture / "interaction-nodes.csv").open(encoding="utf-8") as handle:
node_ids = {row["node_id"] for row in csv.DictReader(handle)}
with (fixture / "interaction-relationships.csv").open(encoding="utf-8") as handle:
relationships = list(csv.DictReader(handle))

accepted = []
rejected = []
for row in relationships:
valid = (
row["record_status"] == "valid"
and row["source"] in node_ids
and row["target"] in node_ids
and float(row["weight"]) > 0
)
(accepted if valid else rejected).append(row["relationship_id"])

counts = {
state: sum(row["record_status"] == state for row in relationships)
for state in ("missing", "malformed")
}
print(f"accepted={len(accepted)} missing={counts['missing']} malformed={counts['malformed']}")
print(f"rejected={sorted(rejected)} absence_is_unknown=True")

Expected output:

accepted=10 missing=1 malformed=2
rejected=['m01', 'x01', 'x02'] absence_is_unknown=True

This is a rejection contract, not an imputation strategy. Repair would require source evidence; guessing the missing target would manufacture topology.

Limitations​

  • Passing validation does not prove that the observation process covered every group, channel, or time equally.
  • Node resolution can create false merges and false splits even when every field is syntactically valid.
  • Removing malformed edges may disproportionately remove particular populations; report rejection rates by relevant source and cohort where lawful and appropriate.
  • Imputing edges is a modeling assumption and can contaminate later evaluation. Keep observed and inferred relationships distinguishable.

Practice​

Design a quality report with counts for unknown endpoints, duplicate relationship IDs, invalid weights, unparseable times, isolated declared nodes, and rejection reasons. Add one coverage question that cannot be answered from the files alone.

Next steps​

Next, make the accepted network visible through network visualization without misleading readers.

Primary sources​

Checked 2026-10-18: W3C, Data Quality Vocabulary; NetworkX, exceptions reference; NetworkX, graph functions for isolates, self-loops, and weights.