Statistical modelling and forecasting of HIV and anti-retroviral therapy cases by time-series and machine learning models

Machine Learning


A statistical framework known as the AR model is employed in time series analysis to anticipate possible future outcomes based on prior values in the series. According to the framework, the data series present value is determined by an unpredictable (random) term and its prior values in a linear manner. In the late 1980s, many researchers focused on the HIV/AIDS epidemic, developing mathematical and statistical models to describe its trends, and impact, and predict new cases. Some of these models were complex and challenging to understand, interpret, and implement. The forecasting of HIV and ART cases in Pakistan was conducted using the ARIMA model and an ANN approach. These methods have been chosen for their proven efficacy in time series analysis and predictive modeling of infectious diseases. Mathematically it can be expressed as follow;

$$\begin{aligned} z_v = c + \phi _1 z_{v-1} + \phi _2 z_{v-2} + \cdots + \phi _p z_{v-p} + \epsilon _v \end{aligned}$$

(1)

With the backshift operator, the ARIMA model can be expressed as follow;

$$\begin{aligned} \phi (B)(1 – B)^d z_v = \theta (B)\epsilon _v \end{aligned}$$

(2)

here; In Eq. (1), \(z_v\) is the value of the time series at time v, c is a constant term, \(\phi _1, \phi _2, \ldots , \phi _p\) are autoregressive coefficients, \(z_{v-1}, z_{v-2}, \ldots , z_{v-p}\) are lagged values, p is the order of the AR model, and \(\epsilon _v\) is the white noise error term. In Eq. (2), B denotes the backshift operator such that \(B z_v = z_{v-1}\), \((1 – B)^d\) is the differencing operator to achieve stationarity, \(\phi (B)\) is the autoregressive polynomial (e.g., \(1 – \phi _1 B – \phi _2 B^2 – \cdots – \phi _p B^p\)), \(\theta (B)\) is the moving average polynomial (e.g., \(1 + \theta _1 B + \theta _2 B^2 + \cdots + \theta _q B^q\)), d is the order of differencing, and \(\epsilon _v\) is the error term.

The ARIMA is a time series forecast technique that resembles to a linear Morrison-Camping function relating the past values and random errors. ARIMA makes it possible to separate the time series into underlying trends, cyclical regularities, and stochastic noise. ARIMA modeling is a four-step procedure.

  1. 1.

    First, ensure the series is stationary by applying the augmented Dickey-Fuller (ADF) test, which tests the null hypothesis that the series is non-stationary. Once stationarity is established, use graphical tools like the autocorrelation function (ACF) and partial autocorrelation function (PACF) to identify the order of the model parameters.

  2. 2.

    In the second step, the ACF and PACF plots are used to estimate a suitable candidate model for the data. The final model is selected by testing various combinations of these candidate models and evaluating their accuracy parameters.

  3. 3.

    The third step involves testing the residuals’ normality using the ACF plot, QQ-Norm plot, and Shapiro-Wilk test, with the best model advancing to the next stage if it passes all tests.

  4. 4.

    In the last step, we use the selected model to forecast a series that satisfies the above mentioned conditions. The model will be fitted in the following steps;

    1: Data-reprocessing

    2: Calculate the p-value for ADF test on input dataset

    3: if P-value is greater than 0.05 then

    4: Data is not Stationary

    5: end

    6: ARIMA

    7: Fit the model

    8: Apply forecast prediction on Data

    9: Calculate the RMSE,MSE, MAPE

    10: Plot a graph for observed and fitted values

    11. Plot the Forecast Data points with confidence intervals.

ETS

The ETS model is also considered a simple exponential smoothing model. In this model, it corresponds to the (A, N, N) model, that is, a model which has additive errors and has no trend and seasonality. Such models capture the underlying components of a time series: error, trend, and seasonality. The model of ETS can be expressed by the following equation;

$$\begin{aligned} \hat{z}_v = \alpha z_{v-1} + (1 – \alpha ) \hat{z}_{v-1} \end{aligned}$$

(3)

