Tutorials › Multiple Imputation by Chained Equations (MICE) › Wide And Long Imputation For Repeated Measures

Nested and Multilevel Data · Tutorial 370 of 497

Wide And Long Imputation For Repeated Measures

Learn how data layout changes the conditional models used for repeated-measures imputation—and why wide or long format alone does not preserve within-person dependence.

Advanced 12 min read

What You'll Learn

  • Distinguish wide and long representations of the same repeated-measures data.
  • Identify how each format represents subject-level predictors and visit-specific outcomes.
  • Explain why long-format imputation needs to account for clustering within subjects.
  • Compare the assumptions behind wide and long conditional imputation models.
  • Diagnose duplicated subject-level imputations and weakened within-person dependence.
  • Choose a representation based on the variables, model, and intended analysis.

Why Data Layout Matters

Repeated-measures data record multiple values for each subject. Those values are not interchangeable rows: measurements from the same person are generally related, and a subject-level characteristic such as baseline age belongs to the person, not to any one visit. A data table can display these facts in different ways. In wide format, a subject usually occupies one row and each visit-specific variable has its own column. In long format, a subject occupies multiple rows, usually one per visit, with a visit identifier and a column for the measured value.

Changing the layout does not, by itself, change the statistical information in the observed records. It can, however, change which conditional models are easy to specify and whether a routine imputation model respects the data structure. In MICE, the key question is not simply “wide or long?” It is whether the imputation steps represent subject-level variables correctly and preserve the relevant dependence among repeated values.

Definition: In wide-format repeated-measures data, each subject is represented by one row, and measurements from different visits are stored in distinct columns, such as \(Y_1,Y_2,Y_3\). In long-format data, each subject is represented by multiple rows, with a subject identifier, a visit identifier, and a common measurement column \(Y\). A subject-level variable has one value per subject; a visit-specific variable can have a different value at each visit.

For example, age at enrollment is subject-level, while a blood-pressure measurement collected at each of three visits is visit-specific. In long format, age may appear on every row for a subject, but those repeated entries represent the same underlying value. They are not independent measurements of age. The earlier material on longitudinal records as two-level data provides the basic interpretation of visits nested within subjects; here the emphasis is how the choice of representation interacts with chained-equation imputation.

Models and Assumptions Before Choosing a Layout

MICE imputes each incomplete variable from a conditional model involving other variables. For repeated measures, the model must also reflect whether the target is a subject-level variable or a visit-specific value. A valid imputation requires, at minimum, a sufficiently appropriate conditional model for the variable being imputed, inclusion of useful observed information, and a representation that does not treat dependent rows as independent when that dependence matters. As in other imputation settings, the missingness assumptions and the variables included in the imputation model must be considered; choosing wide format or long format does not make missingness ignorable.

In wide format, a visit-specific target such as \(Y_2\) can be imputed conditionally on other visit-specific values, subject-level variables, and relevant auxiliary variables. In long format, the same target appears as a row-level value. A row-level model that treats every record as independent will usually fail to represent within-subject dependence. One option is a multilevel conditional model with a subject effect; another is a model that otherwise correctly captures the relevant dependence. The particular specification depends on the variable types and scientific structure.

A useful long-format representation therefore needs a subject identifier and a visit identifier. The subject identifier tells the imputation procedure which rows belong together. The visit identifier distinguishes values from different measurement occasions. Merely including the identifier as an ordinary numeric predictor is not generally equivalent to modeling clustering: its numerical codes have no meaningful distance scale, and it does not automatically produce the appropriate within-subject covariance.

Worked Example: Imputing One Missing Visit in Wide Format

Suppose a hypothetical study records a continuous outcome at three visits, \(Y_1,Y_2,Y_3\), and age at enrollment for each subject. For one subject, the observed data are \(Y_1=10\), \(Y_2\) missing, \(Y_3=14\), and age \(=40\) years. A fitted conditional model for \(Y_2\) is

$$ Y_2 = 2 + 0.5Y_1 + 0.2Y_3 + 0.1(\text{age}) + \varepsilon. $$

Assume for this illustration that this linear conditional model is adequate and that an appropriate residual draw is used to represent uncertainty. The conditional fitted value is

$$ 2 + 0.5(10) + 0.2(14) + 0.1(40) = 2 + 5 + 2.8 + 4 = 13.8. $$

