One Subject, Many Records
An NLME data set may contain several observations for each subject. A central simulation decision is whether a simulated row represents a new subject or another record from a subject already represented. The distinction matters because subject-level random effects describe persistent differences between subjects. A subject’s random effect is drawn once and is shared by that subject’s records; it is not redrawn every time a new observation is generated.
This tutorial isolates that decision by treating the fitted population parameters as fixed. It focuses on the hierarchy of subject effects and observation-level errors, not on parameter uncertainty. In either type of simulation, the structural model predicts the outcome from the fixed parameters, covariates, and subject effects. The question is which subject-effect draw to use for each record.
The Model Hierarchy and Its Assumptions
Write the outcome for subject \(i\) at record \(j\) as
Here \(t_{ij}\) is the record’s time or occasion, \(x_{ij}\) denotes its covariates, \(\theta\) is the vector of population fixed effects, and \(\eta_i\) is the subject-level random-effect vector. The structural function \(f\) maps these quantities to the model prediction. The record-level error is \(\epsilon_{ij}\). In the usual population simulation, new subjects’ random effects are drawn from the fitted population distribution, often \(\eta_i\sim N(0,\Omega)\), where \(\Omega\) is the random-effect covariance matrix.
For the basic illustrations, assume random-effect vectors are independently drawn across subjects from the same distribution, and that record-level errors are independently drawn across records, independently of the random effects, with mean zero. These assumptions make the distinction especially clear. If the fitted model specifies a different residual structure, simulate errors according to that structure; the rule that a subject’s \(\eta_i\) is shared by their records still applies. Throughout, \(\theta\), \(\Omega\), and residual-model parameters are held fixed at their fitted values.
The simulation unit is therefore not always the row of the data set. Drawing \(\eta_i\) once for every row creates a different model: it makes subject characteristics fluctuate between that subject’s records. Conversely, using one draw for every subject in a population simulation makes all subjects share the same random effects. The correct assignment is one random-effect draw per simulated subject, followed by as many records as required for that subject.
Worked Example: Adding a Record for an Existing Subject
Suppose a hypothetical random-intercept model is \(Y_{ij}=10+\eta_i+\epsilon_{ij}\), with \(\eta_i\sim N(0,2^2)\) and independent \(\epsilon_{ij}\sim N(0,1.5^2)\). In one simulation, subject A has already received the random-effect draw \(\eta_A=1.2\). Generate two records using residual draws \(-0.3\) and \(0.5\).
For the first record, \(Y_{A1}=10+1.2-0.3=10.9\). For the second, \(Y_{A2}=10+1.2+0.5=11.7\). Both records use the same \(1.2\) subject effect; only their residual draws differ.
If the second record were mistakenly generated with a newly drawn random intercept, it would no longer be a repeat record from subject A under this model. It would combine subject A’s first record with a second, independently generated subject effect. That breaks the intended within-subject structure.
Why Reusing the Draw Matters
The effect of this rule can be shown directly in a random-intercept model. Let \(Y_{ij}=\mu+\eta_i+\epsilon_{ij}\), where \(\eta_i\) has mean zero and variance \(\tau^2\), and each \(\epsilon_{ij}\) has mean zero and variance \(\sigma^2\). Assume the random effects and residual errors are mutually independent, and residual errors from different records are independent. For two different records \(j\ne k\) from the same subject,
The fixed mean contributes no covariance, and the independent residual errors contribute none. The shared random effect contributes \(\tau^2\). Each individual record has variance \(\tau^2+\sigma^2\), so the within-subject correlation is \(\tau^2/(\tau^2+\sigma^2)\). If a new \(\eta\) is drawn independently for every record, this shared contribution disappears and the simulated within-subject covariance becomes zero under these assumptions. The simulation then fails to reproduce the dependence implied by the fitted random-intercept model.
Worked Example: Checking Within-Subject Dependence
Consider the hypothetical model \(Y_{ij}=10+\eta_i+\epsilon_{ij}\), where the subject-effect standard deviation is \(2\) and the residual standard deviation is \(1.5\). Thus \(\tau^2=4\) and \(\sigma^2=2.25\). Calculate the marginal variance of one record and the correlation between two records from the same subject.
The variance of one record is \(\tau^2+\sigma^2=4+2.25=6.25\), so its standard deviation is \(2.5\). The covariance of two different records from the same subject is \(\tau^2=4\). Therefore their correlation is \(4/6.25=0.64\).
The positive correlation is a consequence of the shared subject effect, not an extra residual error. A simulation that draws a fresh intercept for each record would give zero covariance between distinct records under the stated independent-error assumptions, rather than the model-implied covariance of \(4\).
Population Subjects and Existing Subjects
A population simulation usually starts by defining the number of subjects and the records to generate for each. Draw a random-effect vector for each subject from the fitted population distribution. Then evaluate the structural model for that subject’s records and generate the required residual errors. By contrast, when adding records for an already simulated subject, retain the vector assigned to that subject. Generate new record-level errors as appropriate, but do not replace the subject effect.
A record can be new without its subject being new. For example, a later observation time for a previously simulated individual is a new record, but it belongs to the same individual. Subject identity, not the order in which rows are generated, determines whether to draw a new random effect.
Worked Example: Multiple Records With a Random Intercept and Slope
Suppose a hypothetical model is \(Y_{ij}=10+2t_{ij}+\eta_{0i}+\eta_{1i}t_{ij}+\epsilon_{ij}\). For one subject, draw an intercept effect \(\eta_{0i}=0.5\) and a slope effect \(\eta_{1i}=-0.1\). Use times \(t=0\) and \(t=2\), with residual draws \(0.2\) and \(-0.3\). These are illustrative draws from the fitted random-effect and residual distributions.
At \(t=0\), the prediction before residual error is \(10+2(0)+0.5+(-0.1)(0)=10.5\). Adding the first residual gives \(Y_{i1}=10.5+0.2=10.7\).
At \(t=2\), the prediction before residual error is \(10+2(2)+0.5+(-0.1)(2)=14.3\). Adding the second residual gives \(Y_{i2}=14.3-0.3=14.0\). Both records reuse the same intercept and slope effects. The slope effect changes the trajectory over time, but it remains the same subject-specific slope across that subject’s records.
To simulate a different subject, draw a new pair \((\eta_{0},\eta_{1})\) from the fitted joint random-effect distribution, preserving its covariance structure if the model includes correlated effects. Do not assign the first subject’s pair to the new subject merely because the records are generated in the same simulation run.
Implementation Checks, Alternatives, and Limitations
A practical simulation can keep a subject identifier alongside a stored random-effect vector. When a subject is first encountered, draw and store the vector; for each later record carrying that identifier, retrieve the stored vector. This simple bookkeeping makes the intended hierarchy explicit.
- Check the number of draws. For a population of \(N\) simulated subjects, there should be \(N\) subject-effect vectors, not one per record and not one for the whole population.
- Check reuse within subject. In a random-intercept model, records from one subject should share the same simulated intercept. In a random-slope model, they should share the same simulated intercept and slope.
- Check variation across subjects. Distinct subjects should receive distinct random-effect draws, except by chance. Reusing one vector for all subjects suppresses the between-subject variation specified by the model.
- Check the error layer separately. New record-level errors are generally generated for new observations, subject to the fitted residual structure. Reusing a subject effect does not mean reusing the same residual error.
A common mistake is to reason, “There is a new row, so I should draw a new random effect.” The correction is to ask whether the row belongs to a new subject. A new row for an existing subject reuses that subject’s effects; a row for a new subject uses a newly drawn vector. Another mistake is to treat the fitted effect for an observed subject, such as an empirical Bayes estimate, as interchangeable with a fresh population draw. These represent different simulation targets: conditioning on an existing subject’s estimated effect describes that subject conditionally, whereas drawing from the population distribution represents a new subject. The conditional estimate also has estimation uncertainty, so it should not automatically be treated as the subject’s known true effect.
The main alternative to a population draw is therefore a conditional simulation for specified existing subjects. It can be useful when the target is additional records for those individuals, but it does not represent a fresh sample of the population. Neither approach is universally preferable: the simulation target determines which is appropriate. Both are limited by the fitted model’s adequacy. Reusing random effects correctly cannot compensate for a misspecified random-effects distribution, residual structure, or structural model. Nor does this distinction by itself add uncertainty in fitted parameters; those parameters are fixed in the simulations described here.
Check Your Understanding
Answer each question, then compare with the brief solutions.
- A simulated subject has random intercept \(\eta_i=0.8\). A second record is added for that subject. Should the intercept be redrawn?
- In a random-intercept model with \(\tau^2=3\) and \(\sigma^2=2\), what is the covariance between two distinct records from the same subject, assuming independent residual errors?
- A simulation generates 50 subjects with four records each. How many subject-level random-effect vectors should be drawn?
- Why does drawing an independent random intercept for every record fail to preserve the model’s within-subject dependence?
- What is the distinction between simulating a new subject from the population and simulating additional records conditionally for an existing subject?
Solutions. (1) No. Reuse \(0.8\), while generating a new record-level error according to the residual model. (2) The covariance is \(\tau^2=3\), because the two records share the same random intercept and their residual errors are independent. (3) Draw 50 vectors, one for each subject, and use each vector for that subject’s four records. (4) Independent intercept draws remove the shared random-effect contribution to covariance; under the stated assumptions, distinct records would then have zero covariance rather than \(\tau^2\). (5) A new-subject simulation draws a new vector from the population random-effects distribution. A conditional repeated-record simulation retains the existing subject’s vector and generates further records using it.