Tutorials › Nonlinear Mixed-Effects Models (NLME) › Sampling Covariates for Population Simulations

Simulation From Fitted Models · Tutorial 694 of 797

Sampling Covariates for Population Simulations

Learn to choose and check a covariate-generating distribution and apply the fitted covariate model to simulated individuals.

Intermediate 10 min read

What You'll Learn

  • Distinguish the target covariate population from the cohort used to represent it.
  • Resample observed covariate records jointly to preserve their empirical relationships.
  • Sample from a specified joint or conditional covariate distribution.
  • Apply fitted covariate effects using the model’s coding, reference values, and scale.
  • Diagnose implausible profiles and mismatches between simulated and target covariates.
  • Explain why independently sampling covariates or using mean covariates can misrepresent a population.

Why Covariates Must Be Simulated

A population simulation needs more than a fitted typical parameter value and a method for drawing random effects. It also needs a description of which kinds of individuals make up the simulated population. Age, body weight, genotype, renal function, and other covariates can shift individual parameters systematically. If the covariates are omitted or represented poorly, the simulated parameter and outcome distributions may not reflect the intended population—even when the fitted covariate relationships are applied correctly.

The task here is to generate covariate profiles for simulated individuals and use the fitted model to calculate their individual parameters. This is distinct from drawing random effects: covariates represent measured or specified characteristics of the target population, whereas random effects represent residual between-individual variation under the NLME model. In the workflow, generate a covariate profile, apply the fitted covariate model, and then draw the individual’s random effects according to the model.

Definition: A covariate profile is the set of covariate values assigned to one simulated individual. A covariate-generating distribution describes how profiles are selected for the target population. It may be the empirical distribution of observed profiles or a specified probability distribution. The covariate model maps each profile to an individual parameter value.

The target population must be stated before choosing a distribution. An observed cohort can be used as a practical representation of that population, but it is not automatically representative. A distribution specified from external knowledge can target a population that differs from the fitting cohort, but its assumptions and dependence structure must be defensible. In either case, the covariate generation step should use the same variable definitions, units, transformations, and category coding as the fitted covariate model.

From a Covariate Profile to an Individual Parameter

For illustration, suppose clearance has a log-linear covariate model with body weight and a binary sex indicator. Let \(W_i\) be individual \(i\)’s weight in kilograms, and let \(F_i=1\) for the category coded as female and \(F_i=0\) for the reference category. Let \(\eta_{CL,i}\) be the individual clearance random effect. A possible model is

$$ CL_i = CL_{\mathrm{pop}}\left(\frac{W_i}{70}\right)^{0.75}\exp(\beta_F F_i+\eta_{CL,i}). $$

Here, \(CL_{\mathrm{pop}}\) is the typical clearance for the reference sex at 70 kg, \(\beta_F\) is the fitted sex effect on the log scale, and the exponent 0.75 is a fitted or prespecified allometric exponent. The units of \(CL_i\) are the units of \(CL_{\mathrm{pop}}\), for example liters per hour. A simulated profile supplies \(W_i\) and \(F_i\); the fitted model supplies the covariate relationship. The random effect is drawn separately, unless a specific simulation task supplies its value.

The model form matters. A coefficient on the log scale is not an additive change in clearance: for a binary covariate, the multiplicative change is \(\exp(\beta_F)\). For a continuous covariate, the formula may use a centered value, a ratio to a reference value, a power model, or another fitted transformation. Substituting raw values into a formula with different coding or units changes the meaning of the model.

Assumptions for applying the fitted covariate model: The simulated covariates are defined and coded as in the fitted model; the model’s functional forms and coefficients are treated as applicable to the target population; and any dependence between covariates and random effects is either absent under the model or represented explicitly. These assumptions do not establish that the fitted model is correct for every possible population.

Two Ways to Generate Covariate Profiles

With empirical resampling, each simulated profile is selected from a row of observed covariate records. For a new population of simulated individuals, sampling rows with replacement is a common choice: the same observed profile can appear more than once, and no individual row is guaranteed to appear. Resampling whole rows preserves observed combinations of covariates, including their empirical associations.

With a specified distribution, profiles are generated from a probability model or a set of probabilities chosen to represent the target population. This can support population definitions beyond the observed cohort, but it requires specifying more than marginal distributions when covariates are related. For example, a conditional distribution for weight within age group preserves a different structure from drawing age group and weight independently.

ApproachWhat it representsMain check
Resample complete observed recordsThe empirical distribution of the cohort used as a stand-in for the target populationDoes the cohort plausibly represent the intended population?
Sample from a specified joint distributionA population described by the chosen probability modelAre marginal distributions, dependencies, and ranges plausible?
Sample each covariate independentlyThe product of the marginal distributionsIs independence actually a defensible assumption?
Use a single typical profileA population in which every individual has the same chosen covariatesIs a population distribution really unnecessary for the question?

Worked Example: Resampling Observed Profiles Jointly

Suppose a hypothetical cohort contains the following five observed profiles. Weight is in kilograms; the last column is the binary covariate \(F\).

RecordWeight \(W\)\(F\)
1551
2621
3780
4840
5681

For a hypothetical simulation of four new individuals, suppose the sampled record indices are 2, 5, 2, and 4. The resulting profiles are \((62,1)\), \((68,1)\), \((62,1)\), and \((84,0)\). Record 2 appears twice because sampling is with replacement. Each profile remains an observed weight-sex combination; the simulation has not invented a combination by pairing values from different records.

In this small cohort, all three records with \(F=1\) have weights below 70 kg, whereas the two records with \(F=0\) have weights above 70 kg. Resampling whole rows retains this association in the empirical distribution. Independently resampling weights and \(F\) would allow, for example, the combination \((84,1)\), which is not present in the cohort. That combination may be plausible in the actual target population, but the observed rows alone do not establish that it should be generated.

This procedure represents the cohort’s empirical profile distribution, not automatically the distribution of every population of interest. If the cohort was selected from a narrow clinical setting, the resulting simulated profiles inherit that restriction. The choice is justified only when the cohort is an appropriate stand-in for the simulation target.

Worked Example: Applying Covariate Effects to a Profile

Use the clearance model above with hypothetical fitted values \(CL_{\mathrm{pop}}=5.00\) L/h and \(\beta_F=-0.20\). Consider a simulated individual with \(W_i=84\) kg, \(F_i=1\), and a supplied random-effect value \(\eta_{CL,i}=0.10\). Calculate the individual clearance.

First substitute all values into the fitted model:

$$ CL_i=5.00\left(\frac{84}{70}\right)^{0.75}\exp\bigl((-0.20)(1)+0.10\bigr)\ \mathrm{L/h}. $$

The weight ratio is \(84/70=1.20\), and \(1.20^{0.75}\approx1.147\). The total exponent is \(-0.20+0.10=-0.10\), so \(\exp(-0.10)\approx0.9048\). Therefore,

$$ CL_i \approx 5.00(1.147)(0.9048)=5.19\ \mathrm{L/h}. $$

The result is an individual parameter value conditional on this profile and this supplied random effect, under the stated model. It is not obtained by adding \(-0.20\) L/h to clearance: the sex coefficient acts multiplicatively through the exponential. In a simulation that draws random effects, the value of \(\eta_{CL,i}\) would be generated according to the fitted random-effects model rather than chosen to fit the covariate profile.

Worked Example: Sampling From a Specified Joint Distribution

Suppose a hypothetical target population is represented by this discrete joint distribution. The table gives the probability of each weight-sex profile; the probabilities sum to 1. Use the same clearance model, with \(CL_{\mathrm{pop}}=5.00\) L/h and \(\beta_F=-0.20\), and set \(\eta_{CL}=0\) to isolate the covariate effect.

Weight (kg)\(F\)Probability
6010.35
8010.25
7000.15
9000.25

For each row, apply the model. At 60 kg with \(F=1\), \(CL=5.00(60/70)^{0.75}\exp(-0.20)\approx3.65\) L/h. At 80 kg with \(F=1\), \(CL=5.00(80/70)^{0.75}\exp(-0.20)\approx4.53\) L/h. At 70 kg with \(F=0\), \(CL=5.00\) L/h. At 90 kg with \(F=0\), \(CL=5.00(90/70)^{0.75}\approx6.04\) L/h.

The population-weighted mean of these covariate-adjusted values is

$$ 0.35(3.65)+0.25(4.53)+0.15(5.00)+0.25(6.04) \approx4.67\ \mathrm{L/h}. $$

To simulate individuals, draw a row according to its probability and calculate that individual’s parameter from the row. The weighted calculation summarizes the expected covariate-adjusted clearance for this finite distribution when \(\eta_{CL}=0\); it is not a substitute for generating individual profiles when the goal is a population of simulated individuals. In particular, applying a nonlinear covariate function to a mean profile need not give the same result as averaging parameter values across profiles.

Justification for Empirical Resampling

