## 4 Development and Simulation of a Predictive S&OP Methodology
### Statistical Treatment of Demand for a Defined Case Study
#### 4.2.2 Statistical Treatment  
The goal of this subsection is to apply the methodology with the following steps:  
* Calculation of the expected demand based on the different scenarios and their probability of occurrence;
* Statistical analysis of the weighted expected demand (WED) to identify demand patterns and their changes;
* Generation of suitable random numbers. First, the WED is calculated as the average of the three scenarios, with their different weights according to their probability of occurrence. Figure 9 shows the resulting demand data series. Observing the time series helps to detect patterns or behaviors to obtain information about the series. In this research, a time series is characterized by a succession of data observed over time, obtained sequentially by default at regular intervals of time, in which the order of the data is important and cannot be altered. In this context, demand data fulfill these characteristics, as there is a demand value for each working day. To test if a data series is stationary, _weak stationarity_ is chosen, in which a series is stationary if it is stable in its mean and autocovariance. A very useful function to measure the dependence between two separate \(h\) units of time is the _autocorrelation function_\(\rho(h)=\gamma(h)/\gamma(0)\). The first step consists of observing the series (Figure 9) and determining its stationarity. For this purpose, the Dickey-Fuller test [41] (or unit roots) was applied using the R Studio test package [42], showing that the series is stationary because the \(p\)-value is < 0.05:  
* Data: weighted expected demand (WED) data series;
* Test: augmented Dickey-Fuller test;
* Alternative hypothesis: stationary;
* Results: \(\circ\) & Dickey-Fuller = -3.7563; \(\circ\) & Lag order = 9; \(\circ\) & \(p\)-value = 0.02118. Additionally, since approximately the first 100 data values present a lower variance than the rest of the data, a changepoint test was performed for the mean and variance using the changepoint package [43], the results of which are shown in Table 2. These results indicate a change in variance at point 105 and the average at 933. Figure 9: Weighted expected demand (WED) (own elaboration). Based on the changepoint analysis, three different methods for random number generation were analyzed to select the one that best suits the WED data series:  
1. **Harmonic series:** A first approximation due to the periodic and cyclical nature of the series, which consists of carrying out a harmonic regression and a spectral analysis of the series, considering that each point of the series can be decomposed into a sum of sines and cosines, where \(y_{t}\) is the value of the series at each time \(t\), \(a_{j}\) and \(b_{j}\) are the \(j\) harmonic coefficients of the series, and \(n\) is the period of the series:  
\[y_{t}=a_{0}+\sum_{j=1}^{(n-1)/2}\bigl{[}a_{j}\cos(2\pi t\ j/n)+b_{j}\sin(2\pi t \ j/n)\bigr{]}. \tag{4}\]  
Analysis of the S\({}_{2}\) data series provides a frequency of 0.008464 Hz, which indicates a period of 118.143 s--that is, the series is composed of a single wave that uses approximately 118 data values for one cycle. The coefficients a and b of the model are then estimated by harmonic regression, complemented by a study of higher order harmonics to determine their impact on the regression model. Table 3 shows the results of the following harmonic regression. \begin{table}
\begin{tabular}{c l c c} \hline \hline
**No.** & **Changepoint Test Parameters** & **Mean** & **Variance** \\ \hline
1 & Changepoint Type & Change in mean & Change in variance \\
2 & Test Statistics & Normal & Normal \\
3 & Minimum Segment Length & 1 & 2 \\
4 & Maximum no. of Changepoints & 1 & 1 \\
5 & Changepoint Locations & 933 & 105 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Changepoints of the WED data series for the mean and variance. Figure 10: Changes in the variance and mean of the WED data series (own elaboration).