Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nowosad committed Oct 19, 2024
2 parents eb02a6f + fdd0472 commit 04eacc2
Show file tree
Hide file tree
Showing 29 changed files with 146 additions and 147 deletions.
4 changes: 2 additions & 2 deletions 02-spatial-data.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -821,14 +821,14 @@ library(tmap)
tm1 = tm_shape(india_buffer_with_s2) +
tm_fill(fill = hcl.colors(4, palette = "purple green")[2], lwd = 0.01) +
tm_shape(india) +
tm_fill(fill = "grey95") +
tm_fill(fill = "gray95") +
tm_title("st_buffer() with dist = 1") +
tm_title("s2 switched on (default)", position = tm_pos_in("right", "bottom"), size = 1)
tm2 = tm_shape(india_buffer_without_s2) +
tm_fill(fill = hcl.colors(4, palette = "purple green")[3], lwd = 0.01) +
tm_shape(india) +
tm_fill(fill = "grey95") +
tm_fill(fill = "gray95") +
tm_title(" ") +
tm_title("s2 switched off", position = tm_pos_in("right", "bottom"), size = 1)
Expand Down
2 changes: 1 addition & 1 deletion 04-spatial-operations.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ tm_shape(grid_sf) +
tm_fill(fill = c("queens", "rooks"),
fill.scale = tm_scale(values = c("white", "black"))) +
tm_shape(grid_sf) +
tm_borders(col = "grey", lwd = 2) +
tm_borders(col = "gray", lwd = 2) +
tm_layout(frame = FALSE, legend.show = FALSE,
panel.labels = c("queen", "rook"))
```
Expand Down
14 changes: 6 additions & 8 deletions 09-mapping.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -1012,9 +1012,9 @@ Building on this basic example and knowing where to find help (see `?shiny`), th
The recommended next step is to open the previously mentioned [`CycleHireApp/app.R`](https://github.com/geocompx/geocompr/blob/main/apps/CycleHireApp/app.R) script in an integrated development environment (IDE) of choice, modify it and re-run it repeatedly.
The example contains some of the components of a web mapping application implemented in **shiny** and should 'shine' a light on how they behave.

The `CycleHireApp/app.R` script contains **shiny** functions that go beyond those demonstrated in the simple 'lifeApp' example (Figure \@ref(fig:CycleHireApp-html)).
These include `reactive()` and `observe()` (for creating outputs that respond to the user interface --- see `?reactive`) and `leafletProxy()` (for modifying a `leaflet` object that has already been created).
Such elements are critical to the creation of web mapping applications implemented in **shiny**.
The `CycleHireApp/app.R` script contains **shiny** functions that go beyond those demonstrated in the simple 'lifeApp' example, deployed at [shiny.robinlovelace.net/CycleHireApp](https://shiny.robinlovelace.net/CycleHireApp).
These include `reactive()` and `observe()`, (for creating outputs that respond to the user interface, see `?reactive`) and `leafletProxy()` (for modifying a `leaflet` object that has already been created).
Such elements enable web mapping applications implemented in **shiny** [@lovelace_propensity_2017].
A range of 'events' can be programmed including advanced functionality such as drawing new layers or subsetting data, as described in the shiny section of RStudio's **leaflet** [website](https://rstudio.github.io/leaflet/shiny.html).

```{block2 shinynote, type='rmdnote'}
Expand All @@ -1040,11 +1040,9 @@ For that reason, despite advocating **shiny**, we recommend starting with the lo
This way your prototype web applications should be limited not by technical considerations, but by your motivations and imagination.

```{r CycleHireApp-html, echo=FALSE, message=FALSE, fig.cap="CycleHireApp, a simple web mapping application for finding the closest cycle hiring station based on your location and requirement of cycles. Interactive version available online at: r.geocompx.org.",fig.scap="Cycle Hire App, a simple web mapping application.", eval=knitr::is_html_output(), out.width="690"}
knitr::include_app("https://shiny.robinlovelace.net/CycleHireApp/")
```

```{r CycleHireApp-latex, echo=FALSE, message=FALSE, fig.cap="CycleHireApp, a simple web mapping application for finding the closest cycle hiring station based on your location and requirement of cycles. Interactive version available online at r.geocompx.org.", fig.scap="coffeeApp, a simple web mapping application.", eval=knitr::is_latex_output()}
knitr::include_graphics("images/09_cycle_hire_app.png")
if (knitr::is_html_output()){
knitr::include_url("https://shiny.robinlovelace.net/CycleHireApp/")
}
```

