# Comparisons of Spatially Downscaling TMPA and IMERG over the Tibetan Plateau
## 2 Materials and Methods
### Methods  
#### 2.3.1 Random Forest  
RF was developed as an extension of the CART to improve the accuracy and stability of the CART model [43]. To perform a regression in CART, the model searches every distinct value of every predictor in the entire data set (S) to find the optimal predictor and split values that are used to partition the data into two groups (S\({}_{1}\) and S\({}_{2}\)), such that the overall sum of squared error (SSE) is minimized [44]:  
\[SSE=\sum_{i\in S_{1}}\left(y_{i}-\overline{y}_{1}\right)^{2}+\sum_{i\in S_{2}} \left(y_{i}-\overline{y}_{2}\right)^{2} \tag{1}\]  
where \(\overline{y}_{1}\) and \(\overline{y}_{2}\) represent the averages of the training set outcomes of groups S\({}_{1}\) and S\({}_{2}\), respectively. The process continues within sets S\({}_{1}\) and S\({}_{2}\) until the number of samples in the splits falls below some threshold.  
To reduce the variance of the estimates, bagging (short for bootstrap aggregation) strategy was proposed. The bagging method generates \(m\) bootstrap samples of the original data and trains the tree model for each bootstrap sample. Each model is then used to generate a prediction for a new sample, and these \(m\) predictions are averaged to obtain the bagged model's prediction. However, the trees in bagging are not completely independent of each other because of the underlying relationship between the predictors and responses. The trees from different bootstrap samples may have similar structures that prevent bagging from optimally reducing the variance of the predicted values. Random Forest was developed to reduce the tree correlation by randomly selecting predictors at each split.  
The main steps of the random forest algorithm were as follows.  
1. To randomly generate _ntree_ bootstrap samples from the original dataset. The elements not selected are referred to as 'out of bag' (OOB) samples.
2. For each split, to randomly select \(m_{try}\) predictors of the original predictors and choose the best predictor among the \(m_{try}\) predictors to partition the dataset. Additionally, \(m_{try}\) is the tuning parameter of the model.
3. To predict new data (OOB elements) by averaging predictions of the _ntree_ trees.
4. The OOB samples were used to estimate the prediction error. The OOB estimate of the error rate [45] was calculated as follows: \[MSE_{obb}=\frac{1}{N}\sum_{i=1}^{N}\left(y_{i}-\hat{f}_{obb}[X_{i}]\right)^{2}\] (2) where \(\hat{f}_{obb}[X_{i}]\) represents the observation of the \(i\)th OOB prediction.  
The random forest can provide a measurement of variable's importance. One of the approaches is to look at the increase in the OOB estimate error when the specific predictor variable is randomly permuted and other predictors are kept unchanged. The more the error increases, the more important the variable is. These variable importance values are used to rank the predictors in terms of their relative contribution to the model. The random forest model was generated using the package _randomforest_ in R ([[https://cran.r-project.org/web/packages/randomForest/](https://cran.r-project.org/web/packages/randomForest/)]([https://cran.r-project.org/web/packages/randomForest/](https://cran.r-project.org/web/packages/randomForest/))).