Tutorials › Pharmacometric Workflows and Reproducible Modeling › Occasion-Level Variability Across Modeling Tools

Software Landscape and Interoperability · Tutorial 206 of 399

Occasion-Level Variability Across Modeling Tools

You will learn to define occasion-level random effects, compare their representation across tools, diagnose common modeling problems, and carry occasion-specific parameter values into mrgsolve.

Intermediate 12 min read

What You'll Learn

  • Distinguish interoccasion variability from interindividual variability and residual error.
  • Write a log-normal parameter model with subject- and occasion-level random effects.
  • Map the same IOV structure to NONMEM, Monolix, and nlmixr2.
  • Carry fixed occasion-specific parameter values into mrgsolve without accidentally redrawing them.
  • Check occasion coding, identifiability, and model diagnostics.

Why Occasion-Level Variability Needs Its Own Representation

A subject’s clearance can differ between treatment periods even when the subject’s underlying disposition is unchanged. A model with only interindividual variability assigns one clearance deviation to each subject; it cannot represent additional, persistent-within-period changes from one occasion to another. Interoccasion variability (IOV) represents that second source of variation explicitly.

The distinction matters when data include repeated occasions, such as separate study periods or dosing intervals defined as occasions by the analysis plan. An occasion effect is shared by records belonging to the same subject and occasion. It is not a new random draw for every observation, and it is not automatically the same as a time-varying covariate.

Definition: Let \(i\) index subjects and \(j\) index occasions within subject. For a positive parameter such as clearance, a common model is \(CL_{ij}=CL_{\mathrm{typ},ij}\exp(\eta_i+\kappa_{ij})\). Here \(\eta_i\) is the subject-level random effect, shared across that subject’s occasions, and \(\kappa_{ij}\) is the occasion-level random effect, shared by records in occasion \(j\). A standard assumption is \(\eta_i\sim N(0,\omega_{\eta}^2)\), \(\kappa_{ij}\sim N(0,\omega_{\kappa}^2)\), with the two effects mutually independent and occasion effects independent across occasions.

The typical parameter \(CL_{\mathrm{typ},ij}\) may include covariate effects; it is the value before these random effects are applied. Under the stated assumptions, the random effects are centered on the log scale. Thus, the exponential model is multiplicative on the clearance scale, and its conditional median is \(CL_{\mathrm{typ},ij}\), not its arithmetic mean.

The model also specifies a dependence pattern. On the log scale, two clearances for the same subject at different occasions share \(\eta_i\), but have independent occasion effects. Their covariance is therefore \(\omega_\eta^2\). For observations in the same occasion, both random effects are shared. This is why the occasion assignment must be consistent across all records in that period.

Worked Example: Calculating Occasion-Specific Clearance

Suppose a hypothetical subject has typical clearance \(CL_{\mathrm{typ}}=5.00\) L/h and an estimated subject effect \(\eta_i=0.10\). For two occasions, let the occasion effects be \(\kappa_{i1}=0.20\) and \(\kappa_{i2}=-0.10\). Calculate the clearance assigned to each occasion.

The model is \(CL_{ij}=5.00\exp(0.10+\kappa_{ij})\) L/h. For occasion 1:

$$ CL_{i1}=5.00\exp(0.10+0.20) =5.00\exp(0.30) =5.00(1.3499) =6.749\ \text{L/h}. $$

For occasion 2:

$$ CL_{i2}=5.00\exp(0.10-0.10) =5.00\exp(0) =5.000\ \text{L/h}. $$

The subject effect contributes to both values, while the occasion effect changes between them. The resulting difference is not a new subject effect and should not be assigned independently to each observation within an occasion.

Representing the Same Structure in Each Tool

The statistical model should remain fixed while its software representation changes. In each implementation, identify the subject-level effect, the occasion-level effect, the occasion identifier, and the variance associated with each effect. The syntax and estimation interfaces differ; the intended hierarchy does not.

ToolRepresentation to preserveImplementation check
NONMEMSubject-level ETA plus an occasion-level random effect, commonly organized using occasion-level random-effect support such as $LEVEL.Confirm that the occasion indicator defines the level at which the effect is shared, rather than creating one effect per record.
MonolixA subject-level random effect and an additional random effect declared at the occasion level.Confirm that the occasion column is declared and that the occasion effect is assigned to that level in the model configuration.
nlmixr2A subject-level ETA plus an occasion-indexed random effect, using the IOV mechanism supported by the installed version.Confirm that the occasion index is passed to the IOV specification and that the variance belongs to the occasion effect.
mrgsolveA parameter expression that uses both the subject effect and the occasion-specific value supplied for the current occasion.Provide the occasion-specific value as input or otherwise construct it explicitly; do not assume a fitted-model IOV effect is automatically generated.