## Other mapping packages
Expand Down
4 changes: 2 additions & 2 deletions 10-gis.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ aggzone_wgs = st_transform(aggregating_zones, "EPSG:4326")
#| results: hide
library(tmap)
tm_shape(incongr_wgs) +
tm_polygons(col = "grey5") +
tm_polygons(col = "gray5") +
tm_shape(aggzone_wgs) +
tm_borders(col_alpha = 0.5, col = "red") +
tm_add_legend(type = "lines", labels = c("incongr_wgs", "aggzone_wgs"),
col = c("grey5", "red"), lwd = 3, position = tm_pos_in("right", "top")) +
col = c("gray5", "red"), lwd = 3, position = tm_pos_in("right", "top")) +
tm_scalebar(position = c("left", "bottom"), breaks = c(0, 0.5, 1)) +
tm_layout(frame = FALSE, legend.text.size = 1,
inner.margins = c(0.02, 0.02, 0.03, 0.02))
Expand Down
8 changes: 4 additions & 4 deletions 12-spatial-cv.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ library(lgr) # logging framework for R
library(mlr3) # unified interface to machine learning algorithms
library(mlr3learners) # most important machine learning algorithms
library(mlr3extralearners) # access to even more learning algorithms
library(mlr3proba) # make probabilistic predictions, here only needed for mlr3extralearners::list_learners()
library(mlr3proba) # here needed for mlr3extralearners::list_learners()
library(mlr3spatiotempcv) # spatiotemporal resampling strategies
library(mlr3tuning) # hyperparameter tuning
library(mlr3viz) # plotting functions for mlr3 objects
Expand Down Expand Up @@ -214,7 +214,7 @@ However, it is possible to include spatial autocorrelation\index{autocorrelation
Though, this is beyond the scope of this book, we give the interested reader some pointers where to look it up:

1. The predictions of regression kriging combines the predictions of a regression with the kriging of the regression's residuals [@goovaerts_geostatistics_1997; @hengl_practical_2007; @bivand_applied_2013].
2. One can also add a spatial correlation (dependency) structure to a generalized least squares model (`nlme::gls()`; @zuur_mixed_2009; @zuur_beginners_2017).
2. One can also add a spatial correlation (dependency) structure to a generalized least squares model [`nlme::gls()`, @zuur_mixed_2009; @zuur_beginners_2017].
3. One can also use mixed-effect modeling approaches.
Basically, a random effect imposes a dependency structure on the response variable which in turn allows for observations of one class to be more similar to each other than to those of another class [@zuur_mixed_2009].
Classes can be, for example, bee hives, owl nests, vegetation transects or an altitudinal stratification.
Expand Down Expand Up @@ -444,7 +444,7 @@ mean(score_spcv_glm$classif.auc) |>
round(2)
```

To put these results in perspective, let us compare them with AUROC\index{AUROC} values from a 100-repeated 5-fold non-spatial cross-validation (Figure \@ref(fig:boxplot-cv); the code for the non-spatial cross-validation\index{cross-validation} is not shown here but will be explored in the exercise section).
To put these results in perspective, let us compare them with AUROC\index{AUROC} values from a 100-repeated 5-fold non-spatial cross-validation (Figure \@ref(fig:boxplot-cv); the code for the non-spatial cross-validation\index{cross-validation} is not shown here but will be explored in the Exercise section).
As expected (see Section \@ref(intro-cv)), the spatially cross-validated result yields lower AUROC values on average than the conventional cross-validation approach, underlining the over-optimistic predictive performance of the latter due to its spatial autocorrelation\index{autocorrelation!spatial}.

```{r boxplot-cv, echo=FALSE, message=FALSE, out.width="75%", fig.cap="Boxplot showing the difference in GLM AUROC values on spatial and conventional 100-repeated 5-fold cross-validation.", fig.scap="Boxplot showing AUROC values."}
Expand Down Expand Up @@ -625,7 +625,7 @@ score_spcv_svm = dplyr::filter(score, learner_id == "classif.ksvm.tuned",
resampling_id == "repeated_spcv_coords")
```

Let us have a look at the final AUROC\index{AUROC}: the model's ability to discriminate the two classes.
Let's have a look at the final AUROC\index{AUROC}: the model's ability to discriminate the two classes.

```{r 12-spatial-cv-33}
# final mean AUROC
Expand Down
Loading

0 comments on commit 04eacc2

Please sign in to comment.