# LoRaWAN Path Loss Measurements in an Urban Scenario Including Environmental Effects
## 5 Path Loss and Shadowing Modelling
### Data Preparation  
To develop the CPLS models that can be seen as application examples of our dataset, we followed the process depicted in Figure 11. After collecting the in-field measurements, we processed the outliers using the Mahalanobis distance \(M_{d}\)[41]. This distance measures how far an observation and the dataset's distribution is; in addition, it is not affected by the scales of the predictor variables and considers the covariance between them. According to [41], a row is considered an outlier if \(M_{d}\) is greater than the tabulated value of the \(\chi^{2}\) distribution with \(n-1\) degrees of freedom and with a significance level \(p=0.001\). Because the predictor variables that could be used from the dataset for modeling purposes are distance, frequency, SF, frame length, temperature, relative humidity, barometric pressure, particulate matter, time on air, energy, and experimental path loss, we have 11 degrees of freedom. Thus, the tabulated value of the \(\chi^{2}\) distribution with 10 degrees of freedom and a \(p\)-value = 0.001 is 29.59. Then, we calculated \(M_{d}\) for all the observations and removed those whose value was greater than 29.59.  
In the second step, we split the dataset into two subsets: one for training and one for testing. The idea behind this division is to adjust the models' parameters with the training subset and assess the model's ability to perform accurate predictions with new and unseen data (the test subset). In our case, we divided the whole dataset with 80% of rows for training, and 20% for testing, as commonly recommended in the literature [42] and previous path loss model approaches [25; 26]. We divided the rows for both subsets by using a random split with a fixed seed to ensure the reproducibility of the results using the library _caTools_ of \(RStudio\). We decided to use a uniformly distributed random split to correctly capture the CPLS changes caused by the environmental variables, which are very diverse in tropical regions like Colombia. Furthermore, using a uniformly distributed random split does not alter the distributions of predictor variables. The relation between the training subset, the testing subset, and the whole data frame in time is depicted in Figure 12, where it can be noticed that the subsets proportions are the same for each time interval.  
In the third step, we divided our training subset into five folds to carry out k-fold-based cross-validation. This process helps reduce the risks of overfitting when calculating the models' parameters [42]. Mainly, the operation principle is as follows: (_i_) divide the training subset into \(a,b,c,d\) and \(e\) folds, (_ii_) calculate the models' parameters with the folds \(a,b,c\), and \(d\), and calculate the RMSE with the fold \(e\), (_iii_) iterate the literal _ii_ alternating the folds, and (_iv_) calculate the average RMSE and the standard deviation of the RMSE for all the iterations. If the obtained model weights achieve low RMSE and standard deviation, it is considered that the model has a good ability for generalization. Finally, the fourth step uses the obtained model with unseen data, i.e., the testing set, and calculates the RMSE and R\({}^{2}\).  
Figure 10: Theoretical behavior of path loss and shadowing. The dissipation caused by the channel, i.e., the ratio between the transmitted power P\({}_{t}\) and the received power P\({}_{r}\), changes according to the logarithm of the distance \(d\)[12].