In NONMEM, the important modeling choice is to define the occasion-level effect at the occasion level, rather than to create a separate fixed list of ETAs for a predetermined number of periods. A `$LEVEL`-based specification can express that level structure when supported and configured for the model and data. The control stream must link the occasion identifier in the data to the level declaration. Check the NONMEM version’s syntax and the resulting random-effect structure; a record-level or incorrectly indexed effect would imply a different model.

In Monolix, specify the additional random effect as occasion-level variability, with the occasion variable identified in the project’s data and model configuration. In nlmixr2, use the package’s IOV facility to associate the random effect with the occasion index; exact function and argument details can vary by version. In either case, a formula that merely adds another subject-level random effect is insufficient: that effect would persist across all of a subject’s occasions.

A useful translation check is to write the statistical equation before writing software syntax. Then verify that each tool implements the same typical parameter, same transformations, same sharing of effects within and between occasions, and same variance assumptions. Do not infer equivalence merely because parameter names look similar.

What the Variance Components Imply

Under the independence assumptions in the definition, the log of clearance has two random components. For a fixed typical value, its variance on the log scale is the sum of the subject and occasion variances. For two different occasions in the same subject, the shared subject effect induces correlation on the log scale.

$$ \operatorname{Var}(\log CL_{ij})=\omega_{\eta}^2+\omega_{\kappa}^2,\qquad \operatorname{Cov}(\log CL_{ij},\log CL_{ik})=\omega_{\eta}^2\quad (j\ne k). $$

Consequently, the log-scale correlation across two occasions is \(\omega_{\eta}^2/(\omega_{\eta}^2+\omega_{\kappa}^2)\). This formula describes log clearance under the model, not the correlation of untransformed clearance values.

Worked Example: Separating the Variance Components

Suppose a hypothetical fitted model has \(\omega_{\eta}^2=0.0400\) and \(\omega_{\kappa}^2=0.0900\). Find the log-scale variance within an occasion and the correlation in log clearance between two occasions from the same subject.

Within one occasion, both random effects vary across subjects and occasions, so:

$$ \operatorname{Var}(\log CL_{ij})=0.0400+0.0900=0.1300. $$

Across two occasions for the same subject, only the subject-level effect is shared, giving covariance \(0.0400\). Therefore:

$$ \operatorname{Corr}(\log CL_{ij},\log CL_{ik}) =\frac{0.0400}{\sqrt{0.1300\cdot0.1300}} =\frac{0.0400}{0.1300} =0.3077. $$

The model implies a log-scale correlation of about 0.308 between those occasions. The occasion component increases within-occasion variability without being shared across different occasions.

Carrying Occasion Values into mrgsolve

mrgsolve can use occasion-specific parameter values in a simulation, but the model must be given those values or a mechanism to calculate them. A fitted random-effects structure in another tool does not, by itself, transfer occasion-level effects into mrgsolve. For a simulation based on supplied individual estimates or scenarios, prepare input values indexed by subject and occasion, and use the value associated with the current occasion in the parameter expression.

For example, the conceptual expression is \(CL=CL_{\mathrm{typ}}\exp(\eta+\kappa)\). The subject effect \(\eta\) is constant across that subject’s occasions. The input \(\kappa\) changes when the simulation advances to a different occasion, and remains constant for all records assigned to the same occasion. The precise mrgsolve data columns and model code depend on the implementation, but this indexing rule does not.

Worked Example: Supplying Occasion Values to a Simulation

Use the hypothetical values from the first example for subject 17: \(CL_{\mathrm{typ}}=5.00\) L/h, \(\eta_{17}=0.10\), and occasion effects \(0.20\) and \(-0.10\). A simulation input can carry the subject’s ETA and an occasion-specific KAPPA_CL value: rows for occasion 1 carry \(0.20\), and rows for occasion 2 carry \(-0.10\). The model’s clearance expression uses both values.

For records in occasion 1, the calculation is \(5.00\exp(0.10+0.20)=6.749\) L/h. For records in occasion 2, it is \(5.00\exp(0.10-0.10)=5.000\) L/h. Thus every record within one occasion uses the same occasion effect, while the effect changes at the boundary to the next occasion.