The reason row resampling reproduces the cohort’s empirical distribution can be written directly. Let \(x_1,\ldots,x_N\) be the observed covariate profiles and let \(g(x)\) be any quantity calculated from a profile, such as its covariate-adjusted typical clearance. Define one resampled profile \(X^*\) to have probability \(1/N\) of equaling each observed row. Then

$$ E\{g(X^*)\mid x_1,\ldots,x_N\} =\sum_{j=1}^{N}\frac{1}{N}g(x_j) =\frac{1}{N}\sum_{j=1}^{N}g(x_j). $$

Thus the expected value of a function of a resampled profile equals its average over the observed records. If \(M\) profiles are independently sampled with replacement, the average of their \(g\)-values has this same conditional expectation. This establishes what resampling does: it targets the empirical distribution. It does not prove that the empirical distribution is representative of an external target population.

1
Define the target.
State the population the simulated profiles are intended to represent and identify the covariates needed by the fitted model.
2
Choose the profile distribution.
Use complete observed rows when the cohort is a defensible empirical stand-in, or specify a joint or conditional distribution when targeting another population.
3
Generate profiles and calculate parameters.
Sample profiles, check their values, then apply the fitted covariate functions with the original coding and units.
4
Inspect the generated population.
Compare its covariate summaries and combinations with the intended target, and investigate impossible or unexpected profiles before interpreting simulated outcomes.

Diagnostics, Alternatives, and Limitations

At minimum, compare simulated and intended covariate distributions using category proportions, means or quantiles for continuous variables, and ranges. Also inspect joint patterns: marginal summaries can match while combinations are wrong. Check for values outside the fitted model’s support, impossible category combinations, missing-value handling, and inconsistent units. If simulated profiles differ from the target, first determine whether the distribution was specified incorrectly, the observed cohort was an unsuitable stand-in, or the sampling code failed.

Independent marginal sampling is appropriate only when independence is a reasonable assumption for the target population or when the simulation deliberately defines such a population. Otherwise it can distort covariate combinations and, through nonlinear covariate effects, change the distribution of individual parameters. Joint empirical resampling preserves observed dependencies but cannot generate profiles outside the observed combinations. A specified joint or conditional model can represent broader combinations, but the result depends on that model. A single typical profile is simpler, but it removes covariate variation and cannot represent between-profile differences in parameters.

A further limitation is extrapolation. Applying a fitted covariate relationship to values far beyond those represented in the fitting data assumes that the same relationship continues to hold there. The covariate distribution and the fitted covariate model are separate ingredients: a plausible profile generator does not validate the parameter relationship, and a well-fitting relationship does not make the source cohort representative. Population simulations are conditional on both choices.

Common Mistake

Pitfall: “I will sample each covariate from its observed marginal distribution; that preserves the observed population.” This is wrong when the covariates are associated, because independent draws generate the product of the marginal distributions rather than the observed joint distribution. Correction: Resample complete covariate records or specify a joint or conditional distribution that represents the target. Check the resulting combinations, not only each covariate’s marginal summary.

Another common error is to use the mean covariate profile for every simulated individual and call the result a population simulation. That can be useful for a typical-profile calculation, but it removes covariate heterogeneity. With nonlinear relationships, the parameter calculated at the mean profile generally differs from the average parameter across profiles, as the discrete distribution example illustrates.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. A cohort has linked records of age and body weight. What is preserved by resampling complete rows that may be lost by independently sampling age and weight?
  2. In the model \(CL_i=5(W_i/70)^{0.75}\exp(-0.20F_i+\eta_{CL,i})\), calculate \(CL_i\) for \(W_i=70\) kg, \(F_i=1\), and \(\eta_{CL,i}=0\).
  3. A simulated population matches the observed mean weight but includes many weight-sex combinations absent from the source cohort. Name one likely explanation and one diagnostic to perform.
  4. Why does resampling observed profiles not, by itself, show that the simulated population represents an external target population?

Solutions. (1) Complete-row resampling preserves the observed joint combinations and empirical association between age and weight; independent sampling replaces that joint distribution with the product of the two marginals. (2) Substitute the values: \(CL_i=5(70/70)^{0.75}\exp(-0.20(1)+0)=5\exp(-0.20)\approx4.09\) L/h. (3) Independent marginal sampling is one possible explanation. Compare joint combinations or a cross-tabulation in the simulated profiles with the source data and the intended target. (4) Resampling reproduces the cohort’s empirical distribution, as shown by the expectation of \(g(X^*)\); representativeness requires a separate justification about how the cohort relates to the external population.