Feature not applicable to some samples I am working with a private medical dataset including categorical features coming from patients examinations.
However, the problem is that some patients underwent MRI, others scanner, and some underwent both.
Thus, scanner-only patients have missing values in the MRI associated features, and vice-versa.
How could I handle this situation?
I thought about 3 solutions for now:

*

*Using an "examination not passed" category to replace missing values, but this would be considered as a full category on itself by machine learning algorithms. They could make correlations such as "exam not passed" => "class number 1" but there is no link between both as the examination rely on availability of imaging devices in the hospitals from where the data were collected. Some just didn't own MRI devices, etc.


*Treat MRI, scanner, and MRI+scanner patients as 3 different datasets and train a different model on each one. But doing so would imply writing specific code wrapping Sklearn objects in order to automatize the whole training process.


*Using a model robust to missing values such as XGBoost. I don't think it is a good idea, my problem should be handled beforehand as XGBoost uses its own imputing values. It is just moving the problem elsewhere.
 A: You can encode variables related with MRI for Not applicable cases using an out of range value, i.e., if your measures lay between 0 and 1000 you can encode the N/A cases as -1000. I can think on at least two reasons you should not let it missing and rely on XGBoost to handle it:

*

*It is not clear if XGBoost implicit imputation can provide unbiased estimators beyond missing completely at random (MCAR) mechanism, when the missingness is just a random sample of the observed values. Simulation studies are needed to understand its limitations.

*This is not real missingness, you know that they weren't examined because of lack of resources or they didn't comply with clinical criteria for being examined by MRI. So you should not impute these cases.

The lack of information can be also informative. It can happen that people that were screened by MRI have a better prognostic because this is an important examination that prevents patient deterioration by allowing for early intervention. Or, even more fundamental, hospitals without this machine lack resources compared to the ones where MRI is available leading to better patient care.
However, I can anticipate that performing imputation for actually missing values after encoding this variable can cause an inconsistency problem. For example, imputing one of the MRI related features with the out-of-range value and then imputing the other ones with possible values inside the measurement range when all of them should be -1000.
A: Based on the comment on your original questions, I think the easiest solution would be to have two columns per test (overall 4). Lets say the patient passed the MRI the then she would receive a 1 in the first column and a 0 in the second.
If she did not pass she would failed, she gets a 0 in the first and a 0 in the second column. In case she did not receive the treatment, both column are set to 0.
Same goes for the other test, with two new columns.
A: I don't think the answers so far by users @Janosch and user The Doctor really answers your problem. Use the solution given at How do you deal with "nested" variables in a regression model?,  with one indicator variable has_MRI and another indicator variable has_scanner. Then, in R-speak, use a linear predictor including
 has_MRI + has_MRI:MRI + has_scanner + has_scanner:scan + ...

