We’ve been working on correctly handling missing states for our mostr package.
A colleague pointed out that with missingness, we are not maximizing the correct likelihood. We should average over the paths the patient could have taken. Currently, one can do a hybrid solution by including the row with the missing Y using Ocens(). But for the next row yprev has to be imputed or carried forward, which is not elegant (and does not respect the Markov structure of the model).
With the help of Fable 5.2, I was able to implement this in a very, very efficient way, so model fitting doesn’t take much longer than with complete data, even if averaging over thousands of paths in situations of high missingness. Use of Ocens() is also supported. Essentially, we fit the model first on the rows with an observed state, and then optimize the correct likelihood using Newton-Raphson, while always averaging over the paths the patients could have taken.
The result is removal of bias and often higher efficiency because we use all information available.
However, the resulting code is so difficult for me/us to parse that it will probably still take some time until this becomes a part of the R package.
If anybody wants to contribute, they are of course very welcome.
Small example where 70% of non-absorbing states are randomly missing.
library(mostr)
# 10,000 patients in two arms, ACTT-2 preset, daily states for 28 days,
# treatment odds ratio 0.8 for being in a worse state.
complete <- sim_markov(
"actt2",
n_patients = 10000,
times = 1:28,
treatment_effect = log(0.8),
seed = 20261117
)
# One row per patient and day with the state `y` and the previous day's
# state `yprev`; state 8 (death) is absorbing.
complete <- prepare_markov_data(complete, absorb = 8L)
# Delete each non-absorbing state with probability 0.7, independently of
# everything else (missing completely at random). Deaths are always recorded.
set.seed(1)
observed <- complete
y <- as.integer(as.character(complete$y))
missed <- y != 8 & stats::runif(nrow(complete)) < 0.7
# On the row after a deleted state, the previous state is unknown as well.
same_patient <- c(FALSE, complete$id[-1] == complete$id[-nrow(complete)])
after_missed <- c(FALSE, missed[-length(missed)]) & same_patient
observed$y[missed] <- NA
observed$yprev[after_missed] <- NA
# fit model and drop any rows with missing data
fit_drop <- mostm(
y ~ yprev + rms::rcs(time, c(2, 6, 11, 16, 21, 27)) + tx,
data = observed, id_var = "id", absorb = "8",
missing_states = "drop"
)
# fit and average over the paths the patients could have taken
fit_average <- mostm(
y ~ yprev + rms::rcs(time, c(2, 6, 11, 16, 21, 27)) + tx,
data = observed, id_var = "id", absorb = "8",
missing_states = "average"
)
Time it takes to fit the models
| Fit |
Time per mostm() call |
Iterations |
| Rows dropped |
1.8–2.2 s |
9 (rms::orm()) |
| Averaged over unobserved states |
15.7–16.1 s |
12 Newton iterations |
| Complete data, for reference |
5.8–6.1 s |
not read out |
Dropping rows with missing data → mortality overestimated
Coefficient Table
|
Complete data |
Rows dropped |
Averaged |
Simulation |
| y ≥ 2 |
−0.665 (0.028) |
−0.832 (0.073) |
−0.701 (0.038) |
−0.6465 |
| y ≥ 3 |
−4.867 (0.054) |
−4.909 (0.161) |
−4.823 (0.083) |
−4.9314 |
| y ≥ 4 |
−5.148 (0.054) |
−5.224 (0.161) |
−5.120 (0.084) |
−5.2230 |
| y ≥ 5 |
−7.338 (0.056) |
−7.383 (0.164) |
−7.319 (0.087) |
−7.4169 |
| y ≥ 6 |
−11.461 (0.058) |
−11.625 (0.170) |
−11.457 (0.090) |
−11.5321 |
| y ≥ 7 |
−15.171 (0.062) |
−15.282 (0.183) |
−15.179 (0.095) |
−15.2262 |
| y ≥ 8 (death) |
−21.976 (0.078) |
−21.112 (0.211) |
−21.933 (0.107) |
−22.0693 |
| yprev = 2 |
−0.004 (0.022) |
0.058 (0.073) |
0.048 (0.069) |
0 |
| yprev = 3 |
6.195 (0.065) |
6.158 (0.216) |
6.200 (0.127) |
6.2218 |
| yprev = 4 |
7.081 (0.050) |
7.111 (0.153) |
7.043 (0.081) |
7.1412 |
| yprev = 5 |
9.877 (0.051) |
9.937 (0.159) |
9.850 (0.083) |
9.9809 |
| yprev = 6 |
14.102 (0.057) |
14.199 (0.173) |
14.098 (0.091) |
14.1645 |
| yprev = 7 |
19.309 (0.065) |
19.471 (0.199) |
19.313 (0.099) |
19.3517 |
| time |
−0.306 (0.006) |
−0.289 (0.017) |
−0.302 (0.009) |
−0.3084 |
| time′ |
2.473 (0.083) |
2.338 (0.247) |
2.414 (0.118) |
2.5186 |
| time″ |
−4.929 (0.214) |
−4.600 (0.658) |
−4.765 (0.311) |
−5.0276 |
| time‴ |
3.107 (0.262) |
2.796 (0.842) |
2.887 (0.394) |
3.1714 |
| time⁗ |
−1.039 (0.244) |
−1.006 (0.814) |
−0.820 (0.384) |
−1.0672 |
| tx |
−0.206 (0.010) |
−0.232 (0.032) |
−0.210 (0.012) |
−0.2231 |
| Treatment odds ratio |
0.814 |
0.793 |
0.810 |
0.800 |