## 2 Materials and Methods
### Overview  
Our patient cohort generator algorithm was developed in Microsoft Excel and implemented using Visual Basic for Applications (VBA). It is designed to produce synthetic patient-level datasets based on user-defined variables, probability distributions, and clinical constraints. All inputs are configured via a structured Excel interface, while the underlying computations and logic are handled by the VBA engine. The following sections outline the key components of the method, including parameter specification, data generation, and constraint handling (Figure 1).  
The model's pipeline begins with the input parameters. For each parameter, the user specifies its type. For continuous variables, the user specifies the probability distribution, as well as the mean, standard deviation, and the minimum and maximum plausible values. For binary variables, only the prevalence is required. The model also allows for a correlation matrix to be defined. Furthermore, equations to define hard limits or linking one parameter to another can be specified. The process then moves to generate random numbers, which are used to sample from CDF by applying the inverse CDF, generating initial raw values for every patient.  
To prepare the data for correlation, the initial raw values are standardized into Z-scores, which shifts their distribution to have a mean of zero and a standard deviation of one. This standardization is essential because it brings all variables onto a common scale, a prerequisite for the subsequent correlation step (Cholesky Decomposition). The correlation matrix is then decomposed into a lower triangular matrix, which is then multiplied by the vector of Z-values for each synthetic patient. This transforms the independent data into a set of correlated Z-scores that reflect the complex, real-world relationships between variables.  
Before applying hard limits and resolving linked parameters, the model must then evaluate dependency levels, establishing a logical calculation order. Parameters with no dependencies are calculated first (Level 1), followed by those that depend on level 1 parameters only (Level 2), and so on. With the calculation order set, the model can then apply hard limits, which are user-defined rules that prevent clinically implausible scenarios, such as a pediatric patient being recorded as a smoker. Finally, it can resolve linked parameters, calculating their values deterministically based on the already-finalized dependent variables.  
The next step is to convert the correlated Z-values to final values back from their original scale. Following this, the model will quantify the binary parameters. The generated values are compared against a quantile of the generated sample that corresponds to the target prevalence of the variable. This ensures that the final proportion of binary outcomes in the synthetic cohort precisely matches the user input.  
Figure 1: The flow diagram of the cohort-generation pipeline.  
Due to the slight distortion of mean values of the continuous parameters during the correlation application, as well as clamping the values between the minimum and maximum values, mean adjustment is performed to align the simulated means with user inputs, after which minimum and maximum bounds are enforced to clamp any values that fall outside a plausible range, and this process is repeated until the mean error is sufficiently small.