Tutorials › Pharmacometric Workflows and Reproducible Modeling › Defining the Pharmacometric Record Grain

Data Specification and Dataset Preparation · Tutorial 1 of 399

Defining the Pharmacometric Record Grain

Learn to define a dataset’s record grain and apply it consistently to subject-level information and repeated observations, doses, and covariates.

Intermediate 11 min read

What You'll Learn

  • Define record grain as the entity or occurrence represented by one row.
  • Distinguish one-row-per-subject data from one-row-per-event data.
  • Calculate and interpret subject and observation counts when subjects contribute different numbers of measurements.
  • Recognize the consequences of combining different record types in one table.
  • Choose whether observations, doses, and covariates belong in separate, consistently grained datasets.
  • Diagnose grain problems by checking what each row means and what the row count measures.

Why Record Grain Comes First

Before a pharmacometric dataset can be interpreted, its rows need a clear meaning. A row might represent one subject, one concentration measurement, one dose administration, or a subject-level characteristic. If the row meaning is left implicit, a count of rows can be mistaken for a count of subjects or measurements, and the same information may be repeated or represented at incompatible levels.

The record grain is the unit represented by one row of a dataset. Choosing a grain is a design decision: it determines what one row stands for and, therefore, what the table’s row count describes. A dataset may contain several tables with different grains, but within a given table the row meaning should be consistent and stated plainly.

Definition: A dataset’s record grain is the entity or occurrence represented by each row. A subject-level grain has one row per subject for the information being recorded. An event-level grain has one row per occurrence of a specified event, such as one concentration observation or one dose administration. The row count measures the number of records at that grain; it is not automatically the number of subjects.

A grain description should be specific enough to distinguish different kinds of event. “One row per event” is usually too vague if the dataset contains both observations and doses. “One row per concentration observation” or “one row per dose administration” identifies what is counted. This tutorial concerns that choice of row meaning; it does not define the later mechanics for identifying, ordering, or coding individual records.

Subject-Level and Event-Level Tables

A subject-level table can hold information that is represented once per subject in that dataset, such as a baseline characteristic. An event-level table can hold repeated records, such as measurements taken at multiple occasions. These tables answer different counting questions: the first counts subjects represented, while the second counts event records represented.

Let \(S\) be the number of subjects in a specified group, and let \(m_i\) be the number of observations contributed by subject \(i\), for \(i=1,\ldots,S\). The total number of observation records is \(\sum_{i=1}^{S}m_i\). The subject count and observation-record count need not match. A subject with no observation contributes to the subject count but not the observation count; a subject with several observations contributes several observation records.

$$ N_{\text{observations}}=\sum_{i=1}^{S}m_i $$

This distinction matters when describing a dataset, planning summaries, or checking whether an operation has changed the number of records. For example, “there are 24 rows” has no scientific interpretation until the grain is known. It could mean 24 subjects, 24 observations, or a mixture of record types.

Worked Example: Counting Subjects and Observation Records

Hypothetical data. Four subjects contribute 3, 2, 0, and 1 concentration observations, respectively. Find the subject count and the total observation-record count, and explain what each count represents.

There are \(S=4\) subjects. Their observation counts are \(m_1=3\), \(m_2=2\), \(m_3=0\), and \(m_4=1\). Therefore,

$$ N_{\text{observations}}=\sum_{i=1}^{4}m_i=3+2+0+1=6 $$

A subject-level table representing all four subjects has 4 rows at one row per subject. A table containing the concentration observations has 6 rows at one row per observation. The subject with no observation is still one of the four subjects, but contributes no row to the observation table. Thus the two row counts are 4 and 6 because they count different things.

When Do the Counts Match?

It is tempting to assume that the number of subjects and the number of observations must differ whenever observation counts vary. That is not generally true: a subject with no observations can balance another subject with multiple observations. The exact condition follows directly from the count formula.

Result: The subject count \(S\) equals the observation-record count if and only if \(\sum_{i=1}^{S}m_i=S\). If every subject contributes at least one observation, then the counts are equal if and only if every subject contributes exactly one observation. Without the at-least-one condition, equality can occur even when some subjects contribute zero and others contribute multiple observations.

To justify the conditional statement, suppose \(m_i\geq 1\) for every subject. Then each difference \(m_i-1\) is nonnegative, and

$$ \sum_{i=1}^{S}m_i=S \quad\Longleftrightarrow\quad \sum_{i=1}^{S}(m_i-1)=0 \quad\Longleftrightarrow\quad m_i-1=0\text{ for every }i \quad\Longleftrightarrow\quad m_i=1\text{ for every }i. $$

The middle implication holds because a sum of nonnegative numbers is zero only when every term is zero. If some \(m_i\) may be zero, the differences \(m_i-1\) can be negative, so positive and negative differences can cancel. In that case the general condition remains \(\sum m_i=S\), not “one observation per subject.”

Worked Example: Equal Counts Do Not Prove One Observation per Subject

Hypothetical data. Two subjects contribute 0 and 2 concentration observations. Compare the subject count with the observation-record count.

Here \(S=2\), \(m_1=0\), and \(m_2=2\), so

$$ N_{\text{observations}}=m_1+m_2=0+2=2=S. $$

The counts happen to be equal, but the subjects did not each contribute one observation. One contributed none and the other contributed two. The correct general check is the sum of the contributions; the stronger “exactly one each” conclusion is valid only if every subject is known to contribute at least one observation.

Choosing a Grain for Observations, Doses, and Covariates

Observations and doses are different kinds of occurrences. A concentration observation table can use one row per recorded concentration measurement, while a dose table can use one row per dose administration. Each table’s row count then has a clear interpretation. This is often easier to maintain than placing both types of occurrence into one table without a declared row meaning.

Subject-level covariates can be stored in a one-row-per-subject table. If they are copied into an observation-level table, the repeated values are attributes attached to each observation row; they do not turn those rows into subject-level records. That arrangement can be useful for analysis inputs, but the table’s grain remains one row per observation. If covariate values vary over time, the data design must also make clear which records the values describe. The important point here is to declare the level of representation rather than assume that every column has the same grain.

Dataset purposeDeclared grainWhat its row count represents
Subject characteristicsOne row per subjectSubject records represented
Concentration measurementsOne row per observationObservation records represented
Dose administrationsOne row per dose administrationDose records represented
Combined event table, if deliberately usedOne row per explicitly classified eventAll included event records, not one event subtype alone

Worked Example: Detecting a Mixed-Grain Table

Hypothetical data. A draft table contains three concentration measurements and two dose administrations for a subject. It has five rows, but the dataset description says only “one row per concentration.” Assess the description and propose a consistent design.

The description is inconsistent with the contents: two rows represent dose administrations, not concentration measurements. The five-row count cannot be reported as the number of concentration observations, because only three rows are observations. Nor is it a count of subjects; all five rows may concern the same subject.

One clear design is a concentration table with 3 rows at one row per concentration observation and a dose table with 2 rows at one row per dose administration. Another possible design is an explicitly mixed event table with 5 rows, provided each row’s event type is unambiguous and analyses distinguish the event types. In either design, the stated grain must match the actual rows. The first design makes the counts particularly direct: 3 observation records and 2 dose records.

Grain Checks and Common Failure Modes

A practical grain check begins by completing the sentence “one row represents one ...” for every dataset. Then examine a small set of rows and verify that each one has that meaning. Finally, state what the row count measures and compare it with expected counts at the same grain. This is a structural check, not a substitute for later checks of identifiers, ordering, or field coding.

1
State the row meaning.
Specify one subject, one observation, one dose administration, or another clearly defined record type.
2
Check representative rows.
Confirm that each row is an instance of the stated unit, rather than a different kind of record inserted into the table.
3
Interpret the row count.
Describe the number of records at the declared grain, and do not relabel it as a subject or observation count without justification.
4
Review repeated information.
Check whether subject-level or covariate values are intentionally repeated across event rows, and keep their level of meaning distinct from the row grain.