This example supplies occasion effects as fixed simulation inputs. It does not estimate their distribution or randomly sample new effects. If the objective is to simulate population variability, generate occasion effects from the intended distribution, independently across occasions under this model, and preserve each generated value for all records in its occasion. State which objective is intended: reproducing supplied individual effects and simulating new variability are not interchangeable workflows.

Derivation, Diagnostics, and Failure Modes

The variance and covariance results follow directly from the model. For fixed typical clearance, take logarithms to obtain \(\log CL_{ij}=\log CL_{\mathrm{typ},ij}+\eta_i+\kappa_{ij}\). Variance of a sum of independent random variables is the sum of their variances, giving \(\omega_{\eta}^2+\omega_{\kappa}^2\). For two distinct occasions, expand the covariance of \(\eta_i+\kappa_{ij}\) and \(\eta_i+\kappa_{ik}\). The shared term contributes \(\operatorname{Var}(\eta_i)=\omega_{\eta}^2\); the cross-covariances and the covariance of the independent occasion effects are zero. This gives the stated covariance.

Before interpreting an estimated IOV component, check that the data and model support its meaning. Occasion labels must identify comparable periods consistently within subjects. Subjects need informative observations across occasions to distinguish persistent subject differences from occasion-to-occasion changes. If each subject contributes only one occasion, the data generally do not separate the two variance components without additional information or constraints. Sparse data, few subjects, or little variation between occasions can also make the occasion variance weakly identified.

  • Check the nesting. Verify that each occasion belongs to the correct subject and that records within an occasion share one occasion effect.
  • Check the variance scale. Confirm that \(\omega_{\kappa}^2\) is a variance on the random-effect scale, not a standard deviation mistakenly entered as a variance.
  • Check the parameter transformation. Adding a random effect on the log scale produces a multiplicative effect on clearance. An additive clearance effect is a different model.
  • Check the implementation. If the simulated parameter changes at every observation rather than at occasion boundaries, the occasion value is being regenerated or indexed incorrectly.
  • Check estimation evidence. A near-zero or imprecise variance estimate, unstable estimates across initial values, or boundary behavior may signal weak information or an overcomplicated random-effects structure. These are warnings to investigate, not automatic proof that IOV is absent.

The principal alternative is a model with interindividual variability alone. It is simpler and may be appropriate when occasion-level changes are unsupported or unneeded, but it cannot represent additional within-subject occasion shifts. A model with a separate fixed parameter for every occasion instead describes systematic occasion differences, not unexplained random variation among occasions. Covariates may explain predictable differences between occasions, but they do not replace IOV when residual occasion-level variation remains. Model choice should follow the study design and data support, not a desire to include every possible random effect.

Common mistake: “There are three observations in an occasion, so I should draw three occasion effects.” That makes the effect observation-specific and changes the model’s dependence structure. The correction is to draw or assign one \(\kappa_{ij}\) for subject \(i\), occasion \(j\), then reuse it for every record in that occasion. A related error is to treat occasion effects as independent between records while retaining a subject ETA; the resulting simulation no longer represents the specified IOV model.

Key takeaway: IOV is an occasion-level random effect nested within subject. Preserve the same effect within an occasion, allow it to change between occasions, and verify that each tool and simulation implements that exact sharing structure.

Check Your Understanding

Answer each question using the subject- and occasion-level model defined above. Short solutions follow each question.

  1. A subject has \(\eta_i=0.05\), \(CL_{\mathrm{typ}}=4.00\) L/h, and \(\kappa_{i1}=0.10\). What is the occasion-specific clearance?

    Solution: \(CL_{i1}=4.00\exp(0.05+0.10)=4.00\exp(0.15)=4.647\) L/h.

  2. Under the model assumptions, what is the covariance of log clearance for two different occasions in the same subject?

    Solution: The shared term is \(\eta_i\); the occasion effects are independent. The covariance is \(\omega_{\eta}^2\).

  3. Why is one independent occasion effect per observation inconsistent with the usual IOV model?

    Solution: The IOV effect is shared across records in an occasion. Drawing one per observation removes that within-occasion sharing and defines a different dependence structure.

  4. A subject has only one observed occasion. Can that subject’s data alone distinguish interindividual variance from interoccasion variance?

    Solution: Generally, no. With only one occasion, the two sources both contribute to the observed log-scale variation, and that subject provides no between-occasion contrast to separate them.

  5. In a mrgsolve simulation, a supplied KAPPA_CL value changes on every row, although the rows belong to the same occasion. What should be checked?

    Solution: Check the occasion indexing and the input construction. The same occasion-specific value must be carried across all records in that occasion and changed only at the occasion boundary.

Clinical Biostats