From 7c80f4dc9477450b3992559cb2a7b2d834891e31 Mon Sep 17 00:00:00 2001 From: Jakub Nowosad Date: Wed, 18 Dec 2024 12:59:35 +0100 Subject: [PATCH 1/3] fixes CRAN note (Found the following Rd file(s) with Rd \link{} targets missing package anchors) --- R/CreateSpacetimeFolds.R | 2 +- R/bss.R | 4 ++-- R/errorProfiles.R | 2 +- R/ffs.R | 20 ++++++++++---------- R/global_validation.R | 4 ++-- R/nndm.R | 2 +- man/CreateSpacetimeFolds.Rd | 2 +- man/bss.Rd | 4 ++-- man/errorProfiles.Rd | 2 +- man/ffs.Rd | 20 ++++++++++---------- man/global_validation.Rd | 4 ++-- man/nndm.Rd | 2 +- 12 files changed, 34 insertions(+), 34 deletions(-) diff --git a/R/CreateSpacetimeFolds.R b/R/CreateSpacetimeFolds.R index f2bde996..0bff7485 100644 --- a/R/CreateSpacetimeFolds.R +++ b/R/CreateSpacetimeFolds.R @@ -22,7 +22,7 @@ #' should be similar in each fold (class="LUC"). #' @note Standard k-fold cross-validation can lead to considerable misinterpretation in spatial-temporal modelling tasks. This function can be used to prepare a Leave-Location-Out, Leave-Time-Out or Leave-Location-and-Time-Out cross-validation as target-oriented validation strategies for spatial-temporal prediction tasks. See Meyer et al. (2018) for further information. #' @author Hanna Meyer -#' @seealso \code{\link{trainControl}},\code{\link{ffs}}, \code{\link{nndm}} +#' @seealso \code{\link[caret]{trainControl}},\code{\link{ffs}}, \code{\link{nndm}} #' @references #' Meyer, H., Reudenbach, C., Hengl, T., Katurji, M., Nauß, T. (2018): Improving performance of spatio-temporal machine learning models using forward feature selection and target-oriented validation. Environmental Modelling & Software 101: 1-9. #' @examples diff --git a/R/bss.R b/R/bss.R index 49a54dd9..6f379b6d 100644 --- a/R/bss.R +++ b/R/bss.R @@ -33,8 +33,8 @@ #' Note that bss is very slow since all combinations of variables are tested. #' A more time efficient alternative is the forward feature selection (\code{\link{ffs}}). #' @author Hanna Meyer -#' @seealso \code{\link{train}},\code{\link{ffs}}, -#' \code{\link{trainControl}},\code{\link{CreateSpacetimeFolds}}, +#' @seealso \code{\link[caret]{train}},\code{\link{ffs}}, +#' \code{\link[caret]{trainControl}},\code{\link{CreateSpacetimeFolds}}, #' \code{\link{nndm}} #' @examples #' \dontrun{ diff --git a/R/errorProfiles.R b/R/errorProfiles.R index 0dbef855..cb3ec5e8 100644 --- a/R/errorProfiles.R +++ b/R/errorProfiles.R @@ -5,7 +5,7 @@ #' @param locations Optional. sf object for the training data used in model. Only used if variable=="geodist". Note that they must be in the same order as model$trainingData. #' @param variable Character. Which dissimilarity or distance measure to use for the error metric. Current options are "DI" or "LPD" #' @param multiCV Logical. Re-run model fitting and validation with different CV strategies. See details. -#' @param window.size Numeric. Size of the moving window. See \code{\link{rollapply}}. +#' @param window.size Numeric. Size of the moving window. See \code{\link[zoo]{rollapply}}. #' @param calib Character. Function to model the DI/LPD~performance relationship. Currently lm and scam are supported #' @param length.out Numeric. Only used if multiCV=TRUE. Number of cross-validation folds. See details. #' @param method Character. Method used for distance calculation. Currently euclidean distance (L2) and Mahalanobis distance (MD) are implemented but only L2 is tested. Note that MD takes considerably longer. See ?aoa for further explanation diff --git a/R/ffs.R b/R/ffs.R index c53250ef..d7c20167 100644 --- a/R/ffs.R +++ b/R/ffs.R @@ -1,18 +1,18 @@ #' Forward feature selection #' @description A simple forward feature selection algorithm -#' @param predictors see \code{\link{train}} -#' @param response see \code{\link{train}} -#' @param method see \code{\link{train}} -#' @param metric see \code{\link{train}} -#' @param maximize see \code{\link{train}} +#' @param predictors see \code{\link[caret]{train}} +#' @param response see \code{\link[caret]{train}} +#' @param method see \code{\link[caret]{train}} +#' @param metric see \code{\link[caret]{train}} +#' @param maximize see \code{\link[caret]{train}} #' @param globalval Logical. Should models be evaluated based on 'global' performance? See \code{\link{global_validation}} #' @param withinSE Logical Models are only selected if they are better than the #' currently best models Standard error #' @param minVar Numeric. Number of variables to combine for the first selection. #' See Details. -#' @param trControl see \code{\link{train}} -#' @param tuneLength see \code{\link{train}} -#' @param tuneGrid see \code{\link{train}} +#' @param trControl see \code{\link[caret]{train}} +#' @param tuneLength see \code{\link[caret]{train}} +#' @param tuneGrid see \code{\link[caret]{train}} #' @param seed A random number used for model training #' @param cores Numeric. If > 2, mclapply will be used. see \code{\link{mclapply}} #' @param verbose Logical. Should information about the progress be printed? @@ -53,8 +53,8 @@ #' See Meyer et al. (2018) and Meyer et al. (2019) for further details. #' #' @author Hanna Meyer -#' @seealso \code{\link{train}},\code{\link{bss}}, -#' \code{\link{trainControl}},\code{\link{CreateSpacetimeFolds}},\code{\link{nndm}} +#' @seealso \code{\link[caret]{train}},\code{\link{bss}}, +#' \code{\link[caret]{trainControl}},\code{\link{CreateSpacetimeFolds}},\code{\link{nndm}} #' @references #' \itemize{ #' \item Gasch, C.K., Hengl, T., Gräler, B., Meyer, H., Magney, T., Brown, D.J. (2015): Spatio-temporal interpolation of soil water, temperature, and electrical conductivity in 3D+T: the Cook Agronomy Farm data set. Spatial Statistics 14: 70-90. diff --git a/R/global_validation.R b/R/global_validation.R index e9e64d31..6a409c64 100644 --- a/R/global_validation.R +++ b/R/global_validation.R @@ -1,7 +1,7 @@ #' Evaluate 'global' cross-validation #' @description Calculate validation metric using all held back predictions at once -#' @param model an object of class \code{\link{train}} -#' @return regression (\code{\link{postResample}}) or classification (\code{\link{confusionMatrix}}) statistics +#' @param model an object of class \code{\link[caret]{train}} +#' @return regression (\code{\link[caret]{postResample}}) or classification (\code{\link[caret]{confusionMatrix}}) statistics #' @details Relevant when folds are not representative for the entire area of interest. #' In this case, metrics like R2 are not meaningful since it doesn't reflect the general ability of #' the model to explain the entire gradient of the response. diff --git a/R/nndm.R b/R/nndm.R index d53a5473..881cb143 100644 --- a/R/nndm.R +++ b/R/nndm.R @@ -23,7 +23,7 @@ #' (distances for G function construction during LOO CV), Gjstar (distances #' for modified G function during NNDM LOO CV), phi (landscape autocorrelation range). #' indx_train and indx_test can directly be used as "index" and "indexOut" in -#' caret's \code{\link{trainControl}} function or used to initiate a custom validation strategy in mlr3. +#' caret's \code{\link[caret]{trainControl}} function or used to initiate a custom validation strategy in mlr3. #' #' @details NNDM proposes a LOO CV scheme such that the nearest neighbour distance distribution function between the test and training data during the CV process is matched to the nearest neighbour #' distance distribution function between the prediction and training points. Details of the method can be found in Milà et al. (2022). diff --git a/man/CreateSpacetimeFolds.Rd b/man/CreateSpacetimeFolds.Rd index 24cebca3..220eb7d8 100644 --- a/man/CreateSpacetimeFolds.Rd +++ b/man/CreateSpacetimeFolds.Rd @@ -69,7 +69,7 @@ str(indices) Meyer, H., Reudenbach, C., Hengl, T., Katurji, M., Nauß, T. (2018): Improving performance of spatio-temporal machine learning models using forward feature selection and target-oriented validation. Environmental Modelling & Software 101: 1-9. } \seealso{ -\code{\link{trainControl}},\code{\link{ffs}}, \code{\link{nndm}} +\code{\link[caret]{trainControl}},\code{\link{ffs}}, \code{\link{nndm}} } \author{ Hanna Meyer diff --git a/man/bss.Rd b/man/bss.Rd index ae844200..a9f4e10c 100644 --- a/man/bss.Rd +++ b/man/bss.Rd @@ -80,8 +80,8 @@ plot(bssmodel) } } \seealso{ -\code{\link{train}},\code{\link{ffs}}, -\code{\link{trainControl}},\code{\link{CreateSpacetimeFolds}}, +\code{\link[caret]{train}},\code{\link{ffs}}, +\code{\link[caret]{trainControl}},\code{\link{CreateSpacetimeFolds}}, \code{\link{nndm}} } \author{ diff --git a/man/errorProfiles.Rd b/man/errorProfiles.Rd index 99b8c752..fbf1fce5 100644 --- a/man/errorProfiles.Rd +++ b/man/errorProfiles.Rd @@ -33,7 +33,7 @@ errorProfiles( \item{length.out}{Numeric. Only used if multiCV=TRUE. Number of cross-validation folds. See details.} -\item{window.size}{Numeric. Size of the moving window. See \code{\link{rollapply}}.} +\item{window.size}{Numeric. Size of the moving window. See \code{\link[zoo]{rollapply}}.} \item{calib}{Character. Function to model the DI/LPD~performance relationship. Currently lm and scam are supported} diff --git a/man/ffs.Rd b/man/ffs.Rd index dc894944..a5284e22 100755 --- a/man/ffs.Rd +++ b/man/ffs.Rd @@ -23,15 +23,15 @@ ffs( ) } \arguments{ -\item{predictors}{see \code{\link{train}}} +\item{predictors}{see \code{\link[caret]{train}}} -\item{response}{see \code{\link{train}}} +\item{response}{see \code{\link[caret]{train}}} -\item{method}{see \code{\link{train}}} +\item{method}{see \code{\link[caret]{train}}} -\item{metric}{see \code{\link{train}}} +\item{metric}{see \code{\link[caret]{train}}} -\item{maximize}{see \code{\link{train}}} +\item{maximize}{see \code{\link[caret]{train}}} \item{globalval}{Logical. Should models be evaluated based on 'global' performance? See \code{\link{global_validation}}} @@ -41,11 +41,11 @@ currently best models Standard error} \item{minVar}{Numeric. Number of variables to combine for the first selection. See Details.} -\item{trControl}{see \code{\link{train}}} +\item{trControl}{see \code{\link[caret]{train}}} -\item{tuneLength}{see \code{\link{train}}} +\item{tuneLength}{see \code{\link[caret]{train}}} -\item{tuneGrid}{see \code{\link{train}}} +\item{tuneGrid}{see \code{\link[caret]{train}}} \item{seed}{A random number used for model training} @@ -181,8 +181,8 @@ ffsmodel <- ffs(predictors = splotdata[,6:16], } } \seealso{ -\code{\link{train}},\code{\link{bss}}, -\code{\link{trainControl}},\code{\link{CreateSpacetimeFolds}},\code{\link{nndm}} +\code{\link[caret]{train}},\code{\link{bss}}, +\code{\link[caret]{trainControl}},\code{\link{CreateSpacetimeFolds}},\code{\link{nndm}} } \author{ Hanna Meyer diff --git a/man/global_validation.Rd b/man/global_validation.Rd index 41d14f60..32b452a9 100644 --- a/man/global_validation.Rd +++ b/man/global_validation.Rd @@ -7,10 +7,10 @@ global_validation(model) } \arguments{ -\item{model}{an object of class \code{\link{train}}} +\item{model}{an object of class \code{\link[caret]{train}}} } \value{ -regression (\code{\link{postResample}}) or classification (\code{\link{confusionMatrix}}) statistics +regression (\code{\link[caret]{postResample}}) or classification (\code{\link[caret]{confusionMatrix}}) statistics } \description{ Calculate validation metric using all held back predictions at once diff --git a/man/nndm.Rd b/man/nndm.Rd index b368fbd7..45946fde 100644 --- a/man/nndm.Rd +++ b/man/nndm.Rd @@ -45,7 +45,7 @@ G function construction between prediction and target points), Gj (distances for G function construction during LOO CV), Gjstar (distances for modified G function during NNDM LOO CV), phi (landscape autocorrelation range). indx_train and indx_test can directly be used as "index" and "indexOut" in -caret's \code{\link{trainControl}} function or used to initiate a custom validation strategy in mlr3. +caret's \code{\link[caret]{trainControl}} function or used to initiate a custom validation strategy in mlr3. } \description{ This function implements the NNDM algorithm and returns the necessary indices to perform a NNDM LOO CV for map validation. From 9846aefad4584c70e2a7bb73c0bdf71f4400730e Mon Sep 17 00:00:00 2001 From: Jakub Nowosad Date: Wed, 18 Dec 2024 13:20:52 +0100 Subject: [PATCH 2/3] adds both tmap3 and tmap4 code --- vignettes/cast01-CAST-intro.Rmd | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/vignettes/cast01-CAST-intro.Rmd b/vignettes/cast01-CAST-intro.Rmd index efbce0c2..f1a09970 100644 --- a/vignettes/cast01-CAST-intro.Rmd +++ b/vignettes/cast01-CAST-intro.Rmd @@ -253,14 +253,24 @@ Still it is required to analyse if the model can be applied to the entire study ```{r, message = FALSE, warning=FALSE} ### AOA for which the spatial CV error applies: AOA <- aoa(predictors_sp,ffsmodel,LPD = TRUE,verbose=FALSE) -tm_shape(prediction) + - tm_raster(col.scale = tm_scale_continuous(values = "-viridis"), - col.legend = tm_legend(title = "Species \nrichness")) + - tm_shape(AOA$AOA) + - tm_raster(col.scale = tm_scale_categorical(values = c("grey", "#00000000")), - col.legend = tm_legend(show = FALSE)) + - tm_layout(frame = FALSE) + - tm_add_legend(type="polygons", fill = "grey", labels = "Outside \nAOA") + +# tmap3 +tm_shape(prediction)+ + tm_raster(title="Species \nrichness",style="cont")+ + tm_shape(AOA$AOA)+ + tm_raster(palette=c("1"=NA,"0"="grey"),style="cat",legend.show = FALSE)+ + tm_layout(frame=FALSE,legend.outside = TRUE)+ + tm_add_legend(type="fill",col="grey",border.lwd=0, labels="Outside \nAOA") + +# tmap4 +# tm_shape(prediction) + +# tm_raster(col.scale = tm_scale_continuous(values = "-viridis"), +# col.legend = tm_legend(title = "Species \nrichness")) + +# tm_shape(AOA$AOA) + +# tm_raster(col.scale = tm_scale_categorical(values = c("grey", "#00000000")), +# col.legend = tm_legend(show = FALSE)) + +# tm_layout(frame = FALSE) + +# tm_add_legend(type="polygons", fill = "grey", labels = "Outside \nAOA") ``` The figure shows in grey areas that are outside the area of applicability, hence predictions should not be considered for these locations. See tutorial on the AOA in this package for more information. From 007602321895e6368522ba7ed636cfd08d2a8f48 Mon Sep 17 00:00:00 2001 From: Jakub Nowosad Date: Wed, 18 Dec 2024 15:43:08 +0100 Subject: [PATCH 3/3] adds missing anchors --- R/bss.R | 16 ++++++++-------- man/bss.Rd | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/R/bss.R b/R/bss.R index 6f379b6d..0e812bf8 100644 --- a/R/bss.R +++ b/R/bss.R @@ -1,14 +1,14 @@ #' Best subset feature selection #' @description Evaluate all combinations of predictors during model training -#' @param predictors see \code{\link{train}} -#' @param response see \code{\link{train}} -#' @param method see \code{\link{train}} -#' @param metric see \code{\link{train}} -#' @param maximize see \code{\link{train}} +#' @param predictors see \code{\link[caret]{train}} +#' @param response see \code{\link[caret]{train}} +#' @param method see \code{\link[caret]{train}} +#' @param metric see \code{\link[caret]{train}} +#' @param maximize see \code{\link[caret]{train}} #' @param globalval Logical. Should models be evaluated based on 'global' performance? See \code{\link{global_validation}} -#' @param trControl see \code{\link{train}} -#' @param tuneLength see \code{\link{train}} -#' @param tuneGrid see \code{\link{train}} +#' @param trControl see \code{\link[caret]{train}} +#' @param tuneLength see \code{\link[caret]{train}} +#' @param tuneGrid see \code{\link[caret]{train}} #' @param seed A random number #' @param verbose Logical. Should information about the progress be printed? #' @param ... arguments passed to the classification or regression routine diff --git a/man/bss.Rd b/man/bss.Rd index a9f4e10c..150b78aa 100644 --- a/man/bss.Rd +++ b/man/bss.Rd @@ -20,23 +20,23 @@ bss( ) } \arguments{ -\item{predictors}{see \code{\link{train}}} +\item{predictors}{see \code{\link[caret]{train}}} -\item{response}{see \code{\link{train}}} +\item{response}{see \code{\link[caret]{train}}} -\item{method}{see \code{\link{train}}} +\item{method}{see \code{\link[caret]{train}}} -\item{metric}{see \code{\link{train}}} +\item{metric}{see \code{\link[caret]{train}}} -\item{maximize}{see \code{\link{train}}} +\item{maximize}{see \code{\link[caret]{train}}} \item{globalval}{Logical. Should models be evaluated based on 'global' performance? See \code{\link{global_validation}}} -\item{trControl}{see \code{\link{train}}} +\item{trControl}{see \code{\link[caret]{train}}} -\item{tuneLength}{see \code{\link{train}}} +\item{tuneLength}{see \code{\link[caret]{train}}} -\item{tuneGrid}{see \code{\link{train}}} +\item{tuneGrid}{see \code{\link[caret]{train}}} \item{seed}{A random number}