From phenotype definitions to cohort targets
A virtual population may need to represent clinical features such as disease subtype, biomarker status, or prior treatment. Before assigning any feature, define exactly what counts as each phenotype and who belongs in its denominator. A prevalence target is meaningful only for a specified population and definition: for example, the proportion of eligible virtual patients who are biomarker-positive at baseline. Changing the eligibility definition, measurement rule, or time point changes the target being represented.
Phenotypes can be represented in two common ways. A mutually exclusive categorical variable assigns each patient to exactly one category, such as subtype A, subtype B, or subtype C. Its category prevalences must sum to one. A set of binary phenotype indicators records whether each feature is present or absent. These features may overlap: one patient can be positive for two biomarkers, so their individual prevalences need not sum to one. A missing or unknown status should not silently be treated as negative; either define how it is handled or represent it as an explicit category when appropriate.
The assignment step is not merely a formatting choice. A phenotype may be associated with patient parameters or with other phenotypes. Attaching labels independently to existing parameter vectors can therefore produce a cohort with the requested marginal prevalences but implausible combinations. The earlier material on why matching marginals can distort joint structure motivates a central safeguard here: check both the requested marginal counts and any important co-occurrence structure.
Exact-count assignment
For one binary phenotype with target prevalence \(p\), the exact target count is \(k=np\). If \(k\) is an integer, a cohort can be constructed with precisely \(k\) positive patients and \(n-k\) negative patients. When assigning labels to a fixed candidate pool, randomly choosing \(k\) candidates without replacement gives every candidate the same chance \(k/n\) of receiving the label while fixing the cohort count. This randomization avoids always assigning the phenotype to patients in a particular row order, but it does not by itself preserve associations between the phenotype and patient parameters.
For mutually exclusive categories, exact target counts must be nonnegative integers that sum to \(n\). If every \(np_j\) is an integer, those counts reproduce all targets exactly. If not, an exact match is impossible at that cohort size. Counts must then be chosen using a stated rounding rule, or the cohort size or targets must be reconsidered. Quietly rounding each category separately can yield counts that do not sum to \(n\), so the allocation must be checked as a whole.
Worked Example: Exact Allocation for a Binary Phenotype
A hypothetical virtual cohort will contain \(n=120\) patients, and the target prevalence of a baseline marker is \(p=0.30\). The exact positive count is
Because 36 is an integer, assign the marker-positive phenotype to exactly 36 patients and the marker-negative phenotype to the remaining \(120-36=84\). The resulting cohort prevalence is \(36/120=0.30\), or 30.0%. If the 36 positive labels are assigned by a random draw without replacement from the candidate pool, each candidate has probability \(36/120=0.30\) of being selected, but the total remains exactly 36.
This calculation verifies the marginal prevalence only. If marker status is expected to be associated with a parameter such as receptor abundance, selecting 36 candidates uniformly from a pool without regard to that relationship may produce an inappropriate association. The selection rule must reflect what is known about the phenotype and the candidate patients.
Worked Example: Mutually Exclusive Categories With Noninteger Targets
A hypothetical cohort has \(n=95\) patients and three mutually exclusive subtype targets: \(p_1=0.50\), \(p_2=0.30\), and \(p_3=0.20\). The targets sum to one, but their unrounded counts are
The first two target counts are not integers, so no allocation of 95 patients can reproduce all three targets exactly. One possible allocation is \((k_1,k_2,k_3)=(48,28,19)\), which sums to 95. Its cohort prevalences are \(48/95=0.5053\), \(28/95=0.2947\), and \(19/95=0.2000\), or 50.53%, 29.47%, and 20.00%. The deviations from the targets are respectively \(+0.53\), \(-0.53\), and \(0.00\) percentage points.
The alternative allocation \((47,29,19)\) also sums to 95 and has deviations of \(-0.53\), \(+0.53\), and \(0.00\) percentage points. The two options have equal absolute deviations here. A reproducible implementation should state how such ties are resolved—for example, a fixed priority rule or a randomized tie-break—and report the achieved counts and prevalences rather than claiming an exact match.
Probability-based generation
A probability-based approach assigns phenotypes according to a probability model rather than fixing the realized counts in advance. For a binary phenotype, suppose each patient is assigned independently with probability \(p\). If \(X_i=1\) when patient \(i\) is positive and \(X_i=0\) otherwise, then the cohort count \(K=\sum_{i=1}^{n}X_i\) follows a binomial distribution. This model assumes a common probability \(p\) for every patient and independence of assignments across patients. Those are assumptions about the generation procedure, not facts guaranteed by using random numbers.
For \(J\) mutually exclusive categories, independent patient-level draws from category probabilities \(p_1,\ldots,p_J\), where \(p_j\geq 0\) and \(\sum_j p_j=1\), produce multinomial counts. Their expected values are \(np_j\), but the realized counts vary and always sum to \(n\). Separate Bernoulli draws for each category would not enforce mutual exclusivity: one patient could be assigned multiple categories or none. The categorical draw must select exactly one category per patient.
Worked Example: Variability in a Probability-Based Cohort
For a hypothetical cohort of \(n=40\), each patient is independently assigned a binary phenotype with probability \(p=0.25\). The count \(K\) has mean and standard deviation
Suppose one generated cohort contains 8 positive patients. Its observed prevalence is \(8/40=0.20\), which is 5 percentage points below the target. This does not contradict the assignment model: the count is random. The exact probability of obtaining 10 positive patients is
Thus, even the count equal to the expected count occurs in only about 14.44% of cohorts under this model. Probability-based generation is appropriate when cohort-to-cohort count variability is intended; it is not the method to use when every generated cohort must have exactly 10 positives.
Preserving co-occurrence while matching prevalence
Matching each phenotype prevalence separately does not determine how phenotypes occur together. For two binary features A and B, the marginal targets \(p_A\) and \(p_B\) do not specify \(P(A\text{ and }B)\). Independent assignment would imply \(P(A\text{ and }B)=p_Ap_B\), but that value is justified only if independence is an intended assumption. In a clinical population, two features may co-occur more or less often than independence predicts.
Worked Example: Exact Marginals With a Joint Target
In a hypothetical cohort of 100 patients, the targets are 40% positive for feature A, 30% positive for feature B, and 18% positive for both. These targets imply four joint categories. The both-positive count is 18. The A-positive, B-negative count is \(40-18=22\); the A-negative, B-positive count is \(30-18=12\); and the neither-positive count is \(100-18-22-12=48\).
The resulting table has counts 18, 22, 12, and 48, which sum to 100. The A marginal is \((18+22)/100=0.40\), the B marginal is \((18+12)/100=0.30\), and the joint prevalence is \(18/100=0.18\). If instead A and B were assigned independently at their marginal probabilities, the expected joint prevalence would be \(0.40(0.30)=0.12\), not 0.18. Independent assignment would therefore fail to represent the stated co-occurrence target.
When joint targets are known and exact counts are required, define compatible joint categories and allocate patients to those categories, checking that all cell counts are nonnegative and sum to the cohort size. When the cohort is drawn probabilistically, use a joint probability model consistent with the intended relationships. If only marginal targets are available, do not present an unverified independence assumption as a clinical fact. The limitation is substantive: matching marginals alone cannot recover a joint distribution that was never specified.
Choosing a method and checking the result
| Approach | What it guarantees | Main trade-off |
|---|---|---|
| Exact-count assignment | Prespecified counts in each assigned category, when feasible | Requires integer counts; the assignment rule must still preserve relevant patient-feature relationships |
| Independent probability-based assignment | Target probabilities in the generation model and target counts in expectation | Realized counts vary; independence may be inappropriate for related phenotypes |
| Joint-category assignment | Specified joint cell counts or joint probabilities, as configured | Requires enough joint information and feasible cell allocations |
After generation, calculate the observed count and prevalence for every categorical feature. For mutually exclusive categories, verify that counts sum to \(n\), that no count is negative, and that category prevalences sum to one. For overlapping features, check each marginal and, when relevant, the co-occurrence counts. In probability-based generation, compare observed counts with the intended probabilities while recognizing the expected sampling variation; a difference from the target is not automatically evidence of a coding error.
Also check that labels are attached to the intended patient records and that the phenotype definition, denominator, and handling of unknown status are consistent. A correct count assigned to the wrong patients is not a valid virtual population. Repeating probability-based generation with a new random seed can help reveal how much the realized prevalence varies, but it does not turn a variable-count method into an exact-count method.
A common mistake is to say, “The target is 25%, so a probabilistic cohort of 40 must contain 10 positive patients.” The correction is that 10 is the expected count under independent Bernoulli assignment, not a guaranteed realized count. If exactly 10 positives are required, set the count explicitly and assign exactly 10; if random variation is intended, report the realized count and retain the probability model. Another mistake is to match two marginal prevalences independently and assume their co-occurrence is therefore realistic. That conclusion requires an independence assumption, which must be justified rather than presumed.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions.
- A cohort has 80 patients and a binary phenotype target of 15%. How many positive patients are needed for an exact match?
- For 60 patients divided among three mutually exclusive categories with target probabilities 0.50, 0.30, and 0.20, are all target counts exact integers? State the counts.
- Under independent Bernoulli assignment with \(n=100\) and \(p=0.10\), give the expected positive count and its standard deviation.
- Two binary phenotypes have target prevalences 0.50 and 0.40. What joint prevalence would independent assignment imply? Does that value follow from the marginal targets alone?
Solutions. (1) \(80(0.15)=12\), so assign 12 positive patients and 68 negative patients. (2) The counts are \(60(0.50)=30\), \(60(0.30)=18\), and \(60(0.20)=12\). They are integers and sum to 60, so an exact allocation is feasible. (3) The expected count is \(100(0.10)=10\), and the standard deviation is \(\sqrt{100(0.10)(0.90)}=\sqrt{9}=3\) patients. (4) Independence would imply joint prevalence \(0.50(0.40)=0.20\). The marginal targets alone do not establish independence, so they do not determine that joint prevalence.