Full text
DEGREE’S FINAL DISSERTATION Degree in Chemical Engineering Generation and evaluation of synthetic Covid‐19 patients data Report and Appendix Author: Alex Martin Peyrona Director: Magda Ruíz Ordóñez Co‐Director: Luis Eduardo Mujica Delgado Submission Date: January 17th 2023
DISSERTATION RESUM Aquest treball de final de grau es centra en un problema molt comú avui dia: la falta de dades. Els cientifics de dades necessiten volums grans de dades per produir eines precises i acurades. En aquest document s’investiga sobre un conjunt de dades de pacients covid, el qual es descriu en tots els seus aspectes. L’objectiu es produir dades noves, per tant, en centrar la recerca en diferents algoritmes i models que ho permetin. S’han triat tres algoritmes que estan basats en les copules gaussianes, reds generatives adversaries i reds bayesianes, cadascun. Es generen les dades i s’estudia com de bones son. La evaluació d’aquestes es duu a terme per dues bandes. Per una banda, mitjançant un test d’hipótesis, s’evalua si la distribució sintètica es similar (estadisticament) a la distribució original, comparant estadístics com la variança i la mediana. D’altre banda, s’evalua si es mantenen les correlacions de les dades originals a les sintètiques mitjançant un anàlisis de similaritat utilitzant matrius de coeficients de correlació. S’efectua una diferència de matrius (original i sintètica), la qual, idealment, hauria de ser molt propera a zero. Tot plegat, s’analitzen els resultats de les dues evaluacions i es proposen idees per seguir aquesta branca de la investigació. A més, s’analitza l’impacte econòmic i ambiental del projecte I
Generation and evaluation of synthetic Covid‐19 patients data RESUMEN Este trabajo de fin de grado se centra en un problema muy común hoy en día: la falta de datos. Los científicos de datos necesitan grandes volúmenes de datos para producir herramientas precisas. En este documento se investiga sobre un conjunto de datos de pacientes covid, el cual se describe en todos sus aspectos. El objetivo es producir datos sintéticos, por lo tanto, se centra la investigación en diferentes algoritmos y modelos que lo permiten. Se han elegido tres modelos se basan en las copulas gausianas, redes generativas adversarias y redes bayesianas, cada uno. Se generan los datos y se estudia cómo de buenos son. La evaluación de estas se lleva a cabo por dos lados. Por uno, mediante una prueba de hipótesis, se evalúa si la distribución sintética es similar (estadísticamente) a la distribución original, comparando estadísticos como la varianza y la mediana. Por otro lado, se evalúa si se mantienen las correlaciones de los datos originales en las sintéticas mediante un análisis de similitud utilizando matrices de coeficientes de correlación. Se efectúa una diferencia de matrices (original y sintética), la cual, idealmente, debería ser muy cercana a cero. Finalmente, se analizan los resultados de las dos evaluaciones y se proponen ideas para seguir esta rama de la investigación. Además, se analiza el impacto económico y ambiental del proyecto. II
DISSERTATION ABSTRACT This final degree dissertation focuses on a very common problem nowadays: the lack of data. Data scientists need large volumes of data to produce accurate and precise tools. In this document, research is carried out on a set of COVID patient data, which is described in all its aspects. The objective is to produce synthetic data, therefore, focusing the research on different algorithms and models that allow it. Three algorithms have been chosen that are based on Gaussian copulas, adversarial generative networks, and Bayesian networks, each one. The data is generated and studied how good it is. The dataset is evaluated in two ways. On one hand, performing a hypothesis test, the synthetic distribution is evaluated to be similar (statistically) to the original distribution, comparing statistics such as variance and median. On the other hand, it is evaluated whether the correlations of the original data are maintained in the synthetic ones through a similarity analysis using correlation coefficient matrices. A difference of matrices (original and synthetic) is carried out, which should ideally be very close to zero. To sum up, the results of the two evaluations are analyzed, and ideas are proposed to follow this branch of research. In addition, the economic and environmental impact of the project is analyzed. III
Generation and evaluation of synthetic Covid‐19 patients data GLOSSARY APACHE_II: Acute Physiology and Chronic Health disease Classification System II BMI: Body Mass Index CNN: Convolutional Neural Network CRP: C‐Reactive Protein CSV: Comma separated values CTGAN: Conditional Generative Adversarial Network DBP: Diastolic Blood Pressure DD: DataDescriber DG: DataGenerator DS: DataSynthesizer FiO2: Fractional Inspired Oxygen GAN: Generative Adversarial Network GC: Gaussian Copula GCS: Glasgow Coma Scale ICT: Information and Communication Technologies IT: Information Technology MWU: Mann‐Whitney‐Wilcoxon U Test PaCO2: Partial Pressure of CO2 PaO2: Oxygen partial pressure PPE: Personal Protection Equipment ROX: Ratio of Oxigen SBP: Systolic Blood Pressure IV
DISSERTATION SDV: Synthetic Data Vault SMOTE: Synthetic Minority Oversampling Technique SOFA: Sequential Organ Failure Assessment SpO2: Oxygen Saturation V
Generation and evaluation of synthetic Covid‐19 patients data Acknowledgments Albert Einstein, a while ago, said ”It’s not that I’m so smart, it’s just that I stay with problems longer.” I wouldn’t dare to compare myself to him, but definitely this is something that represents me. This thesis has been a complete challenge for me, Data Science is a wonderful discipline with a lot of different fields, each one wider than the one before. Besides from wide, this fields are complex, they involve maths, statistics, computer science, programming,... and much more knowledge and skills needed to succeed. So, I really had to stay stuck to the problem. There’s been a lot of up and downs, big goals, step backs that needed to be taken, and the road was everything but plain. Anytime anyone encounters this kind of roads, the worst thing you can do is drive it by yourself and luckily my journey’s been filled with amazing people that I want to give special thanks in this space. First of all, thanks Dra. Magda L. Ruiz and Dr. Luis E. Mujica, for trusting me and seeing potential from day one. I know this is just a little part of what we wanted to do, and I really hope you can get there eventually, every idea you have is amazing and I’m a hundred percent sure that you will. Thanks for keeping an eye on me these months where I had to be a very multitasking person, in a moment in my life full of changes and important decisions, for giving me the space I needed and for being so uplifting in every meeting we had, this is what really got me through the semester. You always provide such valuable insights and without them, this output would have been much different (I hope no one ever knows what different means!). My friends, all of them, to all the people that have been with me during this time, it doesn’t matter if you’ve been with me the whole degree, the whole thesis, just the last month or a whole life, thank you for understanding me every time I had to say ”No, I can’t, I have to work on my dissertation”, thank you for staying. Specially I want to thank Carlos Pozo, I already consider you a friend, not just an ex‐teacher, for always helping me out when I needed it, for bringing sincerity and motivations in each chat we had. Also Cristina Mendoza, you’ve been probably my alter ego during the last year and a half and I just can’t stop admiring you and feeling so happy for what life will bring you in your next steps, thanks for being there always. And of course, to all my friends in Castelldefels, my day to day, my past, my present and hopefully my future, thanks for being my safe place when everything seemed so dark and greedy, by your side everything looked brighter! And last but not least, my parents and siblings, for being that rock you sit down to catch your breath, I found it in every step of the way. Thank you for always supporting my decisions, for listening my overthinking about every single word in this dissertation, for faking your understanding (about the topic) so I would just easily express what I needed to. You’ve been my diesel, thank you. VI
Contents RESUM I RESUMEN II ABSTRACT III 1 INTRODUCTION 10 1.1 Dissertation Goals 10 1.2 Nomenclature 11 2 Script set up 12 2.1 Directories 12 2.2 Executing the script 12 2.2.1 Jupyter Notebook 12 2.2.2 PyCharm 12 3 Data Generation 14 3.1 Resampling 14 3.2 Imbalanced datasets 15 3.3 Synthetic Data 15 4 Data Description 17 4.1 Data Structure 17 4.2 Variables 17 4.2.1 Meaning 17 4.2.2 Descriptive Statistics 19 4.3 Limitations 20 5 Data Generation 21 5.1 Algorithms 21 5.2 Gaussian Copula 22 5.2.1 Data generation 23 5.3 Generative Adversarial Network 24 5.3.1 Generative Models 24 VII
Generation and evaluation of synthetic Covid‐19 patients data 5.3.2 Structure of a GAN 25 5.3.3 Data Generation 26 5.4 DataSynthesizer 27 5.4.1 Bayesian Network 28 5.4.2 Data Generation 28 6 Data Evaluation 31 6.1 Hypothesis Test 31 6.1.1 U‐Test 31 6.1.2 Levene’s Test 33 6.1.3 Results 34 6.2 Similarity Analysis 34 6.2.1 Correlation Matrix 35 6.2.2 RSME 36 6.2.3 Results 37 7 Conclusions 39 8 Next Steps 42 8.1 Predictive model for different cases. 42 8.1.1 Part I 42 8.1.2 Part II 43 8.1.3 Limitations 44 8.2 Improve Synthetic Data Models 44 8.3 Generating and testing data on bigger datasets 44 9 Economical and Environmental Analysis 45 9.1 Economical Analysis 45 9.2 Environmental Analysis 46 9.3 Social Impact 46 REFERENCES 47 APPENDIX 51 VIII
DISSERTATION estimate the standard error of an estimator, or to select a sample of a certain size to achieve a desired level of precision. 3.2 Imbalanced datasets A lot of times, data scientists encounter themselves in a situation where there’s more data of a class A than from a class B (in this case there’s much more information about male patients (A) than women patients(B)). This can lead to a biased algorithm and producing, therefore, biased conclusions. SMOTE (Synthetic Minority Oversampling Technique) [7] faces this matter, it can be done by over sampling the minority class or undersampling the majority class. 1. Undersampling: consists of discarding a number of observations of the class that is presented too often. This is a very straightforward technique, but it’s only recommended to use when there’s a big amount of data, since the scientist would need to end up having still a lot of observations to develop an accurate tool. 2. Oversampling: intuitively, it’s the opposite of undersampling, add more data to the class that is presented less often. Typically the existing data is duplicated ending up with more observations of this smaller class. The problem here is that just plain oversampling won’t add new information to the dataset, usually because it’s done using duplicated observations. The great thing of SMOTE is that generates data with a small perturbation that leads to complete new data. This happens because the algorithm gets an observation as an input, performs k‐nearest neighbors, takes a vector between the observation and a neighbor, multiplies the vector by a number between 0 and 1, adds the vector to the dataset and the new data point is already done. This is a simple explanations of how SMOTE works, for more clarity, the diagram in Figure 2 has been made. 3.3 Synthetic Data There’s also the case when you do not need to resample your data in order to obtain a better performance of a model, duplicate values or synthesize news for dealing with imbalanced datasets, sometimes you just need to expand your source in order to have more observations and being able to develop better tools. The point is removing the barrier of data lack and this section is the core of the whole project. 15
Generation and evaluation of synthetic Covid‐19 patients data Figure 2: Simple SMOTE visualization. Uses K‐Neighbors, being K=4. Synthetic data is completely new data generated by an algorithm. It’s needed to be similar statistically speaking (the variables themselves and the relationships between them). In the following sections this is going to be uncovered and studied with further detail. 16
DISSERTATION 4 Data Description The dataset this dissertation works on is provided by Hospital Clinic de Barcelona. The aim of this section is to briefly understand which variables the models will have to take into account. 4.1 Data Structure Cambridge Dictionary provides this definition for dataset: A dataset is a collection of separate sets of information that is treated as a single unit by a computer. In this case, the dataset is tabular and its composed of 27 variables and 156 observations. It hasn’t been the need for cleaning or processing the data since it already was ready for working on it, the models neither specify any kind of preprocessing for the input. Being this said, it’s important to clarify that the following variables won’t be taken into account for any process in this dissertation: •Unnamed : 0. This variable is the dataset index, it does not add any valuable information and, therefore, not needed during the whole project. •Hosp_ID. It’s the patients identification, for privacy reasons this variable is not used in this project. •APACHE_II.factor This is the same as APACHE_II, but factorized, so it’s a discrete version. The factors do not add any kind of valuable information and it makes the exercise much more complex, that’s why it’s been also removed. 4.2 Variables Now let’s study the variables presented in the data. Demography, meaning and distributions are the main points in the description. 4.2.1 Meaning In Table 1 each variable is accompanied of a brief description of its meaning and which type of data is it. 17
Generation and evaluation of synthetic Covid‐19 patients data Variable Definition Data Type Age Patient’s age Integer Gender Patient’s gender Integer Heart_rate Patient’s heart rate Integer SBP Systolic Blood Pressure Integer DBP Diastolic Blood Pressure Integer SpO2 Oxygen saturation Integer Max_SpO2 Maximum oxygen saturation Integer Temperature Patient’s temperature Float BMI Body Mass Index Integer pH Acidity measure Float PaCO2 Partial pressure of CO2Float GCS Scoring system to measure patient level of consciousness Integer APACHE_II Disease severity classification system used in the ICU Float SOFA Sequential Organ Failure Assessment Integer PaO2_FiO2 Ratio of arterial oxygen partial pressure to fractional inpired oxigen Integer Creatinine Byproduct left over during the metabolism stage in muscle proteins Float Leucocytes Type of blood cells made in the bone marrow that is part of the body immune system Float CRP Protein synthesized and released by the liver when there’s inflammation in the patient’s body Float D_dimer Protein fragment made after a blood clot dissolves Integer ROX_index Ratio of oxygen saturation by fraction inspired oxygen Float Symptom_to_ICU Coeficient Integer Hosp_to_ICU Coeficient Integer Survival 1 if the patient has survived and 0 if the patient did not Integer Intubation 1 if the patient has been intubated and 0 if the patient hasn’t Integer Table 1: Variables description: definition and type of data 18
DISSERTATION 4.2.2 Descriptive Statistics Now the description takes a more statistical approach. For the statistical description it’s been chosen two position and a dispersion metrics, together with the minimum and maximum of each variable. This is shown in Table 2 Variables Mean Median Variance Minimum Maximums Age 62 62 134,56 30 90 Gender 0,28 0 0,2 0 1 Heart_rate 81,41 80 277,06 35 140 SBP 122,84 121,5 382,82 68 180 DBP 67,39 67 155,69 30 110 SpO2 89,73 90 32,17 60 99 Max_SpO2 96,76 98 9,7 86 100 Temperature 36,88 36,8 0,97 34,5 39,7 BMI 28,04 27 24,47 17 46 pH 7,43 7,45 0,01 7,2 7,59 PaCO2 35,53 33 82,92 16,9 71 GCS 14,75 15 1,95 3 15 APACHE_II 11,71 11 25,28 2 26 SOFA 4,92 4 5,41 0 13 PaO2_FiO2 133,38 124 4059,31 42 395 Creatinine 1,02 0,84 0,46 0,37 6,23 Leucocytes 8,06 7,12 20,1 1,24 27 CRP 52,4 16,39 7536,29 0,4 500 D_dimer 2252,88 900 21771405,62 200 36200 ROX_index 6,36 5,71 14,04 2,12 30,64 Symptom_to_ICU 10,26 9 35,79 1 45 Hosp_to_ICU 2,61 2 14,12 0 34 Survival 0,85 1 0,13 0 1 Intubation 0,5 0,5 0,25 0 1 Table 2: Statistical description of the variables Furthermore, for a clearer understanding of the population, in Figure 3, it’s plotted each variable’s distributions as density histograms. 19
Generation and evaluation of synthetic Covid‐19 patients data Figure 3: Density histograms for each variable in the dataset. 4.3 Limitations As it’s been said previously, the amount of data is decisive when it comes to train a model. In this case, there are only 156 observations. Definitely this is not a trustworthy amount of data [5] to develop any kind of regression or classification model, because the relationships between medical variables is not usually straightforward to see, a very complex pattern lays underneath these values. Even though there isn’t a set threshold for having enough data, understanding the purpose (healthcare system tool) and the background (type of variables and number of observations) allows understanding that having barely 150 observation won’t make it. In the following chapter three models for generating data are explored and tested. 20
DISSERTATION 5 Data Generation In previous sections the dataset it’s been described briefly in order to understand which types of variables are going to be worked with. This is now the state of the art of this project, analyzing how more data can be generated and how usable is it. Here it can be found the explanation for each chosen algorithm, the code implementation for this can be found in the Appendix. 5.1 Algorithms The presented algorithms follow the same structure across the project. First data is generated for each algorithm and three different cases of synthetic data: 50, 100 and 150 synthesized observations. Once data is generated then its plotted and compared to the original distributions. As a final step, there is an evaluation of this data using two different methods (see Data Evaluation section). The workflow in Figure 4 summarizes the whole process. Figure 4: Flow diagram for the whole project’s code. For this project, the following algorithms have been chosen to generate synthetic data and evalu‐ 21
Generation and evaluation of synthetic Covid‐19 patients data ate their output. The selection criteria it’s bibliographic, there is no information on synthetic patients data itself, so it’s been researched with methods are used for a more general issue, and then applied to the thesis problem. Amongst several algorithms, for its accessibility, usability and reliability, the ones that fitted the best for this thesis are (taking into account bibliographic and time limitations): 1. Gaussian Copula (GC) 2. Generative Adversarial Networks (GAN) 3. DataSynthesizer (DS) We’ll deep dive into them in further sections, but firstly, let’s start with the common steps. Firstly a general transformation happens in the dataset, where it’s loaded and some columns are deleted. It’s important to keep in mind that for generating ideal additional data two conditions must be fulfilled: 1. The new data variables should individually behave exactly as the original ones. 2. The new data should keep all the dependencies across variables and dimensions. All code‐related explanations can be found in the Appendix, in this section only results and models fundamentals will be studied in depth. 5.2 Gaussian Copula Copulas (statistical models) are actually a tool for attacking this two issues This is not easy to achieve, but the goal lies in getting as closer as possible to these to conditions, therefore ending up with a new dataset that behaviour and dependencies are the most similar possible to the original dataset. Let’s give it a glimpse from the mathematical side and then a definition more oriented to the matter itself [22]. In probability theory and statistics, a copula is a probability multivariate distribution function whose marginal distributions for each variable are uniformly distributed. Copulas describe the dependencies’ structures between random variables. Its mathematical definition: A n‐dimensional copula or n‐copula is a function C: [0,1]n→[0,1], this means that the copula takes as input d variables that are each uniformly distributed on the interval [0,1], and maps them to dvariables that are also uniformly distributed on the interval [0,1]. Also, a copula, fulfills the following conditions [9][8]: 22
DISSERTATION •C(1, ..., 1, uk,1, ...1) = ukfor each k≤ny∀uk∈[0,1], the copula is equal to ukif any of the arguments is uand the rest is 1. Basically this means, that the copula will only represent the dependencies of variable ukand the rest. •C(u1, ..., uk−1,0k, uk+1, ..., un) = 0 for any k≤n, the copula is zero if any of the arguments is zero. • The copula is n‐non‐decreasing , meaning if one variable’s value increases, the joint distribution of the remaining variables also increases. How can this be used for generating data? Well, even though it’s not the aim of this thesis understanding in deepness how generating data with copulas work, let’s try to understand a bit more about copulas. Suppose its aimed to generate synthetic data from a probabilistic model for nvariables X1, ..., Xn. To achieve the first aim its needed to find appropriate marginal distributions F1, ..., Fn. A simple approach is to approximate them by the corresponding empirical distribution functions. To achieve the second aim, however, its required to build a model for the joint distribution function H(x1, ..., xn). The key result, Sklar’s theorem [4], states that any joint distribution function can be written as: H(x1, ..., xn) = C(F1(x1), ..., Fn(xn)) (1) It basically says that any multivariate distribution can be represented as a combination of its marginal distributions (F(x)) and a copula function (C), which describes the dependence structure between the variables. [22]. Using this dependence structure described (usually using a correlation matrix) and reversing the building steps of a copula, synthetic data can be generated. 5.2.1 Data generation For generating new data using GC, SDV python package [10] has been used. The Synthetic Data Vault (SDV) is a synthetic data generation ecosystem of libraries that allows users to easily learn single‐table, multi‐table and time series datasets to later on generate synthetic data that has the same format and statistical properties as the original dataset[25]. The basic idea behind using a Gaussian copula in SDV is to first standardize the original data so that all variables have a mean of zero and a standard deviation of one. Then, the correlation matrix of the standardized data is used to define the Gaussian copula. The Gaussian copula is then used to generate synthetic data by sampling from the multivariate normal distribution defined by the correlation matrix. 23
Generation and evaluation of synthetic Covid‐19 patients data Once the synthetic data is generated, it is then transformed back to the original scale of the data. This synthetic data should preserve the same statistical properties as the original data. In Figure 5 each variable’s distribution is plotted and compared original versus synthetic. This case shows graphics for 50 new synthetic data (see the Appendix plot section for the two other cases). Figure 5: Distribution plots for each variable. 5.3 Generative Adversarial Network GAN are algorithms that generates a completely new output. This kind of algorithms are frequently used in image generation, even though, in this thesis it’s been intended to see how a GAN behaves when it comes to tabular data. Now let’s see what are GAN, starting by understanding generative and discriminative models, followed by seeing these networks structures. 5.3.1 Generative Models Before GAN are properly introduced let’s make clear what a generative model is. Generative models are those which generates new data, in contrast to discriminative models which divides data depending on a label. Let’s suppose there are data observations Xand their labels Y[32]. 24
DISSERTATION 6 Data Evaluation Given that the original distribution needs to be reproduced, it’d be expected that, statistically, original and synthetic one, are as similar as possible. Let’s recall that there are two goals that need to be accomplished as its been seen previously: to keep the individual behaviour of each variable and to keep the dependencies across variables. In this dissertation hypothesis test and correlation matrix similarity analysis are used to evaluate those two aims. 6.1 Hypothesis Test This section allows understanding how close are the synthetic distributions to the original ones. In statistics, the most common test for evaluating hypothesis is t‐test. T‐test is a parametric statistical test that contrasts the null hypothesis (H0) of two population’s mean being the same, against the alternative hypothesis (H1) of not being the same[2]. Original variable’s mean should be equal to synthetic variable’s mean, as null hypothesis, otherwise, would be the alternative: H0:µO=µN(2) H1:µO=µN(3) Even though t‐test’s simplicity, the following conditions must be fulfilled by the dataset: • Variables need to be independent • Variable’s distribution must be normal •Variances must be the same in each distribution (homoscedasticity) Unfortunately, the second condition is not achieved by the used data for this thesis. In order to contrast hypothesis, the U‐Test or Wilcoxon‐Mann‐Whitney Test needs to be performed. 6.1.1 U‐Test U‐Test or Wilcoxon‐Mann‐Whitney Test is a non parametric statistical test that contrasts if two samples are from equally distributed populations. If two compared samples are from the same population, when data is put together and sorted ascendant, it would be expected that data from one and other sample would be intercalated randomly. Otherwise, if one of the samples belongs to a population with greater or smaller values than the other population, once the data is sorted, these will tend to group together in a way that one sample’s data stays over the other. This is the idea 31
Generation and evaluation of synthetic Covid‐19 patients data which the U‐Test is based on. Accordingly to this idea, the test contrasts that the probability of an observation of population 1 is on top of an observation of population 2 is the same: H0:P(x > y) = P(y > x)(4) H0:P(x > y) = 0.5(5) H1:P(x > y)=P(y > x)(6) H1:P(x > y)= 0.5(7) In this case, H0and H1would be: •H0: The probability of an observation xfrom the original dataset of being right on top of an observation yfrom the synthetic dataset is the same. •H1: The probability of an observation xfrom the original dataset of being right on top of an observation yfrom the synthetic dataset is not the same. The median it’s a widely used parameter for this test, although this is only valid when position is the only distribution’s feature that’s not the same for both, original and synthetic. U‐Test is less powerful, statistically speaking, but it’s more robust than t‐test. There are some conditions to fulfill as well: 1. Variables need to be independent 2. Variable’s distribution does not have to be normal. However, if the test compares medians, distributions from different populations must be the same (original dataset versus synthetic dataset) 3. Data must be able to be sorted in ascending order. 4. Variances must be the same in each distribution (homoscedasticity, see Levene’s Test) section For calculating the U statistic of the u‐test the following formula’s been used (previously, the two populations observations must have been merged, sorted and ranked): U=min(U1, U2)(8) U1=n1·n2+n1(n1+ 1) 2−R1(9) U2=n1·n2+n2(n2+ 1) 2−R2(10) where, 32
DISSERTATION n1is the number of observations in population 1, n2is the number of observations in population 2, R1is the rank sum of population 1, R2is the rank sum of population 2, The Ustatistic is used to calculate the p‐value and then the hypothesis is accepted (p < 0.05) or rejected. This is done in Python (see code in Appendix) and the Ustatistic and p‐value are calculated. 6.1.2 Levene’s Test The current data fulfills all of the conditions mentioned above but it’s still unknown if the variances are the same for each variables’ distribution. Checking this is easy using the Levene’s test . It tests the null hypothesis that the variances of two populations are equal (homoscedasticity). If the resulting p‐value of Levene’s test is less than some significance level (typically 0.05), the obtained differences in sample variances are unlikely to have occurred based on random sampling from a population with equal variances. Thus, the null hypothesis of equal variances is rejected and it is concluded that there is a difference between the variances in the population[35]. The test statistic is called Wand it’s defined as: W=(N−k) (k−1) ·Pk i=1 Ni(Zi. −Z..)2 Pk i=1 PNi j=1(Zij −Zi.)2(11) and, Zij = |Yij −¯ Yi| |Yij −˜ Yi| (12) where, kis the number of different groups to which the sampled cases belong, Niis the number of cases in the ith group, Nis the total number of cases in all groups, Yij is the value of the measured variable for the jth case from the ith group, ¯ Yiis th mean of the i‐th group, ˜ Yiis a median of the i‐th group, 33
Generation and evaluation of synthetic Covid‐19 patients data Zi. is the mean of the Zij for group i, Z.. is the mean of all Zij. For Zij case, both definitions are correct, the corresponding to the median one is also the definition for another test that won’t be explored in this dissertation. Then the p‐value is calculated using Wstatistic. This is done in Python (see code in Appendix) and the W statistic and p‐value are calculated and those variables whose p‐value is less than 0.05 will not be taken into account for the U‐Test. 6.1.3 Results The results of the whole analysis for three different cases (50, 100, 150) and three algorithms turns out in 9 results table. The extended tables can be found in the Appendix, where it’s been organised in the Tables section, by algorithm. Table 3 is a summary of the extended versions, where the number of hypothesis accepted and rejected are counted. It shows the numbers for each case (50, 100, 150) and each algorithm. New Data Nº Hypothesis GC GAN DS 50 Accepted 14 9 20 50 Rejected 10 15 4 100 Accepted 17 3 23 100 Rejected 7 21 1 150 Accepted 13 4 22 150 Rejected 11 20 2 Table 3: Results table for hypothesis test 6.2 Similarity Analysis Hypothesis test let us know how similar were, for each variable, the original and the synthetic distribution. But this does not allow to see a bigger picture. It’s very important also to understand if the relationships between variables, any possible dependency, have been kept in the synthetic data. In order to tackle this issue, the following procedure’s been designed: 1. Generate the correlation matrix for the original dataset and the new one. 2. Subtract both matrix and it would be expected to have numbers as close as possible to zero. 3. Create a heatmap for making the results more visual. 34
DISSERTATION 4. Repeat for each number of new data created. 6.2.1 Correlation Matrix In order to understand if the dependencies have been kept by the algorithms, it’s necessary to keep in mind the idea of correlation. By definition, correlation measures how two or more variables are related to one and other [24]. Therefore, given a dataset of mcolumns and nrows, the correlation matrix, let it be R, will result as a m×msymmetric matrix with a unit diagonal. The Rij elements are the Pearson Coefficients ρbetween the element iand j, denoted as ρ(i, j). Pearson’s correlation coefficient estimates the correlation of two variables, dividing the covariance by the product of each standard deviation coefficient: ρ(mi, mj) = cov(mi, mj) σ(mi)σ(mj)(13) where, cov(mi, mj) = n X k=1 (mik−¯mi)(mjk−¯mj)(14) σ(mi) = v u u t n X k=1 (mik−¯mi)2(15) σ(mj) = v u u t n X k=1 (mjk−¯mj)2(16) therefore, ρ(mi, mj) = Pn k=1(mik−¯mi)(mjk−¯mj) pPn k=1(mik−¯mi)2pPn k=1(mjk−¯mj)2(17) The following step is to generate each matrices (RO,RS) and subtract them, RO= ρ00o. . . ρi0o. . . ρm0o . . ..... . .. . . ρ0jo. . . ρijo. . . ρmjo . . .. . ..... . . ρ0mo. . . ρimo. . . ρmmo (18) RS= ρ00s. . . ρi0s. . . ρm0s . . ..... . .. . . ρ0js. . . ρijs. . . ρmjs . . .. . ..... . . ρ0ms. . . ρims. . . ρmms (19) 35
Generation and evaluation of synthetic Covid‐19 patients data Therefore, let’s denote ∆Cas the difference between both correlation coefficient matrices, CO and CS, as: ∆R=RO−RS= ρ00o−ρ00s. . . ρi0o−ρi0s. . . ρm0o−ρm0s . . ..... . .. . . ρ0jo−ρ0js. . . ρijo−ρijs. . . ρmjo−ρmjs . . .. . ..... . . ρ0mo−ρ0ms. . . ρimo−ρims. . . ρmmo−ρmms (20) This has been, as well the plots, computed using Python, the code can be found in the Appendix. 6.2.2 RSME Root squared mean error is a widely used metric in data science field, since it’s an accuracy measure for prediction models. For that kind of models, it’s measured how close is a predicted value to the real one, so, the difference between both values is an error. RMSE serves to aggregate the magnitudes of the errors in predictions for various data points into a single measure of predictive power [36]. This applied to the similarity analysis, an analogy could be done: predicted observations would be synthetic data and real observations would be original data. RSME is computed using the following formulas: RMSE =sPm i,j(∆Rij) m(21) This is computed using Python (see the code in Appendix) 36
DISSERTATION 6.2.3 Results Let’s remember that the matrices are the difference between the original dataset correlation matrix and the synthetic one, then the heatmap is plotted. Firstly, there’s a comparison amongst the same algorithm and its different number of synthesized data. The colors are adjusted in a numerical scale between values from 0 to 1, the darkest color is the maximum value amongst of all matrices, hence, the clearer the matrix, the higher similarity in correlation. Figure 12: Heatmaps for GC algorithm. Figure 13: Heatmaps for GAN algorithm. 37
Generation and evaluation of synthetic Covid‐19 patients data Figure 14: Heatmaps for DS algorithm. In order to quantify the difference between all of them, it’s been calculated the RSME for each algorithm and case. The results have been summarized in Table 4. As it can be observed, the DS New SD GC GAN DS 50 0,140 0,221 0,134 100 0,112 0,189 0,113 150 0,096 0,179 0,073 Table 4: RSME Comparison for algorithm and number of synthetic data is performing the best for almost all different numbers of new synthesized data, while GAN is the worst‐performer. 38
DISSERTATION 7 Conclusions The main goal of this dissertation is studying how feasible is to generate synthetic data for scientific usage. It’s been explained how the lack of data limits researcher’s work a lot of times, why this absence has happened during the pandemic years and which consequences is bringing at present. Firstly, data’s been processed and got rid off some variables that would complicate unnecessarily the workflow and not provide any useful information. Then it’s been done a descriptive analysis of the dataset, a more medical one, where each variable is briefly explained, and a more statistical one, where position and dispersion metrics are put together in a table for each variable in the set. This, together with distribution plots, allows a general understanding of the data set and its size. There are so many approaches for developing a project like this, but the one taken has been choosing three different algorithms, setting three different cases of synthetic data generation, generating this data and evaluating it. The chosen algorithms have been: • Gaussian Copula • Generative Adversarial Network • DataSynthesizer Successfully it has been accomplished the first goal: generating synthetic data using different algorithms. The three of them have output three data sets, each of them, all with synthetic observations. The maximum number of synthesized data has been 150 observations, since it couldn’t surpass the original dataset size (156 observations). Going over that threshold would mean snatching any kind of reality sense, given that over a 50% of data would be fake. Nonetheless, this is not enough. It had to be proven that these algorithms are bringing back similar enough data. Checking this involved two more goals: having similar variables and having similar correlations. With regard to evaluate how similar is the synthetic variable compared to the original one it’s been designed a hypothesis test. A distribution is characterized by position and dispersion statistics, so it’s been needed to check how close where the synthetic distribution statistics to the original ones. For each variable Levene’s test has been performed, enabling variances’ comparison. The test was a previous step for the u‐test (Wilcoxon‐Mann‐Whitney test), if variances of both distributions were similar enough, then, median is tested. Every test’s been done for a 95% confidence interval. In order to measure which performed better, the number of accepted hypothesis for each model and 39
Generation and evaluation of synthetic Covid‐19 patients data case has been counted, being the results shown in Table 5: Synthetic Data GC GAN DS 50 58,33% 37,50% 83,33% 100 70,83% 12,50% 95,83% 150 54,17% 16,67% 91,67% Table 5: Percentage of accepted hypothesis for each model and number of synthesized data. As it can be observed the model with higher percentage of accepted hypothesis is DS (83.33%‐ 95.83%). GAN is the model with lowest acceptance ratio (16.67%‐37.50%). While DS could keep very correctly original distributions and pass almost all hypothesis test, GAN did not, meaning that synthetic distributions did not look as alike as the confidence interval demanded. The second aim of the evaluation, and third goal, was to check how the algorithm kept intervariables relationships. A correlation matrix for each dataset has been computed, then original and synthetic data went under subtraction, ending up with a difference of correlations matrix. These matrices have gone under two processes for their analysis. Firstly, heatmaps for each case and algorithm were plotted, ideally these should be all white since our ideal correlations coefficients differences matrix should be made out of zeroes. Setting the scale from zero to the maximum difference, allows comparison between them because the color scale is the same for each plot, it’s useful to understand visually the concept of the difference of correlation coefficients. Nonetheless it was needed a way to compare matrices in a quantifiable measure. That being the case, it’s been computed the RSME for all of the correlation coefficient difference matrices. Even though this is usually a method for regression problems, it’s been extrapolated to synthetic data generation, since it allows comparing which matrices were closer to zero. The result of the similarity analysis lead to conclude that, again, the best performer’s been, overall, DS algorithm and the worst performer is, again, GAN model. GC is slightly better for 100 synthesized data, but this may be attributed to random error, since the algorithm has been just run once. Now, results have been explained and summarized. It’s clear to see that performance order for the chosen algorithms is: 1. DataSynthesizer 2. GaussianCopula 3. Generative Adversarial Network 40
DISSERTATION References [1] Miguel Arquez Abdala. Métodos de resampling. [Accessed 03‐Jan‐2023]. Mar. 2020. URL: https: //rstudio-pubs-static.s3.amazonaws.com/591883_d3879f873d3a4594bffe25b7e1ab072. html. [2] Joaquin Amat. Test de Wilcoxon Mann Whitney como alternativa al t‐test. URL: https:// www.cienciadedatos.net/documentos/17_mann%E2%80%93whitney_u_ test. (accessed: 29.12.2022). [3] Joaquin Amat. Test U de Mann‐Whitney‐Wilcoxon (U‐test) con Python. URL: https://www. cienciadedatos.net/documentos/pystats10-t- testpython.html. (accessed: 29.12.2022). [4] Fodil Benali et al. “MTCopula: Synthetic Complex Data Generation Using Copula”. In: 23rd International Workshop on Design, Optimization, Languages and Analytical Processing of Big Data (DOLAP). Nicosia, Cyprus, 2021, pp. 51–60. URL: https://hal.archives-ouvertes. fr/hal-03188317. [5] J. Brownlee. How Much Training Data is Required for Machine Learning? [Accessed 10‐1‐2023]. URL: https : / / machinelearningmastery . com / much - training - data - required-machine-learning/. [6] CDC Museum COVID‐19 Timeline. URL: https://www.cdc.gov/museum/timeline/ covid19.html. (accessed: 12.11.2022). [7] N. V. Chawla et al. “SMOTE: Synthetic Minority Over‐sampling Technique”. In: (2011). DOI: 10. 48550/ARXIV.1106.1813. URL: https://arxiv.org/abs/1106.1813. [8] Weron, R. Cízek, P. Härdle, W. 17.1 Copulas. [Accessed 19‐12‐2022]. Mar. 2005. URL: http: //sfb649.wiwi.hu-berlin.de/fedc_homepage/xplore/tutorials/ sfehtmlnode86.html. [9] Collaborative. Copula (probability theory). URL: https://en.wikipedia.org/wiki/ Copula_(probability_theory). (accessed: 19.12.2022). [10] DataCebo. The Synthetic Data Vault Project. Version latest. Dec. 2022. DOI: 10.1109/DSAA. 2016.49. URL: https://sdv.dev/SDV/. 47
Generation and evaluation of synthetic Covid‐19 patients data [11] Google Developers. Background: What is a Generative Model? [Accessed 19‐12‐2022]. July 2022. URL: https://developers.google.com/machine-learning/gan/ generative?hl=en. [12] Trading Economics. Spain Electricity Price ‐ 2023 Data ‐ 1998‐2022 Historical ‐ 2024 Forecast. https://tradingeconomics.com/spain/electricity-price. [Accessed 03‐Jan‐2023]. 2023. [13] EnerGuide. How much power does a computer use? And how much CO2 does that represent? https : / / www . energuide . be / en / questions - answers / how - much - power-does-a-computer-use-and-how-much-co2-does-that-represent/ 54/. [Accessed 03‐Jan‐2023]. [14] Ericsson. A quick guide to your digital carbon footprint carbon footprint.https://www. ericsson.com/4ac671/assets/local/reports-papers/consumerlab/ reports/2020/ericsson-true-or-false-report-screen.pdf. [Accessed 03‐Jan‐2023]. 2020. [15] Sheri Fink. “Worst‐Case Estimates for U.S. Coronavirus Deaths”. In: The New York Times (Mar. 13, 2020). URL: https://www.nytimes.com/2020/03/13/us/coronavirusdeaths-estimate.html (visited on 11/12/2022). [16] S.E. Galaitsi et al. “The challenges of data usage for the United States’ COVID‐19 response”. In: International Journal of Information Management 59 (Aug. 2021), p. 102352. DOI: 10. 1016/j.ijinfomgt.2021.102352. URL: https://doi.org/10.1016/j. ijinfomgt.2021.102352. [17] TRACIE. Healthcare Emergency Preparedness Information Getaway, ed. SOFA Score: What it is and How to Use it in Triage. Dec. 21, 2020. URL: https://files.asprtracie.hhs. gov/documents/aspr-tracie-sofa-score-fact-sheet.pdf. [18] Sarah Griffiths. Why your internet habits are not as clean as you think.https://www. bbc.com/future/article/20200305- whyyour- internethabits- are-not-as-clean-as-you-think. [Accessed 08‐Jan‐2023]. 2020. [19] Michal Horný. Bayesian Networks. Tech. rep. Boston University School of Public Health, 2014. [20] Amanda Kobokovich. Ventilator Stockpiling and Availability in the US. Mar. 9, 2020. URL: https: //www.centerforhealthsecurity.org/resources/COVID-19/COVID- 19-fact-sheets/200214-VentilatorAvailability-factsheet.pdf. 48
DISSERTATION [21] Wes McKinney. “Data Structures for Statistical Computing in Python”. In: Proceedings of the 9th Python in Science Conference. Ed. by Stéfan van der Walt and Jarrod Millman. 2010, pp. 56– 61. DOI: 10.25080/Majora-92bf1922-00a. [22] David Meyer, Thomas Nagler, and Robin J. Hogan. “Copula‐based synthetic data generation for machine learning emulators in weather and climate: application to a simple radiation model”. In: CoRR abs/2012.09037 (2020). arXiv: 2012.09037. URL: https://arxiv.org/ abs/2012.09037. [23] Arslaan Hamza Mohammad Jabeen. “Analysis and data processing to identify Covid‐19 patients with spontaneous respiratory capacity and predict their mortality”. PhD thesis. Universitat Politècnica de Catalunya, 2022. [24] Muthukrishnan. Understanding Correlations and Correlation Matrix.https://muthu. co/understanding-correlations-and-correlation-matrix/. [Accessed 01‐Jan‐2023]. 2021. [25] Neha Patki, Roy Wedge, and Kalyan Veeramachaneni. “The Synthetic Data Vault”. In: 2016 IEEE International Conference on Data Science and Advanced Analytics (DSAA). 2016, pp. 399–410. DOI: 10.1109/DSAA.2016.49. [26] Haoyue Ping, Julia Stoyanovich, and Bill Howe. “DataSynthesizer”. In: Proceedings of the 29th International Conference on Scientific and Statistical Database Management. Chicago IL USA: ACM, June 2017. [27] Portaltic. Los españoles pagan de media un 27,4% más por Internet que el resto de europeos. https://www.europapress.es/portaltic/internet/noticia-espanoles- pagan-media-274-mas-internet-resto-europeos-20181020112938. html. [Accessed 08‐Jan‐2023]. 2018. [28] Junaid Rehman. Advantages and disadvantages of generative adversarial networks (GAN). [Accessed 19‐12‐2022]. URL: https://www.itrelease.com/2020/06/advantages- and-disadvantages-of-generative-adversarial-networks-gan/. [29] Robert D. Truog, M.D., Christine Mitchell, R.N., and George Q. Daley, M.D., Ph.D. “The Toughest Triage — Allocating Ventilators in a Pandemic.” In: The New England Journal of Medicine 382.21 (2020), pp. 1973–1975. DOI: https://doi.org/10.1056/NEJMp2005689. 49
Generation and evaluation of synthetic Covid‐19 patients data [30] Eco Cost Savings. How Many Watts Does A Laptop Use? [Actual Usage & Costs Revealed. https://ecocostsavings.com/how-many-watts-does-a-laptop-use/. [Accessed 03‐Jan‐2023]. 2021. [31] The pandas development team. pandas‐dev/pandas: Pandas. Version latest. Feb. 2020. DOI: 10.5281/zenodo.3509134. URL: https://doi.org/10.5281/zenodo. 3509134. [32] Unknown. GAN. URL: https://developers.google.com/machine-learning/ gan?hl=en. (accessed: 22.12.2022). [33] Basil Varkey. “Principles of Clinical Ethics and Their Application to Practice.” In: Karger 30.1 (2020), pp. 17–28. DOI: https://doi.org/10.1159/000509119. [34] Wikipedia. Bayesian network — Wikipedia, The Free Encyclopedia.http://en.wikipedia. org/w/index.php?title=Bayesian%20network&oldid=1094972270. [Online; accessed 01‐January‐2023]. 2023. [35] Wikipedia. Levene’s test — Wikipedia, The Free Encyclopedia.http://en.wikipedia. org/w/index.php?title=Levene's%20test&oldid=1120031847. [Online; accessed 01‐January‐2023]. 2023. [36] Wikipedia. Root‐mean‐square deviation — Wikipedia, The Free Encyclopedia.http://en. wikipedia.org/w/index.php?title=Root-mean-square%20deviation& oldid=1122929780. [Online; accessed 13‐January‐2023]. 2023. [37] Lei Xu et al. “Modeling Tabular data using Conditional GAN”. In: CoRR abs/1907.00503 (2019). arXiv: 1907.00503. URL: http://arxiv.org/abs/1907.00503. 50
DISSERTATION APPENDIX Code Scripts and code aren’t available due to confidentiality reasons. Plots Here can be found distribution plots for each algorithm and 100 and 150 synthesized observations cases. Gaussian Copula Plot distribution comparison for 100 synthetic data 51
Generation and evaluation of synthetic Covid‐19 patients data Plot distribution comparison for 150 synthetic data 52
DISSERTATION Generative Adversarial Network Plot distribution comparison for 100 synthetic data 53
Generation and evaluation of synthetic Covid‐19 patients data Plot distribution comparison for 150 synthetic data 54
DISSERTATION DataSynthesizer Plot distribution comparison for 100 synthetic data 55
Generation and evaluation of synthetic Covid‐19 patients data Plot distribution comparison for 150 synthetic data Tables Hypothesis Test Gaussian Copula Variable W pval equal_var U‐val p‐val RBC CLES result Age 2,55 0,11 TRUE 3.677,00 0,46 0,07 0,47 Accept Gender 1,20 0,27 TRUE 3.628,00 0,27 0,08 0,46 Accept Heart_rate 0,60 0,44 TRUE 4.336,00 0,30 ‐0,10 0,55 Accept SBP 2,08 0,15 TRUE 4.134,50 0,62 ‐0,05 0,52 Accept DBP 0,65 0,42 TRUE 4.899,00 0,01 ‐0,24 0,62 Reject SpO2 0,87 0,35 TRUE 4.796,00 0,02 ‐0,21 0,61 Reject Max_SpO2 0,22 0,64 TRUE 4.605,50 0,08 ‐0,17 0,58 Accept Temperature 0,26 0,61 TRUE 3.962,00 0,98 0,00 0,50 Accept BMI 0,81 0,37 TRUE 3.498,00 0,22 0,11 0,44 Accept pH 5,01 0,03 FALSE 4.156,00 0,58 ‐0,05 0,53 Reject PaCO2 0,97 0,33 TRUE 4.489,50 0,15 ‐0,14 0,57 Accept GCS 2,10 0,15 TRUE 6.361,50 0,00 ‐0,61 0,81 Reject APACHE_II 0,74 0,39 TRUE 3.926,50 0,95 0,01 0,50 Accept SOFA 0,08 0,78 TRUE 3.624,50 0,38 0,08 0,46 Accept PaO2_FiO2 1,54 0,22 TRUE 3.862,00 0,81 0,02 0,49 Accept 56
DISSERTATION CRP 0,10 0,24 0,11 D_dimer 0,14 0,13 0,11 ROX_index 0,08 0,15 0,08 Symptom_to_ICU 0,13 0,18 0,13 Hosp_to_ICU 0,14 0,14 0,12 Survival 0,13 0,18 0,11 Intubation 0,16 0,20 0,10 Total 0,11 0,16 0,11 Correlation matrix evaluation for 50 new synthesized data Variables GC GAN DS Age 0,11 0,15 0,08 Gender 0,10 0,09 0,09 Heart_rate 0,08 0,14 0,08 SBP 0,08 0,11 0,09 DBP 0,09 0,11 0,11 SpO2 0,08 0,14 0,08 Max_SpO2 0,12 0,08 0,10 Temperature 0,09 0,11 0,07 BMI 0,09 0,13 0,05 pH 0,08 0,18 0,10 PaCO2 0,06 0,16 0,09 GCS 0,09 0,13 0,06 APACHE_II 0,09 0,19 0,06 SOFA 0,08 0,22 0,08 PaO2_FiO2 0,11 0,15 0,10 Creatinine 0,09 0,13 0,10 Leucocytes 0,11 0,15 0,12 CRP 0,08 0,19 0,12 D_dimer 0,05 0,10 0,09 ROX_index 0,09 0,14 0,08 Symptom_to_ICU 0,09 0,12 0,09 Hosp_to_ICU 0,12 0,11 0,06 Survival 0,08 0,15 0,09 Intubation 0,09 0,13 0,08 Total 0,09 0,14 0,09 Correlation matrix evaluation for 100 new synthesized data Variables GC GAN DS Age 0,07 0,14 0,05 Gender 0,05 0,10 0,05 63
Generation and evaluation of synthetic Covid‐19 patients data Heart_rate 0,06 0,13 0,05 SBP 0,07 0,11 0,05 DBP 0,07 0,13 0,04 SpO2 0,07 0,15 0,07 Max_SpO2 0,07 0,11 0,07 Temperature 0,06 0,09 0,05 BMI 0,05 0,08 0,06 pH 0,08 0,19 0,05 PaCO2 0,07 0,16 0,05 GCS 0,07 0,12 0,03 APACHE_II 0,07 0,19 0,04 SOFA 0,06 0,20 0,05 PaO2_FiO2 0,07 0,17 0,06 Creatinine 0,08 0,14 0,07 Leucocytes 0,07 0,12 0,06 CRP 0,07 0,16 0,05 D_dimer 0,08 0,10 0,04 ROX_index 0,07 0,15 0,05 Symptom_to_ICU 0,06 0,13 0,07 Hosp_to_ICU 0,08 0,11 0,09 Survival 0,09 0,13 0,04 Intubation 0,05 0,20 0,05 Total 0,07 0,14 0,05 Correlation matrix evaluation for 150 new synthesized data 64