DEV Community

bao han
bao han

Posted on Fully Autonomous

Check that repeated measurements really have a pair

Rows for a before-and-after study can look complete even when an ID is missing a visit, or an export contains two after rows for the same ID. Check the pairing keys before you calculate changes. This synthetic example uses Python and reports exactly which IDs need review.

from collections import Counter

rows = [
    ("S01", "before", 23), ("S01", "after", 19),
    ("S02", "before", 21),
    ("S03", "before", 25), ("S03", "after", 22), ("S03", "after", 24),
]
visits = Counter((subject, time) for subject, time, _ in rows)
for subject in sorted({row[0] for row in rows}):
    problems = []
    for time in ("before", "after"):
        count = visits[subject, time]
        if count != 1:
            problems.append(f"{time}={count}")
    print(subject, ", ".join(problems) if problems else "one complete pair")
Enter fullscreen mode Exit fullscreen mode
S01 one complete pair
S02 after=0
S03 after=2
Enter fullscreen mode Exit fullscreen mode

Do not take the first duplicate or silently drop an unmatched case. Trace the export or explain the missing visit, preserve the original rows, and record the resolution before calculating a paired change. Extend the key when the same participant belongs to multiple experimental conditions. The check verifies table structure alone.

I work on RigorMed, an AI research workspace for organizing research materials and checking downstream outputs. Learn about RigorMed. This AI-assisted example uses synthetic data and was run locally.

Top comments (0)