forked from FAO-SID/SOC-Mapping-Cookbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
13-code-examples.Rmd
252 lines (135 loc) · 7.38 KB
/
13-code-examples.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# Compendium of the code examples {#compendium}
*G.F. Olmedo*
This technical manual gives relatively simple step-by-step guidance on DSM. Guidance is mainly on mapping and modelling of soil organic carbon, but also contains generic sections on soil grid development that can be used to map various soil properties. The document follows the typical DSM work-flow and provides users a complete soil property mapping solution from the ground up (see Fig. \@ref(fig:grworkflow)).
The authors have demonstrated the methods in the previous Chapters using a dataset extracted from the Macedonian Soil Information System (MASIS). In this Chapter we present a compendium of the technical steps presented in the practical chapters.
With the help of these examples, the user should be able to produce a soil property map starting from ground data to the validation of the map. There are also optional work-flow steps depending on the nature of the input data. The **framework** presented in this manual is aiming to help users preparing a soil property prediction map includes soil data preparation, preparation of environmental covariates, overlaying soil data and covariates, fitting a model for the spatial interpolation and validation:
1. Soil data preparation
- **Option A**: Data preparation - Soil profiles (Code \@ref(cd:PreparationProfiles))
- **Option B**: Data preparation - Topsoil or auger samples (Code \@ref(cd:PreparationAuger))
- *[optional]* Data preparation - Merging topsoil or auger samples and soil profiles (Code \@ref(cd:merging))
- *[optional]* Split the soil data in test and validations datasets (Code \@ref(cd:data-splitting))
2. Covariates preparation
- *[optional]* Rasterizing a vector layer in **R** (Code \@ref(cd:Rasterizing))
- Overlay covariates and soil points data (Code \@ref(cd:Overlay))
3. Spatial interpolation model
- **Option A**: Fitting a regression-kriging model to predict the SOC stock (Code \@ref(cd:RK))
- **Option B**: Fitting a random forest model to predict the SOC stock (Code \@ref(cd:rf))
- **Option C**: Fitting a support vector machines model to predict the SOC stock (Code \@ref(cd:svm))
4. Validation
- Quality measures for quantitative data (Code \@ref(cd:Validation))
- *[optional]* Graphical quality measures for quantitative data (Code \@ref(cd:Graphs))
- *[optional]* Cross-validation for regression-kriging models (Code \@ref(cd:xvalRK))
- *[optional]* Validation of random forest using quantile regression trees (Code \@ref(cd:quantreg))
5. Model evaluation
- Model evaluation (Code \@ref(cd:Evaluation))
\clearpage
## Data preparation for soil profiles{#cd:PreparationProfiles}
The extended and discussed version of the following code is presented in Chapter \@ref(preparation), by G.F. Olmedo & R. Baritz.
```{r, echo=FALSE, cache=FALSE}
knitr::read_chunk(path = "code/1A-DataPreparation-Profiles.R")
```
```{r 1A-DataPreparation-Profiles, eval=FALSE}
```
\clearpage
## Data preparation for topsoil or auger samples {#cd:PreparationAuger}
The extended and discussed version of the following code is presented in Chapter \@ref(preparation), by G.F. Olmedo & R. Baritz.
```{r, echo=FALSE, cache=FALSE}
knitr::read_chunk(path = "code/1B-DataPreparation-Augers.R")
```
```{r 1B-DataPreparation-Augers, eval=FALSE}
```
\clearpage
## Merging topsoil or auger samples and soil profiles databases{#cd:merging}
```{r, echo=FALSE, cache=FALSE}
knitr::read_chunk(path = "code/optional-Merging.R")
```
```{r optional-Merging, eval=FALSE}
```
\clearpage
## Data-splitting{#cd:data-splitting}
The extended and discussed version of the following code is presented in Chapter \@ref(chvalidation), by B. Kempen, D.J. Brus & G.B.M. Heuvelink, with code contributions from G.F. Olmedo.
```{r, echo=FALSE, cache=FALSE}
knitr::read_chunk(path = "code/optional-DataSplitting.R")
```
```{r optional-DataSplitting, eval=FALSE}
```
\clearpage
## Rasterizing a vector layer in R {#cd:Rasterizing}
The extended and discussed version of the following code is presented in Chapter \@ref(covariates), by R. Baritz & Y. Yigini.
```{r, echo=FALSE, cache=FALSE}
knitr::read_chunk(path = "code/optional-Rasterizing.R")
```
```{r optional-Rasterizing, eval=FALSE}
```
\clearpage
## Overlay covariates and soil points data {#cd:Overlay}
The extended and discussed version of the following code is presented in Chapter \@ref(covariates), by R. Baritz & Y. Yigini.
```{r, echo=FALSE, cache=FALSE}
knitr::read_chunk(path = "code/2-OverlayCovariates.R")
```
```{r 2-OverlayCovariates, eval=FALSE}
```
\clearpage
## Fitting a regression-kriging model to predict the SOC stock {#cd:RK}
The extended and discussed version of the following code is presented in Section \@ref(RK), by G.F. Olmedo & Y. Yigini.
```{r, echo=FALSE, cache=FALSE}
knitr::read_chunk(path = "code/3A-1-RegressionKriging.R")
```
```{r 3A-1-RegressionKriging, eval=FALSE}
```
## Cross-validation of regression-kriging models {#cd:xvalRK}
The extended and discussed version of the following code is presented in Section \@ref(RK), by G.F. Olmedo & Y. Yigini.
```{r, echo=FALSE, cache=FALSE}
knitr::read_chunk(path = "code/3A-2-XvalRegressionKriging.R")
```
```{r 3A-2-XvalRegressionKriging, eval=FALSE}
```
\clearpage
## Fitting a random forest model to predict the SOC stock {#cd:rf}
The extended and discussed version of the following code is presented in Section \@ref(rf), by M. Guevara, C. Thine, G.F. Olmedo & R.R. Vargas.
```{r, echo=FALSE, cache=FALSE}
knitr::read_chunk(path = "code/3B-1-randomForest.R")
```
```{r 3B-1-randomForest, eval=FALSE}
```
\clearpage
## Using quantile regression forest to estimate uncertainty {#cd:quantreg}
The extended and discussed version of the following code is presented in Section \@ref(rf), by M. Guevara, C. Thine, G.F. Olmedo & R.R. Vargas.
```{r, echo=FALSE, cache=FALSE}
knitr::read_chunk(path = "code/3B-2-QuantileRegressionForest.R")
```
```{r 3B-2-QuantileRegressionForest, eval=FALSE}
```
\clearpage
## Fitting a support vector machines model to predict the SOC stock {#cd:svm}
The extended and discussed version of the following code is presented in Section \@ref(svm), by G.F. Olmedo & M. Guevara.
```{r, echo=FALSE, cache=FALSE}
knitr::read_chunk(path = "code/3C-SupportVectorMachines.R")
```
```{r 3C-SupportVectorMachines, eval=FALSE}
```
\clearpage
## Validation {#cd:Validation}
The extended and discussed version of the following code is presented in Chapter \@ref(chvalidation), by B. Kempen, D.J. Brus & G.B.M. Heuvelink, with code contributions from G.F. Olmedo.
```{r, echo=FALSE, cache=FALSE}
knitr::read_chunk(path = "code/4-1-Validation.R")
```
```{r 4-1-Validation, eval=FALSE}
```
\clearpage
## Graphical map quality measures {#cd:Graphs}
The extended and discussed version of the following code is presented in Chapter \@ref(chvalidation), by B. Kempen, D.J. Brus & G.B.M. Heuvelink, with code contributions from G.F. Olmedo.
```{r, echo=FALSE, cache=FALSE}
knitr::read_chunk(path = "code/4-2-GraphicalQualityMeasures.R")
```
```{r 4-2-GraphicalQualityMeasures, eval=FALSE}
```
\clearpage
## Model evaluation {#cd:Evaluation}
The extended and discussed version of the following code is presented in Chapter \@ref(evaluation), by M. Guevara and G.F. Olmedo.
```{r, echo=FALSE, cache=FALSE}
knitr::read_chunk(path = "code/5-ModelEvaluation.R")
```
```{r 5-ModelEvaluation, eval=FALSE}
```
`r if (knitr:::is_html_output()) '# References {-}'`