If the stochastic imputation step draws a residual of \(-1.1\) outcome units, the imputed value is \(13.8-1.1=12.7\) outcome units. The residual is a hypothetical draw, not an observed fact. This wide-format step uses both neighboring visit values and age directly. It is defensible only to the extent that the conditional model, its predictor set, and its uncertainty representation are suitable for the data; the table layout alone does not establish those conditions.

How Long Format Represents Dependence

In long format, the three visit values for a subject occupy three rows. A common model for a continuous outcome illustrates why the subject identifier matters:

$$ Y_{ij} = \beta_0 + \beta_1 X_i + b_i + \varepsilon_{ij}, \qquad b_i \sim N(0,\tau^2), \quad \varepsilon_{ij} \sim N(0,\sigma^2). $$

Here \(i\) indexes subjects and \(j\) indexes visits; \(X_i\) is a subject-level predictor. The subject-specific term \(b_i\) is shared across that subject’s visits, while \(\varepsilon_{ij}\) is a visit-level residual. This is one possible dependence structure, not a universal model. Its assumptions include the specified random-intercept structure, appropriate distributions and conditional mean, and independence of residuals across visits given the subject effect and included predictors. Other data may require a different conditional model.

The covariance implication follows directly. For two different visits \(j\ne k\) from the same subject, the shared \(b_i\) contributes to both outcomes, whereas the visit-level residuals are independent under this model. Therefore,

$$ \operatorname{Cov}(Y_{ij},Y_{ik})=\operatorname{Var}(b_i)=\tau^2, \qquad \operatorname{Var}(Y_{ij})=\tau^2+\sigma^2, $$

so the within-subject correlation is \(\tau^2/(\tau^2+\sigma^2)\). For example, if \(\tau^2=9\) and \(\sigma^2=16\), the implied correlation is \(9/(9+16)=0.36\). This calculation justifies the central warning: a long-format imputation model that assumes independent rows does not reproduce even this simple shared-subject dependence.

A wide-format model can also represent dependence, because the repeated outcomes are separate variables in the same subject row. A conditional model for one visit can use the other visits as predictors, and a joint model can represent their covariance directly. The difference is chiefly how dependence is expressed: across columns in wide format, or through subject-level structure and related predictors in long format.

Worked Example: Long-Format Dependence in a Hypothetical Study

Suppose a hypothetical continuous outcome is recorded at three visits for each subject. Under the random-intercept model above, let the between-subject variance be \(9\) outcome-units-squared and the within-subject residual variance be \(16\) outcome-units-squared. For two visits from the same subject, the covariance is \(9\), and each visit has variance \(9+16=25\). Thus the correlation is

$$ \frac{9}{\sqrt{25}\sqrt{25}}=\frac{9}{25}=0.36. $$

If an imputation model instead treats the rows as independent, it represents this correlation as zero, contrary to the stated model. It may then generate repeated values that are too unrelated, affecting summaries or analyses that depend on within-person patterns. The remedy is not to declare long format unsuitable; it is to use an imputation model that acknowledges subjects as clusters and is compatible with the variables being imputed.

This model does not assert that every repeated-measures dataset has correlation \(0.36\), nor that a random intercept always suffices. It demonstrates how a stated dependence model implies a specific covariance, which can be checked against the scientific setting and observed data.

Subject-Level Predictors Must Stay at the Subject Level

A subject-level predictor such as age at enrollment is repeated down the rows when a long-format table is created. That repetition is a data-storage convention, not a change in the unit of information. If age is missing for a subject, the imputation should produce one age value for that subject and use it consistently across the subject’s rows. Drawing a separate age for every visit would create different ages for the same person and contradict the variable’s definition.

The issue also arises in fitting conditional models. A subject-level variable should not be treated as if its repeated copies were independent observations. The imputation model must account for the clustering or otherwise formulate the subject-level imputation at the subject level. In wide format, a subject-level predictor naturally appears once per row, although an imputation model still needs to include relevant predictors and handle missing values appropriately.

Worked Example: One Missing Subject-Level Value in Long Format

Consider a hypothetical long table with three visits per subject. Subjects A and B have enrollment ages of 20 and 40 years, respectively. Subject C’s age is missing. Suppose an appropriate subject-level imputation model produces a predictive value of 35 years for C and draws an uncertainty component of \(+2\) years. The completed age is \(35+2=37\) years.

In long format, the age column should then contain 37 years on each of C’s three visit rows. The three entries are copies of one imputed subject-level value. If the procedure instead drew, for example, 34, 37, and 41 years independently for C’s three rows, the completed data would assign three different enrollment ages to the same person. That is not a noisy version of the intended variable; it is an invalid representation of it.

The imputation model itself must also be appropriate: the stated predictive value and draw are illustrative, and do not establish that a particular model is valid for a real dataset. Predictors should be chosen at the subject level or summarized in a way consistent with the target and analysis, rather than treating each repeated copy as new independent evidence.

When Can the Representations Agree?

Wide and long approaches are not automatically equivalent merely because they contain the same observed values. They can yield comparable imputations when they encode the same relevant predictors and dependence, use compatible conditional distributions, and represent parameter and residual uncertainty appropriately. For example, a wide multivariate model may model the joint distribution of \(Y_1,Y_2,Y_3\), while a long model may impose a particular shared-subject covariance structure. If that structure does not match the joint distribution represented by the wide model, the resulting imputations need not agree.

Likewise, a set of separate wide-format regressions is not guaranteed to be compatible with one another or with the final analysis simply because each uses other visits as predictors. A long-format multilevel model is not guaranteed to be suitable simply because it includes a random effect. Model adequacy depends on the variable types, missingness patterns, available predictors, and dependence structure. The format is an implementation choice; the substantive requirement is a defensible imputation model.

FeatureWide formatLong format
RowsUsually one per subjectUsually one per subject-visit
Visit-specific outcomesSeparate columns, such as \(Y_1,Y_2,Y_3\)One outcome column plus a visit identifier
Subject-level predictorsOne entry per subject rowRepeated copies across a subject’s rows; conceptually one value
Dependence representationRelationships across visit-specific columnsSubject-level or other dependence structure across rows
Common riskMany visit-specific columns and complex conditional modelsIncorrectly treating rows as independent or imputing person-level values separately by row

Diagnostics, Failure Modes, and Limitations

Diagnostics should ask whether the imputed data retain the structure required by the scientific question. Useful checks include comparing observed and imputed distributions by visit, checking that subject-level variables are identical across a subject’s long-format rows, and examining whether within-subject associations in completed data are plausible relative to observed information and the imputation model. Also check that visit labels and subject identifiers are correctly carried through reshaping and that the imputation model includes useful predictors without coding identifiers as arbitrary numeric measurements.

Common warning signs include implausibly weak association among a subject’s repeated outcomes after long-format imputation, inconsistent copies of a subject-level variable, and visit-specific imputed distributions that differ sharply from observed distributions without a substantive explanation. These patterns may point to a model or data-management problem; they are not automatic proof of failure, because observed data and missingness patterns can limit what is diagnosable.

Wide format can become unwieldy when there are many visits or many visit-specific variables, and subjects with different observed visits can create complicated conditional models. Long format is convenient for repeated records, but requires careful handling of subject clustering and variable level. Neither format repairs a misspecified conditional model, supplies information where predictors are uninformative, or guarantees that the imputation assumptions are credible. The choice should follow the intended model and data structure, and reshaping should be checked as a statistical step rather than treated as a cosmetic one.

Common mistake: “The data are in long format, so the dependence among repeated measures is automatically handled.” Long format only places repeated records in rows. Unless the imputation model uses the subject structure or another suitable dependence representation, it may treat those rows as independent. Include and model the clustering appropriately, and verify that subject-level variables remain constant within subject.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions below.

  1. A dataset has one row per subject and columns \(Y_1,Y_2,Y_3\). Is it wide or long, and how is the visit-specific outcome represented?
  2. In long format, a subject-level variable is repeated on three visit rows. What does this repetition mean, and what should happen if that variable is imputed?
  3. Under the random-intercept model, if \(\tau^2=4\) and \(\sigma^2=12\), what within-subject correlation does the model imply?
  4. Why is a long-format imputation that treats all rows as independent potentially problematic?
  5. Does using wide format guarantee that the imputation model represents within-subject dependence correctly? Explain.

Solutions. (1) It is wide format: each visit-specific outcome has its own column. (2) The repeated entries are copies of one subject-level value, not independent measurements; impute one value per subject and keep it consistent across the rows. (3) The implied correlation is \(4/(4+12)=0.25\). (4) Rows from the same subject are generally dependent; an independent-row model may fail to reproduce that dependence. (5) No. Wide format makes visits separate columns, but the conditional or joint models must still represent relevant relationships and uncertainty appropriately.

Clinical Biostats