here, \(\hat{z}_v\) is the forecasted value at time v, \(z_{v-1}\) is the actual value at time \(v-1\), \(\hat{z}_{v-1}\) is the forecasted value at time \(v-1\), and \(\alpha\) \((0< \alpha < 1)\) is the smoothing constant that determines the weight given to the most recent observation. They are useful for forecasting data that exhibit seasonality and trend patterns. HIV/AIDS cases often exhibit seasonal variations influenced by factors such as weather patterns affecting transmission rates or variations in healthcare access during different times of the year. In practical terms, ETS models can be applied to HIV and ART data to forecast future monthly cases, aiding healthcare authorities in resource allocation, treatment planning, and policy formulation. The algorithm of ETS can be defined as follows;

1: Call the Data

2: Apply Holt on Time-series Data

3: Create the Holt0

4: Model

5: Fit the Model for optimal values of parameters

6: predict the forecasted holt

7: Calculate the RMSE, MSE, MAPE

8: Plot a graph for observed and fitted values

9: Plot the Forecasted Data points with confidence.

Brown Holt and Winter method

The Brown Holt, and Winters methods are widely used exponential smoothing techniques for time series forecasting, each designed to handle different types of data trends and seasonal patterns. These methods offer an alternative to traditional autoregressive models by placing more weight on recent observations, making them effective for short term forecasting. BHW is a simple method that works well for short term forecasting of stationary data without trends or seasonality. In contrast, ARIMA is more powerful, handling trends and seasonality through differencing and autoregressive components. However, ARIMA requires more assumptions, manual tuning, and stationarity checks, while BHW is easier to implement but less effective for long term or complex patterns. In the context of forecasting HIV and ART (anti-retroviral therapy) cases, the Brown-Holt-Winters (BHW) method, also known as exponential smoothing with trend and seasonality, offers a structured approach to handle time series data that exhibit both trend and seasonal patterns. The BHW method extends basic exponential smoothing by incorporating adjustments for trend and seasonality. The equations are:

$$\begin{aligned} S_t&= \alpha Z_t + (1 – \alpha ) S_{t-1} \\ S’_t&= \alpha S_t + (1 – \alpha ) S’_{t-1} \\ F_{t+h}&= 2S_t – S’_t + \frac{h}{1 – \alpha }(S_t – S’_t) \end{aligned}$$

It operates by assigning exponentially decreasing weights to past observations, with higher weights given to more recent data points. Holt’s method extends simple exponential smoothing to include a linear trend. The equations can be expressed as follows;

$$\begin{aligned} L_t&= \alpha Z_t + (1 – \alpha )(L_{t-1} + T_{t-1})\\ T_t&= \beta (L_t – L_{t-1}) + (1 – \beta ) T_{t-1}\\ F_{t+h}&= L_t + hT_t \end{aligned}$$

Here \(Z_t\) is the observed value, \(S_t\) and \(S’_t\) are the first and second smoothed values in double exponential smoothing, \(L_t\) and \(T_t\) represent the level and trend in Holts method, \(\alpha\) and \(\beta\) are smoothing parameters, and \(F_{t+h}\) denotes the forecast h steps ahead. The BHW method can effectively capture and predict trends in HIV/AIDS cases and ART usage over time. By combining trend and seasonal adjustments, the BHW method can provide reliable forecasts of future HIV/AIDS and ART cases. BHW forecasting method is generally considered a non-linear time series method.

1: Call the Data

2: Apply Exponential smoothing on Time-series Data

3: Create and hypertune model according to the dataset

4: Model

5: Fit the Model for optimal values of parameters

6: predict the forecasted holt

7: Calculate the RMSE, MSE, MAPE

8: Plot a graph for observed and fitted values

9: Plot the Forecasted Data points with confidence.

Neural network auto-regressive model (NNAR)

