# mlr3spatiotempcv Package website: [release](https://mlr3spatiotempcv.mlr-org.com/) \| [dev](https://mlr3spatiotempcv.mlr-org.com/dev/) Spatiotemporal resampling methods for mlr3. This package extends the [mlr3](https://github.com/mlr-org/mlr3) package framework with spatiotemporal resampling and visualization methods. If you prefer the [tidymodels](https://www.tidymodels.org/) ecosystem, have a look at the [{spatialsample}](https://spatialsample.tidymodels.org/index.html) package for spatial sampling methods. ## Installation CRAN version ``` r install.packages("mlr3spatiotempcv") ``` Development version ``` r remotes::install_github("mlr-org/mlr3spatiotempcv") # R Universe Repo install.packages('mlr3spatiotempcv', mlrorg = 'https://mlr-org.r-universe.dev') ``` ## Get Started See the [“Get Started”](https://mlr3spatiotempcv.mlr-org.com/articles/mlr3spatiotempcv.html) vignette for a quick introduction. For more detailed information including an usage example see the [“Spatiotemporal Analysis”](https://mlr3book.mlr-org.com/chapters/chapter13/beyond_regression_and_classification.html#sec-spatiotemporal) chapter in the mlr3book. Article [“Spatiotemporal Visualization”](https://mlr3spatiotempcv.mlr-org.com/articles/spatiotemp-viz.html) shows how 3D subplots grids can be created. ## Citation To cite the package in publications, use the output of `citation("mlr3spatiotempcv")`. ## Resources - [Recorded talk about mlr3spatiotempcv and mlr3spatial at OpenDataScience Europe Conference 2021 in Wageningen, NL](https://www.youtube.com/watch?v=lWOMsmeWfEo) - [List of scientific articles related to spatiotemporal modeling and/or spatial partitioning](https://pat-s.notion.site/Spatial-autocorrelation-in-modeling-b62e1bc904b546b9a489b171913a3551) # Other spatiotemporal resampling packages This list does not claim to be comprehensive. (Disclaimer: Because CRAN does not like DOI URLs in their automated checks, direct linking to scientific articles is not possible…) | Name | Language | Resources | |---------------|----------|-----------------------------------------------------------------------------------------------------------------| | blockCV | R | [CRAN](https://cran.r-project.org/package=blockCV) | | CAST | R | [Paper](https://doi.org/10.1016/j.envsoft.2017.12.001), [CRAN](https://cran.r-project.org/package=CAST) | | ENMeval | R | [CRAN](https://cran.r-project.org/package=ENMeval) | | spatialsample | R | [CRAN](https://cran.r-project.org/package=spatialsample) | | sperrorest | R | [CRAN](https://cran.r-project.org/package=sperrorest) | | Pyspatialml | Python | [GitHub](https://github.com/stevenpawley/Pyspatialml) | | spacv | Python | [GitHub](https://github.com/SamComber/spacv) | | Museo Toolbox | Python | [Paper](https://joss.theoj.org/papers/10.21105/joss.01978), [GitHub](https://github.com/nkarasiak/MuseoToolBox) | | spatial-kfold | Python | [GitHub](https://github.com/WalidGharianiEAGLE/spatial-kfold) | # FAQ Which resampling method should I use? There is no single-best resampling method. It depends on your dataset characteristics and what your model should is about to predict on. The resampling scheme should reflect the final purpose of the model - this concept is called “target-oriented” resampling. For example, if the model was trained on multiple forest plots and its purpose is to predict something on unknown forest stands, the resampling structure should reflect this. Are there more resampling methods than the one {mlr3spatiotempcv} offers? {mlr3spatiotempcv} aims to offer all resampling methods that exist in R. Though this does not mean that it covers all resampling methods. If there are some that you are missing, feel free to open an issue. How can I use the “blocking” concept of the old {mlr}? This concept is now supported via the “column roles” concept available in {mlr3} [Task](https://mlr3.mlr-org.com/reference/Task.html) objects. See [this documentation](https://mlr3.mlr-org.com/reference/Resampling.html#grouping-blocking) for more information. For the methods that offer buffering, how can an appropriate value be chosen? There is no easy answer to this question. Buffering train and test sets reduces the similarity between both. The degree of this reduction depends on the dataset itself and there is no general approach how to choosen an appropriate buffer size. Some studies used the distance at which the autocorrelation levels off. This buffer distance often removes quite a lot of observations and needs to be calculated first. # Package index ## mlr3spatiotempcv - [`mlr3spatiotempcv`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr3spatiotempcv-package.md) [`mlr3spatiotempcv-package`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr3spatiotempcv-package.md) : mlr3spatiotempcv: Spatiotemporal Resampling Methods for 'mlr3' ## Spatiotemporal Blocking Methods These methods use square/rectangular blocks for partitioning. - [`mlr_resamplings_spcv_block`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_spcv_block.md) [`ResamplingSpCVBlock`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_spcv_block.md) : (blockCV) Spatial block resampling - [`mlr_resamplings_repeated_spcv_block`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_repeated_spcv_block.md) [`ResamplingRepeatedSpCVBlock`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_repeated_spcv_block.md) : (blockCV) Repeated spatial block resampling - [`mlr_resamplings_spcv_tiles`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_spcv_tiles.md) [`ResamplingSpCVTiles`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_spcv_tiles.md) : (sperrorest) Spatial "Tiles" resampling - [`mlr_resamplings_repeated_spcv_tiles`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_repeated_spcv_tiles.md) [`ResamplingRepeatedSpCVTiles`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_repeated_spcv_tiles.md) : (sperrorest) Repeated spatial "tiles" resampling ## Spatiotemporal Buffering Methods These methods support using buffering zones which eventually remove observations between train and test sets. - [`mlr_resamplings_spcv_buffer`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_spcv_buffer.md) [`ResamplingSpCVBuffer`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_spcv_buffer.md) : (blockCV) Spatial buffering resampling - [`mlr_resamplings_spcv_disc`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_spcv_disc.md) [`ResamplingSpCVDisc`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_spcv_disc.md) : (sperrorest) Spatial "disc" resampling - [`mlr_resamplings_repeated_spcv_disc`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_repeated_spcv_disc.md) [`ResamplingRepeatedSpCVDisc`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_repeated_spcv_disc.md) : (sperrorest) Repeated spatial "disc" resampling - [`mlr_resamplings_sptcv_cstf`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_sptcv_cstf.md) [`ResamplingSptCVCstf`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_sptcv_cstf.md) : (CAST) Spatiotemporal "Leave-location-and-time-out" resampling - [`mlr_resamplings_repeated_sptcv_cstf`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_repeated_sptcv_cstf.md) [`ResamplingRepeatedSptCVCstf`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_repeated_sptcv_cstf.md) : (CAST) Repeated spatiotemporal "leave-location-and-time-out" resampling ## Spatiotemporal Clustering Methods These methods make use of clustering methods (e.g. `k-means`) to create (equally-sized) partitions. - [`mlr_resamplings_spcv_coords`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_spcv_coords.md) [`ResamplingSpCVCoords`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_spcv_coords.md) : (sperrorest) Coordinate-based k-means clustering - [`mlr_resamplings_repeated_spcv_coords`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_repeated_spcv_coords.md) [`ResamplingRepeatedSpCVCoords`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_repeated_spcv_coords.md) : (sperrorest) Repeated coordinate-based k-means clustering - [`mlr_resamplings_spcv_disc`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_spcv_disc.md) [`ResamplingSpCVDisc`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_spcv_disc.md) : (sperrorest) Spatial "disc" resampling - [`mlr_resamplings_repeated_spcv_disc`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_repeated_spcv_disc.md) [`ResamplingRepeatedSpCVDisc`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_repeated_spcv_disc.md) : (sperrorest) Repeated spatial "disc" resampling - [`mlr_resamplings_spcv_knndm`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_spcv_knndm.md) [`ResamplingSpCVKnndm`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_spcv_knndm.md) : (CAST) K-fold Nearest Neighbour Distance Matching - [`mlr_resamplings_repeated_spcv_knndm`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_repeated_spcv_knndm.md) [`ResamplingRepeatedSpCVKnndm`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_repeated_spcv_knndm.md) : (CAST) Repeated K-fold Nearest Neighbour Distance Matching ## Feature Space Clustering Methods These methods cluster in the feature space and not (necessarily) in space or time. - [`mlr_resamplings_spcv_env`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_spcv_env.md) [`ResamplingSpCVEnv`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_spcv_env.md) : (blockCV) "Environmental blocking" resampling - [`mlr_resamplings_repeated_spcv_env`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_repeated_spcv_env.md) [`ResamplingRepeatedSpCVEnv`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_repeated_spcv_env.md) : (blockCV) Repeated "environmental blocking" resampling ## Group-level Partitioning Methods These methods use (multiple) factor-variables / inherited grouping to create partitions. - [`mlr_resamplings_sptcv_cstf`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_sptcv_cstf.md) [`ResamplingSptCVCstf`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_sptcv_cstf.md) : (CAST) Spatiotemporal "Leave-location-and-time-out" resampling - [`mlr_resamplings_repeated_sptcv_cstf`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_repeated_sptcv_cstf.md) [`ResamplingRepeatedSptCVCstf`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_resamplings_repeated_sptcv_cstf.md) : (CAST) Repeated spatiotemporal "leave-location-and-time-out" resampling ## Spatiotemporal Tasks Classification and regression tasks. - [`TaskRegrST`](https://mlr3spatiotempcv.mlr-org.com/reference/TaskRegrST.md) : Create a Spatiotemporal Regression Task - [`as_task_regr_st()`](https://mlr3spatiotempcv.mlr-org.com/reference/as_task_regr_st.md) : Convert to a Spatiotemporal Regression Task - [`TaskClassifST`](https://mlr3spatiotempcv.mlr-org.com/reference/TaskClassifST.md) : Create a Spatiotemporal Classification Task - [`as_task_classif_st()`](https://mlr3spatiotempcv.mlr-org.com/reference/as_task_classif_st.md) : Convert to a Spatiotemporal Classification Task ## Spatiotemporal Example Datasets Tasks appended to the `mlr_tasks` dictionary. - [`cookfarm_mlr3`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_tasks_cookfarm_mlr3.md) : Cookfarm Profiles Regression Task - [`diplodia`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_tasks_diplodia.md) : Diplodia Classification Task - [`ecuador`](https://mlr3spatiotempcv.mlr-org.com/reference/mlr_tasks_ecuador.md) : Ecuador Classification Task ## Visualization of spatiotemporal partitions - [`autoplot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingCV.md) [`autoplot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingCV.md) [`plot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingCV.md) [`plot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingCV.md) : Visualization Functions for Non-Spatial CV Methods. - [`autoplot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingCustomCV.md) [`plot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingCustomCV.md) : Visualization Functions for Non-Spatial CV Methods. - [`autoplot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVBlock.md) [`autoplot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVBlock.md) [`plot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVBlock.md) [`plot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVBlock.md) : Visualization Functions for SpCV Block Methods. - [`autoplot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVBuffer.md) [`plot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVBuffer.md) : Visualization Functions for SpCV Buffer Methods. - [`autoplot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVCoords.md) [`autoplot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVCoords.md) [`plot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVCoords.md) [`plot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVCoords.md) : Visualization Functions for SpCV Coords Methods. - [`autoplot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVDisc.md) [`autoplot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVDisc.md) [`plot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVDisc.md) [`plot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVDisc.md) : Visualization Functions for SpCV Disc Method. - [`autoplot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVEnv.md) [`autoplot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVEnv.md) [`plot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVEnv.md) [`plot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVEnv.md) : Visualization Functions for SpCV Env Methods. - [`autoplot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVKnndm.md) [`autoplot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVKnndm.md) [`plot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVKnndm.md) [`plot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVKnndm.md) : Visualization Functions for SpCV knndm Method. - [`autoplot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVTiles.md) [`autoplot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVTiles.md) [`plot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVTiles.md) [`plot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSpCVTiles.md) : Visualization Functions for SpCV Tiles Method. - [`autoplot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSptCVCstf.md) [`autoplot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSptCVCstf.md) [`plot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSptCVCstf.md) [`plot(`*``*`)`](https://mlr3spatiotempcv.mlr-org.com/reference/autoplot.ResamplingSptCVCstf.md) : Visualization Functions for SptCV Cstf Methods. # Articles ### All vignettes - [Getting Started](https://mlr3spatiotempcv.mlr-org.com/articles/mlr3spatiotempcv.md): - [Spatiotemporal Visualization](https://mlr3spatiotempcv.mlr-org.com/articles/spatiotemp-viz.md):