If I understand your problem correctly, I think it's possible¹, but you have to do some extra work and you may be limited with what models you can use.
First, you have a time-varying dataset, so that must be handled correctly. Your poison comes long after birth, and that's important to model. Otherwise you are biasing your model. Ex: Suppose everyone is poisoned at age 90, if they live that long. Then just the act of being poisoned is a signal of living a long time, when in reality, it will hasten the death of the subject. Give this a read too, for many more arguments why it's important to model time-varying covariates.
Okay, so I took your dataset, and I modelled it into a time-varying dataset (see below). Notice:
- A subject could have more than 1 rows (in your case, everyone will have at most two rows, one for prior to poisoning, one for after)
- Each row for a subject is mutually exclusive (see
stop columns). The
status is True iff they died at the end of that interval.
poisoned is a boolean flag for activating after they were poisoned.
start poisoned sex stop id status
0 0 0 f 90 0 False
1 90 1 f 92 0 True
2 0 0 f 90 1 False
3 90 1 f 150 1 False
4 0 0 f 90 2 False
5 90 1 f 91 2 True
6 0 0 m 60 3 False
7 60 1 m 130 3 True
8 0 0 m 60 4 False
9 60 1 m 150 4 False
10 0 0 m 60 5 False
11 60 1 m 62 5 True
The above matrix has the exact same information, but presented differently.
Okay, so we now need to pick a model that can handle time-varying datasets. Let's take a step back and ask "after fitting a model on the training data, can I "transport" that to the testing data (which has no poisonings)?" I argue that, yes, this is valid, and will be more valid you have individuals who died before being poisoned. What your model will do is understand the risk factors associated with your variables given poisonings / no poisoning. Hence, when you move to your test data, the risk factors are already learned and prediction can be done. Here's an analogy: I'm studying the student exam scores on Canadian and American students, and have other variables like lunch, grade, background etc and possibly interactions between them. The objective of "fitting" is to learn the relationship of lunch on exam scores given the other variables. So when I focus my model on only Canadian students in the test data, my model is still valid.
(However, if I had no Canadian students in my training data, then the model's validity can be questioned if I wish to focus on Canadian students in the test data. This is why I hope there are subjects in your training data who died before being poisoned).
We can fit the time-varying dataset using Cox's proportional hazard model. The (linear) model's output looks like:
coef exp(coef) se(coef) z p -log2(p) lower 0.95 upper 0.95
poisoned 17.60 4.41e+07 2670.86 0.01 0.99 0.01 -5217.18 5252.38
sex -0.82 0.44 1.25 -0.66 0.51 0.97 -3.28 1.64
From your description, it sounds like your test data is not time varying. That's fine, it still fits into the time-varying framework: simply each test subject has a single row. You can choose to leave the
poisoned variable out, or just leave it as 0 throughout. The latter is probably easier, especially if you have interactions.
¹ I could be missing some important gotcha that renders this all useless. Generally, working with time-varying data is easy to mess up causality/data leakage.