Why Repeated Records Need Interpretation
A row that looks repeated is not necessarily redundant. Two identical rows may have been created by importing the same source record twice. But two measurements at the same collection time may instead represent distinct specimens, technical replicates, or separate records that happen to have the same measured value. Treating every repeated value or timestamp as a duplicate can erase valid information; keeping every repeated row without investigation can count one observation more than once.
The first task is therefore to determine what one row represents. In a pharmacometric data set, a row might represent a collection event, a specimen, an assay measurement, or a source-file record. The correct duplicate check depends on that intended unit, which is called the data grain. This tutorial focuses on distinguishing accidental duplication from genuine repeated samples, preserving the identifiers that make that distinction possible, and specifying checks that flag suspicious repetitions for review.
Define the Data Grain Before Defining Duplicates
A duplicate rule is meaningful only after the row’s intended meaning is specified. For example, if each row represents one assay measurement, two assay measurements from the same specimen may be legitimate rows. If each row represents one collection event, the same two measurements may belong in a separate measurement-level table rather than being treated as two collection events. The data grain should be stated in plain language, such as “one row per recorded sample measurement.”
A key is a field or combination of fields intended to identify one record at the stated grain. A source record identifier can help identify repeated imports. A sample or specimen identifier can distinguish collected material. A replicate identifier can distinguish repeated measurements of the same material. A collection-event identifier can distinguish separate collection events, including events that share a recorded time. These identifiers serve different purposes and should not be collapsed into one field.
For a measurement-level data set, one possible key might combine subject, specimen, and measurement-replicate identifiers. That choice is valid only if those fields are populated consistently and actually distinguish every intended measurement. A combination such as subject and time alone is often too coarse: it can label two legitimate same-time samples as if they were the same record. Conversely, a source-row identifier may distinguish imported records without establishing whether those records represent different biological samples.
What Repeated Values and Times Can Tell You
A repeated value is a useful signal, not a diagnosis. The same subject can have equal measurements at different times. Two separate samples collected at one time can also have equal measurements, particularly when the recorded values are rounded. And duplicate source rows can disagree if one copy was edited or transformed differently. Thus, checking only the measured value will miss some duplicates and incorrectly flag some legitimate records.
A repeated collection time is similarly ambiguous. It may occur because the data contain legitimate replicates, because separate samples were collected at the same recorded time, because time values were rounded or recorded at limited precision, or because a record was duplicated. Time should be checked in relation to subject and sample or event identifiers, not as an isolated column.
A practical check separates three questions:
- Are the source records repeated? Compare source record identifiers and the values carried by each record. An identical source identifier appearing more than once warrants review of the import or merge.
- Are the sample or measurement identifiers repeated? Check whether the proposed key is unique at the stated grain. Repeated keys may indicate duplicate rows, a missing replicate identifier, or an invalid key definition.
- Are values or times repeated within a subject? Count or list these cases and inspect sample, event, and replicate identifiers. Repetition is a review trigger, not proof of error.
These checks are complementary. A unique key does not guarantee that a record is scientifically correct, and repeated values do not establish that it is incorrect. In practice, checks should preserve enough fields to trace each flagged row to its source and should record the disposition of investigated cases.
Worked Example: Removing a Confirmed Duplicate Import
Suppose a hypothetical merge produces five measurement-level rows. The intended grain is one row per recorded measurement, and the source system supplies a stable source-record identifier.
| Subject | Time (h) | Value (mg/L) | Source record |
|---|---|---|---|
| P01 | 1 | 4.8 | L55 |
| P01 | 1 | 4.8 | L55 |
| P01 | 2 | 3.1 | L56 |
| P02 | 1 | 5.0 | L60 |
| P02 | 1 | 5.2 | L61 |
The first two rows have the same subject, time, value, and source-record identifier. Checking the source record identifier finds one repeated identifier: L55 occurs twice. Inspection of the hypothetical import log confirms that this one source record was loaded twice. The two rows are therefore duplicate representations of the same measurement, not independent samples.
The row count is \(5\) before correction. Removing one confirmed extra representation gives \(5 - 1 = 4\) retained measurement records. The P02 records must both remain: their values differ and, more importantly, their source-record identifiers differ. The fact that both have time 1 h does not make them duplicates. The deduplication decision should record which source identifier was repeated, why one copy was removed, and which retained record remains traceable to the source.
Preserve Replicate Structure in the Data
Replicate identifiers prevent distinct observations from being mistaken for repeated copies. Their meaning should be explicit. A specimen identifier identifies collected material; a measurement-replicate identifier distinguishes repeated measurements of a specimen; and a collection-event identifier distinguishes collection events. These can be separate fields. If the source supplies only one identifier, document what it identifies rather than assuming it captures every kind of repetition.
Do not replace distinct replicate rows with a single average merely to make a key unique. Aggregation changes the data and can conceal variation or collection structure. If a later analysis requires one value per subject and time, the choice to aggregate, select, or otherwise represent replicates must be made explicitly, with its rationale and effects documented. A duplicate-cleaning step should not silently make that modeling decision.
Worked Example: Two Legitimate Measurements of One Specimen
In a hypothetical data set, specimen S204 from subject P07 was measured twice. The row grain is one assay measurement, and the source supplies both a specimen identifier and a measurement-replicate identifier.
| Subject | Collection time (h) | Specimen | Measurement replicate | Value (mg/L) |
|---|---|---|---|---|
| P07 | 1.5 | S204 | 1 | 6.1 |
| P07 | 1.5 | S204 | 2 | 6.3 |
Subject, time, and specimen are the same, but the measurement-replicate identifiers differ. At the stated grain, the rows represent two measurements and should be retained as two records. A key consisting only of subject, time, and specimen would incorrectly flag a collision; adding the replicate identifier distinguishes the records.
The two values have a mean of \((6.1 + 6.3)/2 = 6.2\) mg/L, but that calculation does not make the records duplicates or imply that they should be replaced by their mean. The task here is to preserve their identities and flag their shared specimen and time for interpretation. Any decision to use a summary value belongs to a separately specified analysis rule, not to automatic duplicate removal.
Specify Checks That Flag Rather Than Erase
A reproducible quality check should report what was checked, at what grain, which records were flagged, and what action followed. The check should not silently delete rows. For example, a workflow can produce separate reports for repeated source identifiers, repeated proposed keys, repeated subject-time combinations, and repeated values within a subject. Keeping these reports separate helps identify whether a concern is an import problem, an identifier problem, or a potentially legitimate replicate pattern.
When checking times, use the recorded collection-time field at its available precision and inspect the identifiers that accompany it. Do not assume that two displayed times are identical to the same underlying instant if values have been rounded. Also do not infer the collection time from a different time field: the check should state precisely which recorded field it uses. Questions about planned versus actual time are distinct and are addressed when those fields are specified.
Write what one row represents, such as one recorded measurement. This determines what “same record” means.
Check source-record identifiers and the proposed key for missing or repeated values. A repeated key is a flag to investigate, not an automatic deletion instruction.
List repeated values and subject-time combinations alongside specimen, event, replicate, and source identifiers where available.
For each flagged group, record whether it is a confirmed duplicate, a genuine replicate, an unresolved discrepancy, or a case requiring a corrected identifier.
Worked Example: Interpreting Repeated Times and Values
A hypothetical review checks four rows for subject P12. The intended grain is one row per collected sample measurement. Two separate collection-event identifiers and sample identifiers are available.
| Subject | Time (h) | Event | Sample | Value (mg/L) |
|---|---|---|---|---|
| P12 | 4 | E31 | S31 | 2.7 |
| P12 | 4 | E32 | S32 | 2.7 |
| P12 | 8 | E33 | S33 | 1.9 |
| P12 | 8 | E33 | S33 | 1.9 |
A subject-time check finds two rows at 4 h and two at 8 h. The repeated value 2.7 mg/L also occurs in two rows. Those checks flag the first pair, but their distinct event and sample identifiers show that they are not identical records. The repeated 8 h rows share event, sample, and value; the proposed sample-measurement key therefore occurs twice. They are suspicious, but the table alone does not prove whether the cause is a duplicate import or a missing replicate identifier. The source record or collection documentation must be reviewed before changing the data.
The check reports four rows total, two rows in each repeated-time group, and one repeated sample-measurement key at 8 h. The correct disposition is to retain the 4 h pair as distinct samples and hold the 8 h pair for source review. If source evidence confirms one row was imported twice, remove only the extra representation and document the reason. If evidence establishes two measurements, correct or add the replicate identifier and retain both. This decision follows from the identifiers and source evidence, not from equality of the values.
Deriving a Safe Duplicate Rule
The logic for a safe rule follows from the difference between a record’s observed attributes and its identity. Let \(R\) denote the set of source records and let \(g(r)\) be the displayed fields for record \(r\), such as subject, time, and value. If two records have the same displayed fields, then \(g(r_1)=g(r_2)\). That equality does not establish \(r_1=r_2\): distinct records can map to the same displayed values. For example, two samples can have the same subject, time, and rounded measurement.
A deletion rule based only on displayed-value equality is therefore unsafe: it treats a many-to-one representation as if it uniquely identified a record. A stable source identifier or a well-defined key at the intended grain supplies additional identity evidence. Even then, a repeated identifier signals a problem to investigate; it may reflect a repeated import, an incorrectly assigned identifier, or an incomplete key. Deletion is justified only after the records are confirmed to represent the same intended record.
This is why a robust workflow preserves both the original identifiers and the fields used in review. It allows a reviewer to distinguish “same values” from “same source record,” and to revise a decision if later evidence changes the interpretation.
Common Pitfalls, Alternatives, and Limits
- Deleting every repeated subject-time row. This assumes one sample per subject and time. It can erase distinct same-time collection events or replicates. Define the grain and inspect sample or event identifiers first.
- Deleting identical measurements. Equal values can arise in distinct samples, particularly when values are rounded. Compare record and sample identifiers instead of treating value equality as identity.
- Using a key that is too coarse. Subject and time alone may collapse distinct samples. Use fields that identify one record at the intended grain.
- Using a key that is too fine or unstable. Including an import-row number can make repeated imports appear unique. Retain provenance, but do not confuse a new processing-row number with a stable source-record identity.
- Aggregating replicates during cleaning. Averaging or selecting a replicate changes the observation structure. Keep this separate from deduplication and document any analysis-specific rule.
Automated deduplication is appropriate only for cases with a defensible identity rule and sufficient evidence, such as a confirmed repeated import of the same stable source record. Manual review is appropriate when identifiers conflict or the source is ambiguous. Retaining all rows with a review flag can be safer while a discrepancy is unresolved, but unresolved rows should not be treated as validated merely because they remain in the file.
No single check can establish that samples are scientifically valid. A unique key does not verify the correctness of the recorded time or value, and a duplicate report cannot determine whether a repeat was planned. Checks are limited to the fields and provenance available; their purpose is to make potential issues visible and traceable, not to substitute for source review.
Check Your Understanding
For each question, decide what the repetition establishes and what additional evidence is needed. Solutions are included below each item.
- A measurement-level data set has two rows with the same subject, time, and value but different sample identifiers. Should one be deleted?
Solution: No. The different sample identifiers indicate distinct samples at the stated grain. Retain both unless source review shows an identifier error. - Two rows share the same source-record identifier, subject, time, and value. What should happen next?
Solution: Flag the repeated source identifier and inspect the source or import log. If it confirms the same source record was loaded twice, remove the extra representation and document the action. The repeated identifier alone should prompt investigation. - Why might a check for repeated values miss accidental duplicates?
Solution: A duplicated record may have a changed or transformed value, so the values will not match. A value-only check is neither a complete duplicate detector nor a reliable identity rule. - A subject has two rows at the same recorded time and same value, with distinct collection-event identifiers. What does the repeated time establish?
Solution: It establishes that the recorded time repeats for that subject. The distinct event identifiers support treating the rows as separate events; the repeated time and value alone do not justify deleting either row. - A proposed key contains only subject and time, and it flags two legitimate samples collected at the same time. What is the appropriate correction?
Solution: Revise the key to reflect the row grain, adding an identifier that distinguishes the samples, such as a sample or collection-event identifier. Do not delete a legitimate row merely to make the existing key unique.