## 2 Materials and Methods
### Cross-Validation and Partial Least Squares Regression  
Partial least squares regression or PLSR is a multivariate technique based on the combination of dimensionality reduction similar to PCA and multiple linear regression (MLR) [36]. Unlike PLSR, the latent variables or factors (equivalent to principal components in PCA) are calculated taking into account the response variable [33]. With these latent variables a predictor matrix \(\mathbf{X}\) is built. Then, this matrix is used to build a regression model to explain the variance of the response variable \(\mathbf{Y}\). When \(\mathbf{Y}\) contains only one variable, the method is referred to as PLSR1, and when it contains more than one variable it is referred to as PLSR2; in both cases we refer to \(\mathbf{Y}\) as a matrix of response variables. Some exhaustive reviews of this method have been published [36,37]. PLSR1 was used to relate TC with spectral data. A common practice in soil spectroscopy is to use cross-validation techniques to select the optimal number of latent variables for PLSR. We performed leave-\(k\)-out cross-validation [38,39] to select the \begin{table}
\begin{tabular}{c c c c} \hline
**Soil order** & **Depth (cm)** & **Average** & **Standard Deviation** \\ \hline \multirow{3}{*}{Andisol} & 0–5 & 6.4 (12) & 2.42 \\  & 5–20 & 4.4 (12) & 1.65 \\  & 20–40 & 3.0 (12) & 1.29 \\ \hline \multirow{3}{*}{Ultisol} & 0–5 & 5.3 (12) & 1.55 \\  & 5–20 & 4.5 (11) & 1.26 \\  & 20–40 & 2.7 (11) & 1.78 \\ \hline \end{tabular}
\end{table} 
Table 1: Average of soil total carbon (TC) of each depth sampled for the two soil orders (Andisol and Ultisol). In brackets the numbers of samples averaged. number of latent variables for regression (also referred to as \(k\)-fold CV). In this technique, the data set is randomly split into \(k\) equal-sized groups, where \(k\) is defined by the user. We used \(k=5\) as recommended by [PERSON] et al. [39] and latent variables ranged from 1 to 20. One group is left out, and the model is calibrated with the remaining (\(k-1\)) groups. Then, the prediction accuracy of the model is evaluated using the group that was left out by comparing the predicted and measured values. This process is repeated until each group is used to validate the model. When the value of \(k\) is equal to the number of samples, this technique is referred to as leave-one-out cross-validation (LOOCV). The mean of statistical indicators such as root-mean-squared error (\(RMSE\)) (Equation (1)) and coefficient of determination \(R^{2}\) (Equation (2)) were used as a reference to evaluate the model performance. \[RMSE=\sqrt{\sum_{i=1}^{i}\frac{(y_{i}-\hat{y_{i}})^{2}}{n}} \tag{1}\]  
\[R^{2}=1-\frac{\sum_{i=1}^{i}(y_{i}-\hat{y_{i}})^{2}}{\sum_{i=1}^{i}(y_{i}- \overline{y}_{i})^{2}} \tag{2}\]  
where \(y_{i}\) is the measured value of sample \(i\), \(\hat{y_{i}}\) is the predicted value of sample \(i\) and \(\overline{y}\) is the average of measured samples. After the optimal number of latent variables were determined, the data set was split into two groups. The group for calibration contained 80% of the data set and the remaining 20% was used as validation group. Some strategies to split data have been applied by researchers [18; 33; 40]. Nonetheless, we performed an iterative procedure to find the best data split (80/20%) in terms of model performance i.e., several possible data splits of 80/20% were evaluated by PLSR. This was made using the scikit-learn library [41] of Python programming language (Python Software Foundation, [[https://www.python.org/](https://www.python.org/)]([https://www.python.org/](https://www.python.org/))), which achieves the same data split every time (pseudo-random) in order to reproduce the results. The best calibration/validation sets were selected by the higher \(R^{2}\) in PLSR. For the final model selection, all pre-processing configurations listed in Table 2 were applied to the spectral data before splitting.