{'fraction_non_alphanumeric': 0.028857142857142856, 'fraction_numerical': 0.009591836734693878, 'mean_word_length': 5.108327100473697, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
An Empirical Framework for Domain Generalization in Clinical Settings

Clinical machine learning models experience significantly degraded performance in datasets not seen during training, e.g., new hospitals or populations. Recent developments in domain generalization offer a promising solution to this problem by creating models that learn invariances across environments. In this work, we benchmark the performance of eight domain generalization methods on multi-site clinical time series and medical imaging data. We introduce a framework to induce synthetic but realistic domain shifts and sampling bias to stress-test these methods over existing non-healthcare benchmarks. We find that current domain generalization methods do not consistently achieve significant gains in out-of-distribution performance over empirical risk minimization on real-world medical imaging data, in line with prior work on general imaging datasets. However, a subset of realistic induced-shift scenarios in clinical time series data do exhibit limited performance gains. We characterize these scenarios in detail, and recommend best practices for domain generalization in the clinical setting.


INTRODUCTION
As machine learning models become more prevalent in clinical settings, it is important to consider how well models can generalize to environments external to their training environment [16,17,42,75]. Current large-scale clinical machine learning models often utilize data from a single site in urban population centers, such as the Beth Israel Deaconess Medical Center in Boston for the MIMIC-III dataset [39]. If models trained on these datasets are deployed in other regions or countries, it is important that their performance degradation is minimal.
Prior work has found significant decreases in model performance under the presence of cross-institutional domain shift, in the chest X-ray [21,63,84], MRI [5,50], and pathology [73,74,77] settings. Temporal domain shifts have also been found to reduce performance in clinical machine learning models [53]. Recent developments in domain generalization present a way to combat this problem by learning models that are invariant across environments while ignoring environment-specific spurious correlations [6].
In this work, we focus on the domain generalization learning setup, where a model is learnt on data from multiple training environments, e.g., hospitals, labs, or regions, and evaluated directly on an unseen test environment without further fine-tuning [32]. In our setting, no data from the test environment is accessible to the model during training.
There are several methods that have been developed for domain generalization. The naive baseline is to use empirical risk minimization (ERM) to learn a single model on pooled data across all training environments. Another approach is invariant causal prediction, which assumes the existence of a shared causal graph across all environments, and seeks to discover a subset of invariant features using conditional independence tests [34,59]. Recent extensions of this work relax many of its assumptions and are computationally feasible for large datasets [2,6]. Other methods attempt to learn a representation that has the same distribution across the training environments [25,30,49,52], e.g., with an adversary, or attempt meta-learning from the assumed meta-distribution where all environments are drawn [27,48]. The computer vision literature has also created methods that rely on data augmentation techniques and auxiliary tasks which are specific to the image domain [11,15].
In this work, we focus on domain generalization methods which are data modality agnostic, i.e., can be applied to tabular, time series, or image data alike. Domain generalization methods in the literature have been largely benchmarked on datasets where spurious correlations are introduced in a contrived manner, such as Colored MNIST [6] or Colored Fashion MNIST [2]. More realistic recent evaluations have demonstrated that no domain generalization algorithm significantly outperforms ERM on standard image classification datasets [32]. Similarly, Koh et al. [44] found that two domain generalization methods often actually perform significantly worse than ERM on seven real-world datasets spanning text, image, and graph modalities.
We evaluate the performance of eight algorithms on domain generalization in clinical time series data from intensive care units (ICUs) across four regions [62] and chest x-ray imaging data from four sites [14,37,38,80]. The clinical setting presents a realistic domain for benchmarking methods that might be trained in one site, but deployed in another. We also manually introduce realistic sampling bias in the data to test the limits of these methods in sites with further shift. We present these clinical confounding and sampling bias scenarios as a general empirical framework to stress-test generalization methods. Our main contributions are the following: • We show that state of the art domain generalizations do not consistently perform significantly better than ERM on realworld clinical imaging data. This is consistent with results from prior work on general benchmarking datasets [32,44]. • We introduce a framework which generates plausible augmented versions of clinical datasets with domain shift. While there are realistic clinical scenarios where domain generalization perform marginally better than ERM, these improvements only manifest when the strength of the spurious correlation is strong. • We find, in the case of subsampled datasets with varying label prevalence between genders, that domain generalization methods are not able to learn fairer models than ERM while maintaining overall model performance. • We publicly release the code and framework to reproduce our data and results 1 , based on a modified version of the DomainBed [32] platform. We hope this framework will be used as a realistic clinical generalization scenario against which domain generalization methods can be benchmarked.

RELATED WORKS 2.1 Domain Generalization Methods
In the domain generalization learning setup, we are given labelled data from multiple training environments, and seek to learn a model whose performance generalizes to unseen test environments. Approaches based on causality stemmed from the Invariant Causal Prediction (ICP) method proposed by Peters et al. [59], which assumes the existence of a causal graph and uses conditional independence tests to find a set of invariant features. Followup work include extensions to non-linear models [34] and the use of anchor variables [68]. However, finding this invariant feature set involves a combinatorial search over the feature space, and these conditional independence tests often make many distributional assumptions.
Domain generalization from robust optimization [10] seeks to minimize the worst-case error in the training environments. Krueger et al. [46] introduced the principle of risk extrapolation, which is a generalized form of robust optimization. Xie et al. [82] derived a slightly altered risk extrapolation loss function and linked distributional robustness with causality. Methods like GroupDRO [69], conventionally used in the subpopulation shift setting, has also been tested for domain generalization [32].
Another approach to domain generalization aims to remove all environment information from a latent representation, or, alternatively, learn an encoder such that all environments have the same latent distribution. This can be accomplished with an adversarial network [25,30], the Maximum Mean Discrepency (MMD) loss [49], or by directly minimizing mutual information [52]. Methods based on low-rank decomposition have also been proposed. These methods seek to learn a component that is common among all environments, and a component that is specific to each training domain. The common component is then used for out-of-distribution (OOD) generalization [47,61].
Several methods have been proposed specific to the image domain. Zhang et al. [85] proposed a data augmentation based approach where a series of stacked transformations are applied. Carlucci et al. [15] proposed an auxiliary task for neural network training where the network learns to solve a jigsaw puzzle consisting of shuffled patches of an image. Benton et al. [11] introduced a method where the model automatically learns invariant affine augmentations from the training data. Hendrycks et al. [35] proposed an image augmentation method involving applying randomly sampled operations to the weights and activations of an image autoencoder, though it could potentially be applicable to other modalities as well. In this work, we focus only on methods that are modality agnostic.
The invariant risk minimization (IRM) method proposed by Arjovsky et al. [6] frames domain generalization as a bi-level optimization problem. In addition to alleviating the distributional assumptions of ICP, their optimization problem can be simplified to a loss function compatible with gradient descent that can easily be applied to large datasets. Ahuja et al. [2] proposed an alternate method for solving the same bilevel optimization problem by finding the Nash equilibrium of an ensemble game.

Model Transferrability in Medical Settings
Access to large annotated datasets to train deep neural networks across multiple sites is not always feasible in clinical settings. Transfer learning [57] addresses this by using a model pretrained on a large-scale dataset and fine-tuning it to the downstream task. This method has been commonly used in designing medical image classifiers [4,37,66,70,80]. In these settings, the deep neural network is initialized with a pretrained model (for example, trained on Ima-geNet [24]) and then are finetuned on downstream medical images. Transfer learning has been shown to be effective at increasing model performance in chest X-ray classifiers [66,70], though there are cases where a model trained from scratch can perform just as well [64].
In the transfer learning framework, we are given labelled data for the target domain. A related framework is unsupervised domain adaptation, where we are only given unlabelled data for the target domain. Unsupervised domain adaptation has also been applied to medical imaging [26,58,86]. Our benchmark focuses on the domain generalization setting, where only labeled data from multiple training environments are available, and the goal is to be able to generalize to all unseen test domains.
There have been a limited number of papers which apply domain generalization methods to health data. In their WILDS benchmark, Koh et al. [44] tested two domain generalization methods on the Camelyon17 dataset for tumor identification [7], finding that they both performed worse than ERM by more than 10% accuracy. Ghimire et al. [31] benchmarked the performance of the IRM Games method [2] on pneumonia detection in four chest X-ray environments, finding that it gave marginal improvements to OOD performance. Bellot and van der Schaar [9] also test their proposed method on pneumonia detection using chest X-ray datasets from two hospitals. However, as there is a significant overlap between the training and test domains in their experimental setup, it would be better suited as a subpopulation shift problem [44] rather than a domain generalization one.

Domain Generalization and Fairness
Fairness criteria have grown in popularity in recent years due to the increasing use of machine learning models in settings such as healthcare [8,18,60,65,78,81], where poor performance of models on certain subgroups can lead to significant harm. Common group fairness metrics, such as statistic parity, equalized odds, and equality of opportunity consider fairness through various independence definitions, typically between the random variables of the true label, predicted label and protected attribute (attribute determining subgroups) [33]. Many group fairness objectives focus on minimizing the worst-case performance or the gap in performance according to certain metrics (such as parity, recall, etc.) across subgroups [41].
Domain generalization methods, as described in Section 2.1, similarly aim to minimize the worst-case risk across all possible environments. State-of-the-art algorithms, such as GroupDRO, have arguably been motivated by improvement to both group fairness and generalization performance [25,69]. There has been some recent literature investigating the relationship between domain generalization and fairness [1,23,25], and some analysis of group and individual fairness constraints on generalization ability [22,71].
Within the IRM objective, Creager et al. [23] improves worst-case performance without access to protected group labels in order to develop a generalization method for settings in which the domain labels are not provided. This paper also demonstrated that the IRM objective can be framed to directly optimize group sufficiency if the protected attribute label is taken as the environment variable. Adragna et al. [1] provided empirical results for the gains IRM offers over ERM in terms of fairness guarantees through comparing the ability of both objectives to be invariant to spurious correlations between comment toxicity and particular demographic groups in internet comment datasets.
In this work, we add to existing empirical results linking domain generalization and fairness to investigate this relationship in a clinical context.

Domain Generalization Benchmarks
The large majority of state-of-the-art domain generalization methods are tested on variants of MNIST (such as Colored MNIST) where a spurious correlation (such as a correlation between the channel and the label) are introduced synthetically [6,45,56]. Choe et al. [19] proposed Extended Colored MNIST -a version of Colored MNIST with varying data generation parameters. They benchmark the performance of IRM and ERM on this dataset, along with a sentiment analysis dataset where punctuation is manually confound with the label.
Two large-scale domain generalization benchmarks have been proposed. Gulrajani and Lopez-Paz [32] proposed the DomainBed platform, which tests 15 methods on seven image benchmark datasets classically used for domain adaptation. One example is the PACS dataset [47], where the environments consist of photo, artistic, cartoon, or sketch renditions of objects. Though these datasets are much more realistic than Colored MNIST, they still have limited real-world utility. Gulrajani and Lopez-Paz [32] found that domain generalization methods do not significantly out-perform ERM consistently. Koh et al. [44] proposed the WILDS benchmark, which consists of seven real-world datasets spanning a variety of domains, including satellite imagery, cancer pathology, molecular graphs, and sentiment analysis. They tested two domain generalization methods -IRM [6] and DeepCORAL [76] -and found that neither of the methods improve over ERM performance on any of the datasets.
In this work, we benchmark the performance of eight domain generalization methods on two real-world clinical datasets. In addition to the base datasets, we propose a framework for augmenting clinical datasets via synthetic domain shifts and sampling bias. We hope that this framework will bridge the gap between the stateof-the-art performance that domain generalization methods have shown on the contrived Colored MNIST dataset, and their poor performance on real-world datasets as demonstrated by the two other benchmarks.

METHODS
In the domain generalization setup, we are given labelled data {( , )} =1 , from multiple training environments ∈ E , as well as a risk function ( ) = E , [ℓ ( ( ), )]. The goal is to learn a predictor : → that minimizes the worst-case risk across all possible environments ( ) = max ∈E ( ). In practice, we typically evaluate the performance of a domain generalization method by evaluating the risk of its learnt predictor on some unseen test environment ( ).

Domain Generalization Algorithms
We test the performance of the following eight algorithms: • Empirical Risk Minimization (ERM, [79]) minimizes loss over pooled data across all training environments. • Group Distributionally Robust Optimization (GroupDRO, [69]) minimizes the loss of the worst-case training environment. • Invariant Risk Minimization (IRM, [6]) learns a predictor that is invariant across training environments by optimizing the data representation such that all domains have the same downstream classifier. • Variance Risk Extrapolation (VREx, [46]) minimizes the training risks along with the variance of the training risks across environments. • Risk Variance Penalization (RVP, [82]) minimizes the training risks along with the standard deviation of the training risks across environments. • Maximal Invariant Predictor by Inner-environmental Gradient Alignment (IGA, [45]) learns the optimal classifier such that the label is independent of the environment index given the data representation. • Deep Correlation Alignment for Deep Domain Adaptation (CORAL, [76]) aligns the mean and covariance of latent distributions across domains. • Meta-Learning for Domain Generalization (MLDG, [48]) adapts the model-agnostic meta-learning method [29] to the domain generalization setting.
We also report the performance of two "oracles", corresponding to models that do have access to the test environment during training: • OracleID: train an ERM classifier only on the training split of the test environment. Note that this is not invariant model, as it would learn spurious correlations that exist on the test domain. • OracleMerged: train an ERM classifier on the pooled training splits across all environments.
The difference in performance between the oracles and the ERM model is a proxy measure of how distinct the test environment is from the training environments. The performance of the oracle models is also an informal upper bound for the performance that any of the eight algorithms can hope to achieve.

Model Selection Strategies
Model selection is a crucial part of a domain generalization experiment [32]. It is not realistic to assume that the test environment is available for model selection, i.e., during hyperparameter tuning or early stopping, as is done in Colored MNIST; Gulrajani and Lopez-Paz [32] observed that most of the performance gains on Colored MNIST by domain generalization methods vanish when the test environment is not used for model selection.
We consider two potential model selection methods for all experiments to critically evaluate the impact of the model selection policy on generalization performance: • Selection by Training Domain: We split the data for each training environment into training, validation, and test sets. We use the validation sets pooled across all training environments for model selection. This model selection method does not require any data external to the training environments, but it is unclear that the training domain validation sets would be a good measure of OOD performance. • Selection by Validation Domain: We designate a specific environment as the validation environment. The data from the validation environment is used only for model selection.
In later manual augmentation experiments, we assign the validation environment to have an intermediate level of spurious correlation, between the training environments and the test environment. This simulates the case where limited information is available from an environment closer to the deployment target.

SYNTHETIC DOMAIN SHIFT FRAMEWORK
We experiment with five types of synthetic domain shifts, shown in Figure 1. the unmodified dataset (Base), a noise corrupted label (CorrLabel), a feature-correlated corrupted label (CorrNoise), and biased subsampling (BiasSampUnobs and BiasSampObs).

Unmodified Dataset (Base)
This corresponds to the Base graph shown in Figure 1. For simplicity, we merge all features into a single node X. However, complex causal relationships exist between the features and the label -some of the features may be invariant, and some of which may be spuriously correlated with the label.

Corrupted Label as Feature (CorrLabel)
We create a new binary feature ′ by flipping the target with a certain environment specific probability . We append this feature to the dataset and treat it as a static feature during modelling. The causal graph for this augmentation is shown in Figure 1. We fix the flip probability for the validation and test environment to = 0.5 and = 0.9. For the training environments, we use where is the mean probability between the three environments, and is the distance between each environment. As IRM requires that the training environments are diverse enough to learn invariances [6], some distance between the training environments is required. We fix = 0.1, and vary Here, the goal of domain generalization is to learn a model that completely ignores ′ , as its correlation with the label ( | ′ ) is varying in the training environments, and is flipped for the test environment. In the medical setting, this would represent a scenario where a strong spurious correlation exists in one environment, and is not generalizable to external environments. For this augmentation, we also include the performance of the Unaugmented ERM model (ERM Unaug) for reference, which is the performance of the ERM model from Section 4.1. This is the performance of a model that ignores the spurious correlation completely.

Correlated Noise (CorrNoise)
We modify an existing continuous feature˜to create ′ by adding Gaussian noise that is correlated with both the label and the environment. A practical scenario reflecting this setting is one where sicker patients exhibit more extreme values of a feature in some environments. We sample ∼ N ( , 2 ), where is an environment specific hyperparameter, and ∈ {−1, +1} is the label. We define ′ =˜+ , and use ′ in place of˜as a feature in our model. This corresponds to the CorrNoise causal graph in Figure 1.
Similar to CorrLabel, the goal is to learn a model with low reliance on ′ . However, in this case, we modify an existing informative feature instead of creating a new feature.

Subsampling Based on Unobserved Feature (BiasSampUnobs)
We create an augmented version of the dataset by subsampling based on a binary feature ′ to create confounding. We also remove this feature from modelling to reflect realistic scenarios of induced sampling bias due to unknown factors. We configure the desired data parameters 1 = ( = 1| ′ = 1) and 0 = ( = 1| ′ = 0). We then randomly subsample each environment for each value of ′ separately to achieve the desired label distribution. The algorithm for subsampling is shown in Algorithm 1. The causal graph for this augmentation is shown in Figure 1. A practical scenario reflecting this setting is one where the degree of sampling bias differs across environments.

Algorithm 1: Compute subsampling probability
Data: ( ′ , ): gender and label of sample Data: : desired prevalence of ′ in environment Data: : current prevalence of ′ in environment Result: probability that the sample will be dropped 1 if == 1 and > then Here, the distribution ( | ′ ) is not invariant across environments. If the difference between 1 and 0 is large, ′ becomes highly informative, and an ERM model would tend towards a predictor that outputs the most likely class for each value of ′ , i.e. a classifier that outputsˆ= argmax ( = | ′ = (X)), where is a model that predicts ′ given features X. Because the distribution ( | ′ ) is vastly different from ( | ′ ), this confounding-reliant predictor would then have poor OOD performance. If ′ is set to be a protected attribute (for example, gender), depending on the settings of 1 and 0 , this classifier could also have large performance disparities between groups. Here, the protected group would be an example of a hidden stratification [55].
Several prior connections as elicited in the related work have been made between domain generalization and potential improved statistical parity between protected attributes. Therefore, in addition to overall model performance, we also evaluate the following metrics related to algorithmic fairness. As these metrics require a binarized prediction, we choose the threshold that results in the maximum F1 score for each model.
• Gap in the True Positive Rate (TPR) between the two protected groups. This corresponds to equality of opportunity for the positive class [33]. • Gap in the True Negative Rate (TNR) between the two protected groups. This corresponds to equality of opportunity for the negative class [33]. • The correlation, evaluated using the Matthews correlation coefficient [83], between the predicted label and the binary confounder. This roughly measures how close the learnt classifier is to a protected attribute predictor, and, in turn, how robust it is to the distribution shift.

Subsampling Based on Observed Feature (BiasSampObs)
We have the identical setup as in Section 4.4. However, we now include the confounded feature in our model. This allows us to investigate the model behaviour when it has direct access to the domain-shifted feature.

DATA AND MODELS
We consider clinical data from two distinct data domains -timeseries data and images. We also include results for the Colored MNIST dataset in Appendix B.

In-Hospital Mortality (eICU)
Dataset. The eICU collaborative research database V2.0 [62] consists of intensive care unit (ICU) records for over 200, 000 admissions to over 200 hospitals across the United States. We use the cohort creation procedure for the in-hospital mortality prediction task outlined by Sheikhalishahi et al. [72]. The goal is to predict whether a patient will die in hospital, given data from the first 48 hours of their hospital stay. Patients who die within the first 48 hours are removed from the cohort, as are patients who are younger than 18 or older than 89 years of age. Patients who have more than one ICU stay only have their first stay selected. Time-series observations (labs and vitals) are grouped into 1-hour windows, with missing values imputed from the previous observation.
For each patient, we have 10 continuous and 4 categorical time series features, and 3 continuous and 2 categorical static features. A complete list of these features can be found in Table A2. The resulting dataset consists of 30,680 patients, 11.48% of which have a positive label. Each patient is associated with a hospital, which is located in one of four regions in the United States. A small number of hospitals do not have an associated region in the database. A summary of the statistics for each region is shown in Table 1.
Domains. We use Midwest, South, and West as training environments, and we use Missing as the validation environment. We choose South as the test environment, as its demographics appear to be the most distinct of the five, as seen in Table A1.
Models. We use a gated recurrent neural network [20], with a linear classifier over the final hidden state. Categorical variables are embedded before being input to the network, and continuous features are scaled to zero mean and unit variance. Static features are appended to time-series features at each timestep.
Hyperparameter Search. We use ten iterations of random search [12] to tune the learning rate and hyperparameters specific to each algorithm, randomizing the data splits and model initialization each time. Following the practice established by Gulrajani and Lopez-Paz [32], we select the best model of the ten with the associated model selection strategy (using AUROC as the metric), and then repeat this entire procedure five times, reporting the mean and standard deviation of metrics for the best models across the trials. This allows us to account for the variance in the hyperparameter search procedure.
Experiments. We benchmark this dataset using all of the experimental settings defined in Section 4. For CorrNoise, we choosẽ to be the admission weight (a static continuous feature). For BiasSampUnobs and BiasSampObs, we use gender as the confounding variable. We set and to the values shown in Table 2.

Chest X-rays (CXR)
Dataset. We use four public chest X-ray (CXR) datasets: MIMIC-CXR [38], CheXpert [37], Chest-Xray8 [80], and PadChest [14]. Statistics for each dataset can be found in Table 1, and detailed statistics can be found in Table A3. Each sample consists of a chest X-ray image along with zero or more diagnostic labels.
We preprocess the data to obtain eight common labels shared between all datasets. Though some datasets contain both frontal and lateral CXR images, we use only frontal images (both PA and AP views) for our experiments to prevent presence of additional confounding in our analysis.
Domains. We designate each dataset as its own environment. We use the PadChest dataset as the test environment because it is the only dataset from a hospital located outside of the United States, and because prior work has shown it to be the domain with the worst performance as the transfer target [63].

Models.
We use a DenseNet-121 [36] network, initializing with pre-trained weights from ImageNet [24], which has been shown to perform well on CXR classification [13,64]. We replace the final layer with a linear layer of the appropriate size. For training the network, all images are scaled to 224 × 224 and normalized to the ImageNet mean and standard deviation. We apply multiple image augmentations to the training set: flipping of the images along the horizontal axis, rotation of up to 10 degrees, and a crop of a random size (75% − 100%) and a random aspect ratio (3/4 to 4/3).
Hyperparameter Search. We use the same hyperparameter search strategy as described in Section 5.1.
Experiments. We define two predictive setups. In the multitask setup, we learn a network that jointly predicts the eight labels  simultaneously, trained to minimize the mean of the binary crossentropy over all tasks. For model selection, we use the average AUROC across all eight labels as the metric. In the binary setup, we select only the pneumonia label, and learn a binary classifier to predict whether an image contains a lung infected with pneumonia.
For model selection, we use AUROC as the metric. We benchmark this dataset for the Base setting using both the multitask and binary setups, and for the BiasSampUnobs and BiasSampObs settings using the binary setup. We omit CorrLabel and CorrNoise here, as these shifts are not clinically meaningful for x-ray images. For the biased subsampling shifts, we use gender as the confounding variable. We set and to the values shown in Table 2.

Performance on Base Datasets
ERM Peforms Well Across Targets and Shifts. Table 3 shows the performance of each of the domain generalization methods on the test environment. First, comparing the performance of the OracleID and ERM methods, we note that for the CXR setups, there is indeed a statistically significant drop in performance when a model is trained on PadChest, versus when a model is transferred to PadChest.
Surprisingly, the performance of ERM on the eICU test set is actually on-par with the oracles, indicating that the South environment is likely not OOD. Therefore, it is not fair to make conclusions about the performance of domain generalization methods based on their performance on Base eICU.
In the CXR setting, none of the domain generalization methods consistently outperform ERM, though CORAL performs quite well in the binary task, and many of the methods perform significantly worse than ERM. This result is consistent with prior work [32,44].
Enforcing Invariance Can Harm Performance. We examine the methods that have a tunable parameter that balances the standard ERM loss with some invariance enforcing loss. This evaluation helps to investigate whether domain generalization methods fallback to ERM (i.e. small ), and is lacking in prior benchmarks. As shown in Figure 2, We vary , and find that, in the case where the test environment is not OOD, enforcing invariances in the model can actually significantly hurt test domain performance.

Performance Under Synthetic Domain Shift
We examine the results of CorrLabel and CorrNoise (Table 4), and BiasSampUnobs and BiasSampObs (Table 5).

Domain Generalization Shows Limited Effectiveness Under Extreme Spurious Correlations.
There are indeed scenarios where domain generalization methods outperform ERM, but improvements are limited, and only become significant when the strength of the spurious correlation is extreme. In such cases, ERM is completely reliant on the spurious correlation, and performs worse than chance on the test environment where the spurious correlation is flipped. This provides the opportunity for a performance gain for the domain generalization methods. However, even in such cases, the performance of domain generalization methods is still quite poor relative to the unaugmented case -which represents the performance of an ideal ERM model that ignores the spurious correlation. We note that although the OracleID model has exceptionally high performance in the experiments, it is completely reliant on the spurious correlation in the test environment, and would thus transfer very poorly.
Validation Environment Model Selection is More Robust. Next, we observe that, in almost all cases, model selection on the validation environment yields better performance than using the training domains. Since we specifically designed the validation environment to have an intermediate level of spuriousness between the training and test domains, this result is to be expected.
Increased Training Diversity Improves Generalization. Finally, for the correlated noise experiment in Table 4, we observe that increasing the diversity between the environments by increasing significantly increases performance for the large majority of models. When the gap between the environments increase, it is easier for the models to detect the spurious correlation, as relying on the spurious correlation would lead to comparably worse training loss, resulting in better generalization.    Figure 2: For the Base eICU mortality prediction dataset, we select methods that balance the ERM loss with some invariance loss term using some hyperparameter . We vary from a small value (where the loss function is equivalent to ERM) to a large value (where the training environment invariances are strongly enforced). We find that defaulting to ERM yields the best test environment performance.

Domain Generalization and Fairness Under Sampling Bias
Domain Generalization Does Not Produce Fairer Classifiers with Better Performance. First, we observe from Table 5, similar to our results on the base datasets in Table 3, that domain generalization methods do not show significant improvements in overall performance over ERM. Next, looking at the TPR gaps in Figure 3 and Table A4, we find that few models have significantly lower disparity than ERM, and the models that do have much lower overall utility. There do not appear to be models that improve on both overall performance and fairness over ERM. This is also observed in the TNR gaps (Table A5). Given that a model which ignores the spurious gender correlation should be both fairer and have better performance than ERM, we conclude that domain generalization methods are not capable of overcoming spurious correlations induced through subsampling.
Observing Confounding Can Reduce Fairness. Interestingly, we see that both domain generalization algorithms and ERM produce classifiers with significantly worse fairness, along with worse overall performance, when given the value of the subsampled feature. We observe in Table A6 that the correlation coefficient between gender and the model prediction is also significantly higher when   Table A4.
the protected group is given to the model. It appears that the model becomes more reliant on the spurious correlation when its value is directly provided, resulting in poor performance and fairness under distribution shift.

DISCUSSION 7.1 Disparity Between Real World and Manually Confounded Data
We offer several hypothesis for why domain generalization seems to perform well in limited settings compared with ERM on the manually augmented data, but performs much worse on real-world medical imaging data, as well as various real-world benchmarks from prior work [44]. First, the spurious correlations that we introduce are fairly simple and extreme in magnitude -there is often one single variable which the model should avoid in order to achieve a decent result. In the real world, the spurious correlations that exist are much more subtle and complex, and it is not as simple to isolate it in the causal graph as in our scenarios. Secondly, prior work has demonstrated certain synthetic settings where IRM provably recovers a suboptimal predictor [40]. The sample complexity of IRM [3] versus ERM could also be relevant. However, in the real world where the underlying data generating distribution is unknown, the degree to which these factors contribute to our observations is unclear.
Finally, prior theoretical work into the diversity requirement for the environments in IRM has shown that IRM will fail unless the training environments "cover" the space of all possible environments [67]. In our synthetic augmentation scenarios, we can easily tune the data hyperparameters to increase the space covered by the environments. However, in the real world, where the number of spurious and invariant features are unknown, it is unclear what diversity requirement is needed, or how many environments would be required. Nonetheless such transparent evaluation with added confounding is critical to expose these limitations.

Domain Generalization and Fairness Under Sampling Bias
There are some findings of note in our analysis of fairness in experiments with subsampling. We observe that including the protected group as a feature in the classifier leads to worse performance, more unfair predictions, and greater correlation between model prediction and the gender attribute for both ERM and domain generalization methods. This is consistent with prior findings which show that the inclusion of spurious correlations can have significant effects on accuracy and group fairness [43].
Our results demonstrate that domain generalization methods do not provide improved performance along with improved fairness guarantees over ERM in sampling bias experiments, both in cases with awareness of the sensitive attribute and without knowledge of the protected feature. We do note there exist models which trade-off model performance for increased fairness. This trade-off has also been observed in the supervised learning setting [51]. However, as a random binary classifier is perfectly fair, the real-world utility of these models should be determined on a case-by-case basis.
Our results appear inconsistent with prior work in that Creager et al. [23] prove a direct relationship between group sufficiency and IRM objective. However, Creager et al. [23] demonstrate this theoretical result in the setting where the sensitive attribute is taken to be the environment label. Adragna et al. [1] show empirically that IRM can overcome the fairness impairment faced by ERM when a spurious correlation is introduced between the label and certain demographic groups through label flipping. Both differ from our experimental setup which studies the fairness of domain generalization and ERM in the context of sampling bias -where groups have varying label distributions across different environments.
In this work, we study fairness provided by domain generalization methods on healthcare datasets according to common fairness metrics in machine learning such as equalized odds, we emphasize that such fairness criteria may not be relevant nor particularly useful in healthcare datasets where class often denotes diagnosis. For this reason, we suggest for future work that domain generalization in the clinical sector be evaluated according to other ethical and fairness criteria more suited to healthcare.

Best Practices for Domain Generalization in Medicine
From our evaluation of domain generalization using limited but publicly available healthcare datasets, we provide the following broad insights for applying domain generalization in medicine. First, very few existing benchmarks compare benefits of domain generalization methods to the oracle baseline, where test set data is observed. Though this baseline is impractical from a domain generalization perspective, in reality, a hospital could easily choose to train and deploy a model only on their data, instead of transferring from publicly available datasets. We find that, though this model would learn spurious correlations that exist within that hospital, this approach outperforms domain generalization in almost all cases. It is also important to consider the test environments for which the model will be deployed. In the domain generalization setup, there is no prior knowledge about how the test environments will look like during training time. However, this is not always the case in the real world. If there is a guarantee that the model trained will only be deployed at large hospitals only in the US, and temporal domain shift is not a factor, a simple ERM model could perform quite well, while relying on spurious correlations consistent across the US environments. In fact, in such cases, the test environment might not even be OOD, as in the base eICU example. This is more likely to be true when the majority of observed features (such as vitals or lab tests) tend to be invariant across demographics. In this scenario, careless application of domain generalization methods (with improper hyperparmeter tuning) could actually lead to worse model performance compared to ERM.
If, instead, the model created has the potential to be deployed in all regions throughout the world, it is then critical to learn a model that does not rely on US-specific spurious correlations. Domain generalization could potentially be useful in this case, where an invariant model is learnt in exchange for worse performance at sites in the US. In such cases, it is important to train on a set of environments that is as diverse as possible. This further suggests that without real diversity in training environments, learning models that are truly invariant to such spurious correlations is not possible with existing methods. It is also highly beneficial to conduct model selection using an environment, or a combination of environments, closest to where the model will be deployed.
In the field of medicine specifically, there already exist many known causal effects between various observed features [28,54]. Working with domain experts to delve into existing causal relationships in tabular data can provide invaluable insight both for constructing and benchmarking invariant models.
Finally, when considering the performance of a domain generalization method, it is important to look past its performance on Colored MNIST, as state-of-the-art performance in these datasets appears to have little correlation with performance on real-world data, likely due to their model selection using the test environment (see Appendix B). Instead, it is important to consider their performance on a large variety of realistic benchmarks such as DomainBed [32], WILDS [44], or our clinical framework.

CONCLUSION
Clinical models trained on one hospital or region typically degrade in performance in the presence of domain shift [5,21,50,63,73,74,77,84]. In this paper, we evaluated the performance of eight domain generalization methods on their ability to generalize to an unseen test environment for typical clinical datasets. We find, consistent with prior work on general image datasets [32], that these methods do not consistently exhibit significantly improved performance on chest X-ray datasets over empirical risk minimization. We then propose a framework for manually introducing realistic spurious correlations to the dataset, and find that there exist cases where domain generalization significantly outperforms empirical risk minimization. We observe no consistent improvement in fairness along with performance in the presence of sampling bias.
We believe that the results we have shown motivates the need for further testing of the failure and success modes of domain generalization in clinical settings, as well as theoretical justifications for the disparity between their performance on artificial shifts versus real-world shifts. We reiterate the message by Gulrajani and Lopez-Paz [32] that the model selection strategy is an integral part of a domain generalization method, and echo the sentiment by Koh et al. [44] for more realistic benchmarks for evaluating real-world domain shifts. We believe that our empirical framework that introduces synthetic domain shifts and sampling bias will prove to be useful starting step for stress-testing novel domain generalization methods, as well as inspire further work in domain generalization in medicine.

Appendix B COLORED MNIST B.1 Data Generation Process
Inspired by the work of Choe et al. [19] to vary data generation parameters in Colored MNIST, we introduce the following Colored MNIST data generation process with three adjustable parameters.
• : Average color flip probability between the two training environments. Corresponds to 1 -strength of the spurious correlation. Baseline value of 0.15. • : Gap between two training environments. Baseline value of 0.1.

B.2 Experiments
We vary each data generation parameter independently while keeping the others at their baseline values (which correspond to their settings in standard Colored MNIST). To model the data, we flatten the image and use a dense MLP with ReLU activations, consistent with prior work [6]. For each data generation setting and for each model, we use 20 iterations of random search over model hyperparameters (number of layers, number of units, dropout probability), algorithm hyperparameters (such as the penalty coefficient and the number of annealing iterations), and optimization hyperparameters (batch size and learning rate).
For early stopping and model selection, we experiment with using model accuracy for the following two schemes: • Training Domains: We use the pooled validation sets from the two training environments.
• Test Domain: We use a validation split from the test environment. This is the only model selection scheme used in the prior work for most domain generalization methods [2,6,45,46,82]. Note that as there are only three environments, we do not allocate a validation environment for Colored MNIST. First, we observe from Figure A1 that when the training domain is used for model selection, no method performs significantly better than ERM. The performance gains for domain generalization methods only appear when model selection is done directly on the test set. This is consistent with prior findings [32]. Though this is the setup used in the large majority of papers proposing domain generalization methods [2,6,45,46,82], having test environment data for model selection is not realistic, and defeats much of the purpose of domain generalization. This is also a potential explanation for why domain generalization methods, which work well on Colored MNIST in the literature, do not work well in our clinical experiments (which do not use the test domain for model selection).

B.3 Results
We also observe many intuitive correlations between the data generation parameters and the test environment accuracy. Increasing , the data corruption probability, tends to decrease model performance, consistent with prior work [19]. There is a pronounced increase in model performance as the training environment characteristics ( ) move closer to the test environment (0.9). There is a limited increase in model performance with increasing environment diversity. Surprisingly, some models are able to achieve better performance than ERM even when the two training environments originate from the same distribution. We attribute this to the use of early stopping based on the validation metric in our experiments, as well as the variance in samples from minibatches drawn between the training environments.
Finally, we note the shift in reliance on the spurious versus invariant correlations that occur as we change certain data generation parameters. This is most pronounced when the training domains are used for model selection. For example, as we increase above 0.15, the spurious correlation becomes stronger than the invariant correlation, and there is a marked drop in accuracy. Similarly, as we increase above 0.25, the spurious correlation becomes weaker than the invariant correlation, and there is a decided increase in test domain accuracy.