# Prediction and Comparison of In-Vehicle CO\({}_{2}\) Concentration Based on ARIMA and LSTM Models
## 2 Materials and Methods
### Prediction Models
#### 2.2.1 ARIMA Model  
The ARIMA model is a statistical model that combines autoregressive (AR) and moving average (MA) models to predict stochastic time series data. It was first proposed by [PERSON], an American researcher, and [PERSON], a British statistical researcher, in the 1970s [67]. The model identifies intrinsic relationships between historical and current values to forecast future data.  
The AR model is based on a mathematical equation to describe the autocorrelation in a time series, i.e., the relationship between the current moment (\(t\)) and the previous moment (\(p\)) values. The autoregressive model of order \(p\) is denoted as AR(\(p\)) and is expressed as shown in Equation (1):  
\[Y_{t}=c+\alpha_{1}Y_{t-1}+\alpha_{2}Y_{t-2}+\alpha_{3}Y_{t-3}+\ldots+\alpha_{p} Y_{t-p}+\varepsilon_{t} \tag{1}\]  
The MA model is known as a moving average model and represents a weighted average sum of several white noises. The \(q\)-th order moving average model is denoted as MA(\(q\)), as shown in Equation (2):  
\[Y_{t}=c-\beta_{1}\varepsilon_{t-1}-\beta_{2}\varepsilon_{t-2}-\beta_{3} \varepsilon_{t-3}-\ldots-\beta_{q}\varepsilon_{t-q}+\varepsilon_{t} \tag{2}\]  
Combining the AR model with the MA model yields the ARMA model, as shown in Equation (3):  
\[Y_{t}=c+\alpha_{1}Y_{t-1}+\alpha_{2}Y_{t-2}+\alpha_{3}Y_{t-3}+\ldots+\alpha_{ p}Y_{t-p}+\varepsilon_{t}-\beta_{1}\varepsilon_{t-1}-\beta_{2}\varepsilon_{t-2}- \beta_{3}\varepsilon_{t-3}-\ldots-\beta_{q}\varepsilon_{t-q} \tag{3}\]  
Figure 4: Test driving routes: (**a**) urban road (speed limit 0–40, length 13 km); (**b**) suburban road (speed range 0–80, length 12 km); (**c**) expressway (speed limit 60–120, length 28 km).  
The ARIMA model is the model calculated by differencing the data \(d\) times using the ARMA model, denoted as ARIMA (\(p\), \(d\), \(q\)). The ARIMA model is used for time series forecasting in the following steps:  
* Data stationarity analysis: Prior to establishing an ARIMA prediction model, it is imperative to evaluate the stationarity of the data. The augmented Dickey-Fuller test (ADF) is employed to estimate whether the data are stationary or not in this research. If the data exhibit stability, the significance \(p\)-value should be less than 0.05; otherwise, differencing must be applied to non-stationary data until they achieve stationarity.
* Estimation of model hyperparameters: The stationary time series data are further processed to obtain the autocorrelation coefficient (ACF) and partial autocorrelation coefficient (PACF). After determining the range of hyperparameters p and q, it is necessary to continuously try to determine the combination of model hyperparameters with the highest accuracy, but this method has an interference of certain human factors. Therefore, the \"auto. arima\" function in Python can be utilized to automatically determine the optimal combination of hyperparameters, selecting the optimal model by means of the Akaike Information Criterion (AIC) and Bayesian Information Criterion (BIC), thereby eliminating any potential influence from human factors during the selection process. The range of AIC and BIC values is not fixed but varies across different datasets. Usually, the combination of hyperparameter p and q that yields the smallest AIC and BIC values represents the most suitable model. The calculation method for AIC and BIC is shown in Equations (4) and (5): \[\text{AIC}=2k-2 ln(L)\] (4) \[\text{BIC}=kln(n)-2 ln(L)\] (5)
* Test the validity of the optimal model: Before forecasting, the effectiveness of the optimal model needs to be tested. Firstly, the Ljung-Box test method is used to judge whether the residual of the prediction model is a white noise sequence. If \(p\)-value \(>\) 0.05, it can be considered that the residual is a white noise sequence. Then, the Q test is used to check the normal distribution of the model residuals, and a Q-Q diagram is drawn to observe the distribution of the residuals.
* Forecast the data: After completing the aforementioned actions, predictions can be made.