diff --git a/.github/workflows/R-CMD-check-ubuntu.yaml b/.github/workflows/R-CMD-check-ubuntu.yaml index 7d76849..96debc5 100644 --- a/.github/workflows/R-CMD-check-ubuntu.yaml +++ b/.github/workflows/R-CMD-check-ubuntu.yaml @@ -24,8 +24,8 @@ jobs: fail-fast: false matrix: config: - - {os: ubuntu-20.04, r: 'release'} - - {os: ubuntu-20.04, r: 'devel'} + - {os: ubuntu-22.04, r: 'release'} + - {os: ubuntu-22.04, r: 'devel'} env: _R_REMOTES_NO_ERRORS_FROM_WARNINGS_: true @@ -56,7 +56,8 @@ jobs: - name: Install system dependencies run: | - sudo apt-get install libnlopt-dev coinor-libsymphony-dev + sudo apt-get -y install \ + libnlopt-dev coinor-libsymphony-dev - uses: r-lib/actions/setup-r-dependencies@v2 with: diff --git a/.github/workflows/documentation.yaml b/.github/workflows/documentation.yaml index a0185ea..5c54636 100644 --- a/.github/workflows/documentation.yaml +++ b/.github/workflows/documentation.yaml @@ -92,8 +92,9 @@ jobs: - name: Check URLs if: runner.os == 'Linux' && matrix.config.r == 'release' run: | + d <- suppressWarnings(readLines("inst/URLLIST")) result <- urlchecker::url_check() - result <- result[!startsWith(result$URL, "https://doi.org/"), , drop = FALSE] + result <- result[!result$URL %in% d, , drop = FALSE] if (nrow(result) > 0) { print(result) stop("Invalid URLs detected") diff --git a/DESCRIPTION b/DESCRIPTION index 75375c1..dd3764d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: surveyvoi Type: Package -Version: 1.1.0.1 +Version: 1.1.0.2 Title: Survey Value of Information Description: Decision support tool for prioritizing sites for ecological surveys based on their potential to improve plans for conserving @@ -35,7 +35,7 @@ Imports: parallel, progress (>= 1.2.2), assertthat (>= 0.2.0), - xgboost (>= 1.5.2.1), + xgboost (>= 1.7.8.1), plyr (>= 1.8.4), withr (>= 2.1.2), tibble (>= 2.1.3), @@ -84,7 +84,7 @@ SystemRequirements: URL: https://prioritizr.github.io/surveyvoi/ BugReports: https://github.com/prioritizr/surveyvoi/issues VignetteBuilder: knitr -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Encoding: UTF-8 Biarch: true Collate: diff --git a/NEWS.md b/NEWS.md index 1208336..ecc2e8e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# surveyvoi 1.1.0.2 + +- Fix bug in `fit_xgb_occupancy_models()` that caused an error during model + fitting due to failed predictions. +- Fix package citation. + # surveyvoi 1.1.0.1 - Fix bug in `greedy_heuristic_algorithm()` function so that it returns a diff --git a/R/fit_xgb_occupancy_models.R b/R/fit_xgb_occupancy_models.R index 63d9fa5..14d38ae 100644 --- a/R/fit_xgb_occupancy_models.R +++ b/R/fit_xgb_occupancy_models.R @@ -399,12 +399,10 @@ fit_xgb_occupancy_models <- function( ## make predictions p_train_k <- c(withr::with_package("xgboost", stats::predict( - m_k, xgboost::xgb.DMatrix(x_train_k, nthread = n_threads), - iterationrange = c(1, nround_k + 1)))) + m_k, xgboost::xgb.DMatrix(x_train_k, nthread = n_threads)))) p_test_k <- c(withr::with_package("xgboost", stats::predict( - m_k, xgboost::xgb.DMatrix(x_test_k, nthread = n_threads), - iterationrange = c(1, nround_k + 1)))) + m_k, xgboost::xgb.DMatrix(x_test_k, nthread = n_threads)))) ## validate predictions assertthat::assert_that(all(p_train_k >= 0), all(p_train_k <= 1), msg = "xgboost predictions are not between zero and one") @@ -449,8 +447,7 @@ fit_xgb_occupancy_models <- function( function(x) { ## generate predictions out <- c(withr::with_package("xgboost", stats::predict( - x, xgboost::xgb.DMatrix(site_env_data, nthread = n_threads), - iterationrange = c(1, x$best_iteration + 1) + x, xgboost::xgb.DMatrix(site_env_data, nthread = n_threads) ))) ## validate predictions assertthat::assert_that( @@ -556,10 +553,7 @@ tune_model <- function(data, folds, survey_sensitivity, survey_specificity, }) ### generate predictions yhat_test <- c(withr::with_package("xgboost", - stats::predict( - model, dtest[[k]], - iterationrange = c(1, model$best_iteration + 1) - ))) + stats::predict(model, dtest[[k]]))) ### validate predictions assertthat::assert_that(all(yhat_test >= 0), all(yhat_test <= 1), msg = "xgboost predictions are not between zero and one") @@ -568,7 +562,7 @@ tune_model <- function(data, folds, survey_sensitivity, survey_specificity, data[[k]]$test$y, yhat_test, data[[k]]$test$w, survey_sensitivity, survey_specificity)[[1]] ## check that model evaluations are consistent - assertthat::assert_that(abs(perf - model$best_score) < 1e-5) + assertthat::assert_that(abs(perf - model$best_score) < 1e-2) ### return result list(eval = perf, model = model) }) diff --git a/README.Rmd b/README.Rmd index 91a1840..92f48ba 100644 --- a/README.Rmd +++ b/README.Rmd @@ -23,9 +23,16 @@ knitr::opts_chunk$set(fig.path = "man/figures/README-", fig.align = "center") ```{r "initialization", include = FALSE} devtools::load_all() -h = 2.75 -w = 3.0 -ow = "400" +h = 3.5 +w = 5.0 +ow = "350" +knitr::opts_chunk$set( + fig.height = h, + fig.width = w, + out.width = ow, + fig.path = "man/figures/README-", + fig.align = "center" +) ``` The _surveyvoi_ package is a decision support tool for prioritizing sites for ecological surveys based on their potential to improve plans for conserving biodiversity (e.g. plans for establishing protected areas). Given a set of sites that could potentially be acquired for conservation management -- wherein some sites have previously been surveyed and other sites have not -- this package provides functionality to generate and evaluate plans for additional surveys. Specifically, plans for ecological surveys can be generated using various conventional approaches (e.g. maximizing expected species richness, geographic coverage, diversity of sampled environmental conditions) and by maximizing value of information. After generating plans for surveys, they can also be evaluated using value of information analysis. Please note that several functions depend on the Gurobi optimization software (available from https://www.gurobi.com). Additionally, the JAGS software (available from https://mcmc-jags.sourceforge.io/) is required to fit hierarchical generalized linear models. @@ -103,24 +110,24 @@ data(sim_sites) # print table print(sim_sites, width = Inf) -```{r "management_cost_plot", fig.height = h, fig.width = w} +```{r "management_cost_plot"} # plot cost of protecting each site ggplot(sim_sites) + geom_sf(aes(color = management_cost), size = 4) + ggtitle("management_cost") + -theme(legend.title = element_blank()) +theme(legend.title = element_blank(), text = element_text(size = 16)) ``` -```{r "survey_cost_plot", fig.height = h, fig.width = w} +```{r "survey_cost_plot"} # plot cost of conducting an additional survey in each site # note that these costs are much lower than the protection costs ggplot(sim_sites) + geom_sf(aes(color = survey_cost), size = 4) + ggtitle("survey_cost") + -theme(legend.title = element_blank()) +theme(legend.title = element_blank(), text = element_text(size = 16)) ``` -```{r "n_plot", fig.height = h, fig.width = w * 2.25} +```{r "n_plot", fig.height = h, fig.width = w * 2.4, out.width = "800"} # plot survey data ## n1, n2, n3: number of surveys in each site that looked for each feature sim_sites %>% @@ -128,10 +135,11 @@ select(n1, n2, n3) %>% gather(name, value, -geometry) %>% ggplot() + geom_sf(aes(color = value), size = 4) + -facet_wrap(~name, nrow = 1) +facet_wrap(~name, nrow = 1) + +theme(text = element_text(size = 16)) ``` -```{r "f_plot", fig.height = h, fig.width = w * 2.25} +```{r "f_plot", fig.height = h, fig.width = w * 2.4, out.width = "800"} # plot survey results ## f1, f2, f3: proportion of surveys in each site that looked for each feature ## that detected the feature @@ -141,10 +149,11 @@ gather(name, value, -geometry) %>% ggplot() + geom_sf(aes(color = value), size = 4) + facet_wrap(~name, nrow = 1) + -scale_color_continuous(limits = c(0, 1)) +scale_color_continuous(limits = c(0, 1)) + +theme(text = element_text(size = 16)) ``` -```{r "p_plot", fig.height = h, fig.width = w * 2.25} +```{r "p_plot", fig.height = h, fig.width = w * 2.4, out.width = "800"} # plot modeled probability of occupancy data sim_sites %>% select(p1, p2, p3) %>% @@ -152,7 +161,8 @@ gather(name, value, -geometry) %>% ggplot() + geom_sf(aes(color = value), size = 4) + facet_wrap(~name, nrow = 1) + -scale_color_continuous(limits = c(0, 1)) +scale_color_continuous(limits = c(0, 1)) + +theme(text = element_text(size = 16)) ``` Next, we will load the `sim_features` object. This table contains information on the conservation features (e.g. species). Specifically, each row corresponds to a different feature, and each column contains information associated with the features. In this table, the `"name"` column contains the name of each feature; `"survey"` column indicates whether future surveys would look for this species; `"survey_sensitivity"` and `"survey_specificity"` columns denote the sensitivity (true positive rate) and specificity (true negative rate) for the survey methodology for correctly detecting the feature; `"model_sensitivity"` and `"model_specificity"` columns denote the sensitivity (true positive rate) and specificity (true negative rate) for the species distribution models fitted for each feature; and `"target"` column denotes the required number of protected sites for each feature (termed "representation target", each feature has a target of `r sim_features$target[1]` site). @@ -203,7 +213,7 @@ assertthat::assert_that( ) ``` -```{r "survey_scheme_plot", fig.height = h, fig.width = w * 1.5} +```{r "survey_scheme_plot"} # the opt_scheme object is a matrix that contains the survey schemes # each column corresponds to a different site, # and each row corresponds to a different solution @@ -220,7 +230,7 @@ sim_sites$scheme <- c(opt_scheme[1, ]) ggplot(sim_sites) + geom_sf(aes(color = scheme), size = 4) + ggtitle("scheme") + -theme(legend.title = element_blank()) +theme(text = element_text(size = 16)) ``` This has just been a taster of the _surveyvoi R_ package. In addition to this functionality, it can be used to evaluate survey schemes using value of information analysis. Furthermore, it can be used to generate survey schemes using conventional approaches (e.g. sampling environmental gradients, and selecting places with highly uncertain information). For more information, see the [package vignette](https://prioritizr.github.io/surveyvoi/articles/surveyvoi.html). diff --git a/README.md b/README.md index 2c6437d..1390417 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ [![Documentation](https://img.shields.io/github/actions/workflow/status/prioritizr/surveyvoi/documentation.yaml?branch=master&label=Documentation)](https://github.com/prioritizr/surveyvoi/actions) [![Coverage Status](https://img.shields.io/codecov/c/github/prioritizr/surveyvoi?label=Coverage)](https://app.codecov.io/gh/prioritizr/surveyvoi/branch/master) -[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/surveyvoi)](https://CRAN.R-project.org/package=surveyvoi) +[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/surveyvoi)](https://CRAN.R-project.org/package=surveyvoi) The *surveyvoi* package is a decision support tool for prioritizing sites for ecological surveys based on their potential to improve plans @@ -72,8 +72,8 @@ They can be installed using the following system commands: #### Linux -For Unix-alikes, `gmp` (>= 4.2.3), `mpfr` (>= 3.0.0), `fftw3` -(>= 3.3), and `symphony` (>= 5.6.16) are required. +For Unix-alikes, `gmp` (\>= 4.2.3), `mpfr` (\>= 3.0.0), `fftw3` (\>= +3.3), and `symphony` (\>= 5.6.16) are required. #### macOS @@ -181,10 +181,10 @@ print(sim_sites, width = Inf) ggplot(sim_sites) + geom_sf(aes(color = management_cost), size = 4) + ggtitle("management_cost") + -theme(legend.title = element_blank()) +theme(legend.title = element_blank(), text = element_text(size = 16)) ``` - + ``` r # plot cost of conducting an additional survey in each site @@ -192,10 +192,10 @@ theme(legend.title = element_blank()) ggplot(sim_sites) + geom_sf(aes(color = survey_cost), size = 4) + ggtitle("survey_cost") + -theme(legend.title = element_blank()) +theme(legend.title = element_blank(), text = element_text(size = 16)) ``` - + ``` r # plot survey data @@ -205,10 +205,11 @@ select(n1, n2, n3) %>% gather(name, value, -geometry) %>% ggplot() + geom_sf(aes(color = value), size = 4) + -facet_wrap(~name, nrow = 1) +facet_wrap(~name, nrow = 1) + +theme(text = element_text(size = 16)) ``` - + ``` r # plot survey results @@ -220,10 +221,11 @@ gather(name, value, -geometry) %>% ggplot() + geom_sf(aes(color = value), size = 4) + facet_wrap(~name, nrow = 1) + -scale_color_continuous(limits = c(0, 1)) +scale_color_continuous(limits = c(0, 1)) + +theme(text = element_text(size = 16)) ``` - + ``` r # plot modeled probability of occupancy data @@ -233,10 +235,11 @@ gather(name, value, -geometry) %>% ggplot() + geom_sf(aes(color = value), size = 4) + facet_wrap(~name, nrow = 1) + -scale_color_continuous(limits = c(0, 1)) +scale_color_continuous(limits = c(0, 1)) + +theme(text = element_text(size = 16)) ``` - + Next, we will load the `sim_features` object. This table contains information on the conservation features (e.g. species). Specifically, @@ -345,10 +348,10 @@ sim_sites$scheme <- c(opt_scheme[1, ]) ggplot(sim_sites) + geom_sf(aes(color = scheme), size = 4) + ggtitle("scheme") + -theme(legend.title = element_blank()) +theme(text = element_text(size = 16)) ``` - + This has just been a taster of the *surveyvoi R* package. In addition to this functionality, it can be used to evaluate survey schemes using diff --git a/_pkgdown.yml b/_pkgdown.yml index d011202..ab9c1a6 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -11,6 +11,7 @@ authors: href: https://josephrbennett.wordpress.com template: + bootstrap: 5 params: bootswatch: flatly diff --git a/cran-comments.md b/cran-comments.md index 8bc25b7..381b350 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,6 +1,6 @@ Dear CRAN volunteers, -Thank you for reviewing this submission. This submission contains updates for the _surveyvoi_ package to fix (i) aliasing for the package manual entry, (ii) uneeded C++11 specification, and (iii) installation for Windows on arm64 systems. +Thank you for reviewing this submission. This submission contains minor updates for the _surveyvoi_ package to (i) improve algorithmic performance, (ii) fix a typo in the citation, and (iii) improve compatibility with updates to dependencies. Cheers, @@ -10,8 +10,8 @@ Jeff * [Debian (testing), R-release](https://github.com/r-devel/rcheckserver) ([based on rcheckserver](https://statmath.wu.ac.at/AASC/debian/)) * [Fedora 33, clang, R-devel](https://github.com/prioritizr/surveyvoi/actions?query=workflow%3AFedora) -* [Ubuntu 20.04, R-release](https://github.com/prioritizr/surveyvoi/actions?query=workflow%3AUbuntu) -* [Ubuntu 20.04, R-devel](https://github.com/prioritizr/surveyvoi/actions?query=workflow%3AUbuntu) +* [Ubuntu 22.04, R-release](https://github.com/prioritizr/surveyvoi/actions?query=workflow%3AUbuntu) +* [Ubuntu 22.04, R-devel](https://github.com/prioritizr/surveyvoi/actions?query=workflow%3AUbuntu) * [macOS 10.15, R-release](https://github.com/prioritizr/surveyvoi/actions?query=workflow%3A%22Mac+OSX%22) * [macOS 11.5.2 (arm64), R-release (macOS builder)](https://mac.r-project.org/macbuilder/submit.html) * [Windows Server 2019, R-release](https://github.com/prioritizr/surveyvoi/actions?query=workflow%3AWindows) diff --git a/docs/404.html b/docs/404.html index d39d55b..99faee4 100644 --- a/docs/404.html +++ b/docs/404.html @@ -4,103 +4,73 @@ - +