# A Digital Twins Machine Learning Model for Forecasting Disease Progression in Stroke Patients
## 3 Data Processing  
Using our proposed framework, the \(\beta\)-VAE model was used to generate possible next steps in a patient's trajectory. Our model was trained on data extracted from the Medical Information Mart for Intensive Care (MIMIC)-IV database [17]. The database contains 1216 patients with useable trajectories that experience ischemic stroke at some point in their record, as identified by International Classification of Diseases, Ninth Revision (ICD-9) or International Classification of Diseases, Tenth Revision (ICD-10) codes (Supplementary Table S1). Based on current coding practices and prior ischemic stroke literature [18], these patients were selected as our ischemic stroke population. The trajectories of these patients were modeled using data leading up to and following the point at which they experienced an ischemic stroke. Data were de-identified in compliance with the Health Insurance Portability and Accountability Act (HIPAA) and were collected retrospectively and, as such, Institutional Review Board (IRB) approval was not required per the Federal Health and Human Services Common Federal Rule [19]. Covariates used to model patient trajectory included presence of ischemic stroke within the simulation window. In addition to ischemic stroke, model inputs included prothrombin time (PT), partial thromboplastin time (PTT), creatinine, glucose, red cell distribution width (RDW), white blood cell count, hematocrit, platelet count, international normalized ratio (INR) red blood cell count, potassium, sodium, phosphate, mean corpuscular hemoglobin (MCH), and mean corpuscular volume (MCV). Several laboratory measures, including PT and PTT, were chosen due to the importance in measuring propensity for clotting, while other labs like sodium were chosen due to their frequency of measurement and informativeness with respect to other aspects of patient health. Over 99% of patients had all features present at some point in their trajectories. For lab measurements,result values were log-transformed to address the skewness of the distributions as well as to help the model account for the non-negative nature of such values. All inputs were standardized by mean and standard deviation to enhance the model's learning process. All values were reverted to their raw values, i.e., the standardization and log-transformation were reversed, before analysis. Patients trajectories were modeled using measurements of patients' clinical features, averaged over equally-sized bins that spanned the patients' histories. These bins begin and end at the earliest and latest measurement times in each patient's history. We defined a measurement vector \(x_{i}(t)\) as the list of averages for the covariates measured in patient \(i\) over the \(t\)th bin. Adjacent bins were grouped into threes to use as inputs into the model. We refer to these inputs as \"time window vectors\", denoted by  
\[v_{i}(t)=\{x_{i}(t),\ x_{i}(t-1),\ x_{i}(t-2)\}. \tag{1}\]  
The time window vector represents a dynamic snapshot of the patient's state at a particular point along their trajectory. Ideally, we would like to model the patient's history with as much fine-grained detail as possible. However, due to limitations in the frequency of patient visits, a bin size that is too small would result in many empty bins which would not be usable by the model, hampering model learning. To balance this desire for detail and utility, a bin size of 90 days was found to be most effective. Patients were partitioned 90%:10% into training and testing groups, respectively, with o1094 patients in the training set and 122 patients in the test set. These sets of patients were then used to generate the time window vectors for use in the model. The vectors from the training set were further split 8:1 into train and train validation sets, to be used for model selection. Time window vectors with more than 25% of their measurements missing were removed. Missing data was filled in either with last-observation-carried forward (when possible) or imputation with the feature average.