The Neural Network Autoregressive (NNAR) model is a specialized type of artificial neural network (ANN) designed for time series forecasting. It extends traditional autoregressive (AR) models by incorporating nonlinear relationships through neural network structures. The NNAR model is particularly useful for datasets like HIV and ART cases, which exhibit complex, nonlinear temporal dependencies. NNAR is the type of Artificial neural network (ANN) model that is a highly effective non-linear time series forecasting method, particularly suited for datasets such as HIV and ART cases, which display complex and nonlinear temporal patterns. Unlike traditional linear models, the NNAR model utilizes artificial neural networks (ANN) to capture intricate dependencies and relationships within the data. Neural networks are computational models inspired by the human brain, designed to recognize patterns and relationships within data. They consist of interconnected layers of nodes, or neurons, that process input data to generate predictions or classifications. The Neural Network Autoregressive (NNAR) model is preferred over traditional time series models, such as ARIMA and ETS, due to its ability to capture complex, nonlinear relationships in data. Traditional models assume linear dependencies and require strict conditions like stationarity and manual feature selection, making them less effective for datasets with intricate patterns, such as HIV and ART cases. In contrast, NNAR leverages artificial neural networks to automatically learn optimal lag structures and feature interactions, adapting dynamically to changing trends. Unlike ARIMA, which relies on predefined seasonal components and differencing to remove trends, NNAR directly models both short- and long-term dependencies without requiring such transformations. The network typically includes:

  • Input layer: Receives the initial data.

  • Hidden layers: Transform the input data through weighted connections and activation functions.

  • Output layer: Produces the final prediction.

In the NNAR model, specifically a feed-forward neural network with one hidden layer, lagged values of the time series serve as inputs. These include lags from 1 to p and from m to mp, where m corresponds to the frequency of the time series (e.g., 12 for monthly data, 7 for weekly data). The NNAR (p, k) model is structured based on the lagged time series data, where “p” represents the input lags and “k” denotes the number of nodes in the hidden layer. The NNAR (p, 0) model closely mirrors the ARIMA (p, 0, 0) model but without the constraints of stationarity. For seasonal data, the model is expressed as NNAR (p, P, k) [m], analogous to ARIMA (p, 0, 0) (P, 0, 0) [m], and similarly free from stationarity restrictions. The NNAR model can be described as;

The input layer represents lagged inputs:

$$\begin{aligned} \textbf{z}_t = [Z_{t-1}, X_{t-2}, \ldots , Z_{t-p}, Z_{t-m}, Z_{t-2m}, \ldots , Z_{t-Pm}] \end{aligned}$$

(4)

The hidden layer transforms inputs using an activation function as follow;

$$\begin{aligned} h_j = g \left( \sum _{i=1}^{p+P} w_{ij} z_{t-i} + b_j \right) , \quad \text {for}\quad j = 1, \ldots , k \end{aligned}$$

(5)

The output layer combines hidden layer outputs linearly:

$$\begin{aligned} \hat{Z}_t = \sum _{j=1}^{k} v_j h_j + c \end{aligned}$$

(6)

In these equations, \(\textbf{z}_t\) is the input vector consisting of lagged observations including seasonal lags, \(h_j\) is the output of the j-th hidden neuron using activation function \(g(\cdot )\), \(w_{ij}\) and \(b_j\) are the weights and biases of the hidden layer, k is the number of hidden neurons, and \(\hat{Z}_t\) is the predicted output computed as a weighted sum of hidden layer outputs plus bias c.

This model can be implemented using the “forecast” package in R through the “nnetar” function, designed for seasonally adjusted data. By default, P is set to 1 for seasonal models, and p is derived from the best-fitting linear model for seasonally adjusted data. However, estimating prediction intervals for forecasts generated by neural networks is challenging due to the lack of a clearly defined stochastic process.The current NNAR model has utilized sigmoid activation function in hidden layers. The algorithm proceeds as follows.;

1: vector object – (“ts” class in R)

2: “nnetar” function to fit model

3: “Accuracy”- function for MSE, RMSE, MAE

4:Visualize the forecasted values and prediction intervals using the plot function

Accuracy measures

The commonly used accuracy metrics—root mean square error (RMSE), mean absolute error (MAE), and mean absolute percentage error (MAPE) are employed to identify the best model among competing options (Table 2).

Table 2 Key performance indicators (KPI).

RMSE (Root Mean Square Error) and MAE (Mean Absolute Error) are both important metrics used to assess the performance accuracy of time series (TS) models. RMSE provides an estimate of how well the model predicts the intended value, with a lower RMSE indicating better accuracy. It squares the errors before averaging, making it more sensitive to larger discrepancies between predicted and actual values. On the other hand, MAE measures the average magnitude of the errors in a more straightforward manner, increasing linearly with the size of the error. Unlike RMSE, MAE is simpler, more robust, and easier to interpret, which makes it particularly useful in forecasting. While RMSE tends to penalize large errors more heavily, MAE offers a clearer, more intuitive measure of model accuracy, making it a valuable tool for evaluating time series models in various application.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *