


16 Sep 2025
The problem
Data and preliminary analysis
Experiment design and Modelling framework
Results
Key findings
Next steps



How can we accurately forecast hospital bed occupancy to improve resource allocation and patient care?
How can probabilistic forecasting models be developed to account for the inherent uncertainty in patient flow and bed availability?
What are the hidden factors influencing bed occupancy, and how can they be incorporated into forecasting models?
Daily hospital occupancy data from a UK hospital with 7 wards, spanning from July 2018 to April 2025. The dataset includes:
Strong upward trend in occupancy over time
Spike after COVID-19 pandemic




One approach to make the series stationary is to take the first difference of the series.
Original series: \(y_t, y_{t-1}, y_{t-2}, y_{t-3}, \ldots\)
Differenced series: \(y_t - y_{t-1}, y_{t-1} - y_{t-2}, y_{t-2} - y_{t-3}, \ldots\)




Let \(y_t\) be the observed value at time \(t\), modeled as a function of its \(p\) lagged values, the regime-specific parameters associated with the hidden state \(s_t\), and exogenous variables \(\mathbf{X}_t = (X_{t1}, \ldots, X_{tM})\).
The RS-ARHMM can be expressed as follows:
\[ y_t^{(s)} = \beta_{0}^{(s)} + \sum_{i=1}^{p} \beta_{i}^{(s)} \, y_{t-i} + \sum_{j=1}^{M} \beta_{p+j}^{(s)} \, X_{tj} + \epsilon_t^{(s)}, \]
where:
The Markov property: \[ P(s_t = k \mid s_{1:t-1}) = P(s_t = k \mid s_{t-1}), \quad \forall t \geq 2. \]
A HMM has the following components:
Transition matrix \(P\) is defined as:
\[ P = \begin{pmatrix} p_{11} & \cdots & p_{1K} \\ \vdots & \ddots & \vdots \\ p_{K1} & \cdots & p_{KK} \end{pmatrix} \]
weighted by the predicted regime probabilities:\[ \hat{y}_{T+h} = \sum_{j=1}^{K} P(s_{T+h} = S_j) \, \hat{y}_{T+h}^{(S_j)} \]
\[ P(s_{T+h} = S_j) = \sum_{i=1}^{K} P(s_{T+h-1} = S_i) \, p_{ij} \]
\[ \hat{y}_{T+h}^{s_{T+h}} = \beta_{0}^{(s_{T+h})} + \sum_{i=1}^{p} \beta_{i}^{(s_{T+h})} \, y_{T+h-i} + \sum_{j=1}^{M} \beta_{p+j}^{(s_{T+h})} \, X_{T+h,j} \]
EM (Expectation-Maximization) Algorithm
Iteratively estimates parameters \(\Theta = \{\beta^{(s)}, \sigma^{2(s)}, P, \pi\}\) to maximize likelihood.
Alternates between two steps:
1. E-Step
State probability:
\[
\gamma_t(i) = P(s_t = S_i \mid y_{1:T}, \Theta^{(k)})
\]
Transition probability:
\[
\xi_t(i,j) = P(s_t = S_i, s_{t+1} = S_j \mid y_{1:T}, \Theta^{(k)})
\]
Computed via Forward-Backward algorithm:
\(\alpha_t(i) = P(y_{1:t}, s_t = S_i \mid \Theta) = \sum_{j=1}^{K} \alpha_{t-1}(j) p_{ji} o_i(y_t)\)
\(b_t(i) = P(y_{t+1:T} \mid s_t = S_i, \Theta) = \sum_{j=1}^{K} p_{ij} o_j(y_{t+1}) b_{t+1}(j)\)
Emission (observation) likelihood:
\[
o_i(y_t) = \frac{1}{\sqrt{2\pi \sigma_i^2}} \exp\left( -\frac{(y_t - \mu_{i,t})^2}{2\sigma_i^2} \right)
\]
where \(\mu_{i,t}\) is AR + exogenous mean for state \(i\).
2. M-Step
Update parameters using weighted averages with \(\gamma_t(i)\):
Transition matrix:
\[
p_{ij}^{(k+1)} = \frac{\sum_{t=1}^{T-1} \xi_t(i,j)}{\sum_{t=1}^{T-1} \gamma_t(i)}
\]
Initial state:
\[
\pi_i^{(k+1)} = \gamma_1(i)
\]
Regression (AR/exog) coefficients:
\[
\beta^{(i,k+1)} = (\mathbf{X}^T \mathbf{W}_i \mathbf{X})^{-1} \mathbf{X}^T \mathbf{W}_i \mathbf{y}
\]
Where \(\mathbf{W}_i = \text{diag}(\gamma_1(i),\dots,\gamma_T(i))\)
Repeat E-M Steps until convergence:
\[|\ell(\Theta^{(k+1)}) - \ell(\Theta^{(k)})| < \epsilon\]
Captures regime changes in highly volatile time series data (e.g., healthcare), integrating them into the forecasting process, making it more accurate and reliable predictions.
Traditional statistical and modern machine learning models fail to account for such regime shifts.
Models complex dependencies and non-linear relationships with reduced risk of overfitting and less reliance on extensive hyperparameter tuning.
Produces interpretable results through regime-specific parameters.
Provides reliable forecasts that incorporate uncertainty arising from regime changes.
Statistical models:
Exponential Smoothing (ETS): A state space time series model capturing level, trend, and seasonality.Linear Regression: A statistical model that estimates the linear relationship between predictors and a response variable.Lasso Regression: A regression method with L1 regularization, useful for variable selection and preventing overfitting.Machine Learning models:
XGBoost: An optimized gradient boosting library designed to be highly efficient and flexible. It uses level-wise tree growth, building trees level by level horizontally.LightGBM: A gradient boosting framework that uses tree-based learning algorithms, known for its speed and efficiency. It uses leaf-wise tree growth.Random Forest: An ensemble learning method that builds multiple decision trees and merges them together to get a more accurate and stable prediction.calibration set of 500 observations per horizon.\[ r_{t+h} = y_{t+h} - \hat{y}_{t+h} \]
where \(y_{t+h}\) are the actual observed values and \(\hat{y}_{t+h}\) are the point forecasts for \(t+h\).
\[ q_{1-\alpha}^{(h)} = \text{Quantile}_{1-\alpha}(\{A_{t-n+h}\}_{t=t-n}^{n}) \]
where \(n\) is the size of the calibration set and \(1 - \alpha\) is the desired coverage level
\[ \left[\hat{y}_{t+h} - q_{1-\alpha}^{(h)}, \hat{y}_{t+h} + q_{1-\alpha}^{(h)}\right] \]
\[ y_{t+h}^{(i)} = \hat{y}_{t+h} + r_{t+h}^{(i)}, \quad r_{t+h}^{(i)} \in \{r_{t+h}^{(1)}, r_{t+h}^{(2)}, \ldots, r_{t+h}^{(n)}\} \]
Root Mean Squared Error (RMSE) \[ RMSE = \sqrt{\frac{1}{n} \sum_{t=1}^{n} (y_t - \hat{y}_t)^2} \]
Mean Absolute Error (MAE) \[ MAE = \frac{1}{n} \sum_{t=1}^{n} |y_t - \hat{y}_t| \]
Rolling-origin cross-validation is used to evaluate model performance over time

| ward_0 | RMSE | MAE |
|---|---|---|
| HMM | 3.208 | 2.757 |
| linearRegression | 3.258 | 2.804 |
| Lasso | 3.268 | 2.832 |
| RandomForest | 3.365 | 2.885 |
| LightGBM | 3.364 | 2.905 |
| XGBoost | 3.433 | 2.996 |
| ets | 3.679 | 3.168 |
| ward_1 | RMSE | MAE |
|---|---|---|
| ets | 3.646 | 3.169 |
| Lasso | 3.701 | 3.220 |
| RandomForest | 3.707 | 3.229 |
| linearRegression | 3.711 | 3.233 |
| HMM | 3.712 | 3.231 |
| LightGBM | 3.720 | 3.241 |
| XGBoost | 3.770 | 3.277 |
| ward_2 | RMSE | MAE |
|---|---|---|
| HMM | 2.843 | 2.406 |
| linearRegression | 2.862 | 2.426 |
| Lasso | 2.975 | 2.538 |
| LightGBM | 2.983 | 2.544 |
| XGBoost | 3.036 | 2.605 |
| RandomForest | 3.141 | 2.723 |
| ets | 3.210 | 2.800 |
| ward_3 | RMSE | MAE |
|---|---|---|
| Lasso | 1.992 | 1.664 |
| LightGBM | 2.009 | 1.700 |
| linearRegression | 2.044 | 1.724 |
| RandomForest | 2.058 | 1.730 |
| HMM | 2.078 | 1.749 |
| XGBoost | 2.098 | 1.776 |
| ets | 2.475 | 2.133 |
| ward_4 | RMSE | MAE |
|---|---|---|
| Lasso | 2.320 | 1.999 |
| linearRegression | 2.470 | 2.135 |
| HMM | 2.532 | 2.211 |
| ets | 2.592 | 2.244 |
| XGBoost | 2.660 | 2.314 |
| RandomForest | 2.825 | 2.486 |
| LightGBM | 3.344 | 2.946 |
| ward_5 | RMSE | MAE |
|---|---|---|
| HMM | 2.500 | 2.122 |
| RandomForest | 2.503 | 2.129 |
| LightGBM | 2.511 | 2.143 |
| XGBoost | 2.512 | 2.144 |
| Lasso | 2.517 | 2.144 |
| linearRegression | 2.532 | 2.156 |
| ets | 2.603 | 2.235 |




| T. Matrix | Regime 1 | Regime 2 |
|---|---|---|
| Regime 1 | 0.666 | 0.334 |
| Regime 2 | 0.487 | 0.513 |
| Std. Dev. | Regime 1 | Regime 2 |
|---|---|---|
| sd | 1.393 | 0.006 |
Although AR-RHMM may not always outperform all benchmark models in point forecasting metrics, there is a significant improvement in probabilistic forecasting, particularly in quantile loss across 40% and 85% quantiles.
The model is more reliable for probabilistic forecasting since it accounts for regime changes and provides a distribution of possible future values, making it suitable for decision-making in hospital resource management.
The model performs consistently well interms of probabilistic forecasting since the model is probabilistic in nature and captures regime changes.
Extend the AR-HMM to a multivariate framework (VAR-HMM) to jointly model multiple wards, capturing interdependencies and shared patterns in bed occupancy across different wards.
Develop an optimization framework that utilizes the probabilistic forecasts from the AR-HMM and VAR-HMM models to optimize bed allocation and resource management.
Test the models in real-world scenarios, collaborating with hospital staff to refine the models based on practical feedback and operational needs.