Warning signs include a table whose description says “one row per subject” but whose row count grows when repeated measurements are added, a single count reported as both subjects and observations without supporting conditions, and a table that combines doses and observations while treating every row as the same event type. These are reasons to revisit the data specification before analysis.

A common mistake is to say, “There are six rows, so there are six subjects.” That conclusion is justified only if the table is actually one row per subject and contains the intended subject records. If the rows are observations, six rows mean six observation records; multiple rows may belong to one subject, and some subjects may have no observation in that table. A related mistake is to infer that equal subject and observation counts prove one observation per subject. As shown above, this inference also requires every subject to contribute at least one observation.

Separate tables are not automatically superior in every workflow, and a combined event table is not automatically invalid. The choice depends on the intended use and the discipline with which event types and repeated attributes are represented. The limitation is that a grain statement alone cannot establish whether records are complete, correctly identified, or scientifically valid. It makes the table’s structure interpretable; additional checks are needed for those other properties.

Worked Example: Choosing a Covariate Representation

Hypothetical data. A small dataset has three subjects and two concentration observations per subject. A baseline body-weight value is recorded once for each subject. Compare a subject-level covariate table with a concentration table that repeats body weight on each observation row.

The subject-level table has one row per subject, so it has 3 rows and represents 3 baseline covariate records. The observation table has one row per concentration observation:

$$ N_{\text{observations}}=3\times 2=6. $$

If body weight is copied onto each observation row, the observation table still has 6 rows at one row per concentration observation. The repeated body-weight values provide subject-level information alongside each observation; they do not change the grain or make the table contain 6 subjects. A separate 3-row table preserves the one-record-per-subject representation, while a 6-row observation table can carry the covariate values needed with each measurement. Either representation should be described accurately and checked for consistency.

Why the Grain Decision Matters

A clear grain makes counts interpretable and supports reproducible transformations. When a dataset is joined to another dataset, summarized, or filtered, the expected row count depends on what each input row represents. If that meaning is unspecified, an unexpected increase or decrease in rows is difficult to diagnose: it may be a valid change in event records or an unintended change in representation.

The grain also limits what can be concluded from a table’s size. A dataset with 100 observation rows might represent 100 measurements from one subject or 100 measurements distributed across many subjects. The row count alone does not answer that question. Report the unit counted, and when useful report both the number of subjects represented and the number of event records, with the basis for each count.

Key takeaway: Declare one row’s meaning before interpreting the row count. Subject-level rows count subject records; event-level rows count occurrences at the specified event grain. Equal counts do not by themselves establish a one-to-one relationship between subjects and observations.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. A hypothetical observation table has 18 rows, with one row per concentration measurement. What does 18 count, and what does it not establish about the number of subjects?
  2. Three hypothetical subjects contribute 1, 0, and 2 observations. Calculate the subject count and observation-record count. Are they equal?
  3. In a hypothetical study, five subjects each contribute at least one observation, and the subject count equals the observation-record count. What follows about the number of observations per subject?
  4. A table is described as one row per dose administration but includes concentration-measurement rows too. What is the grain problem, and give one remedy.
  5. A subject-level baseline covariate is repeated on every observation row. Does that make the table subject-level? Explain.

Solutions. (1) The 18 counts concentration-observation records. It does not reveal how many subjects contributed them. (2) There are 3 subjects and \(1+0+2=3\) observation records, so the counts are equal, despite unequal contributions. (3) Each subject contributes at least one, so equality implies exactly one observation per subject. (4) The table contains more than the declared record type; separate dose and observation tables or explicitly define a mixed event grain and distinguish event types. (5) No. The table remains observation-level because each row represents an observation; the repeated covariate is subject-level information attached to those rows.

Clinical Biostats