Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc fixes #55

Merged
merged 14 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/R-CMD-check-ubuntu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/documentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 5 additions & 11 deletions R/fit_xgb_occupancy_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand All @@ -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)
})
Expand Down
40 changes: 25 additions & 15 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -103,35 +110,36 @@ 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 %>%
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
Expand All @@ -141,18 +149,20 @@ 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) %>%
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).
Expand Down Expand Up @@ -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
Expand All @@ -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).
Expand Down
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -72,8 +72,8 @@ They can be installed using the following system commands:

#### Linux

For Unix-alikes, `gmp` (&gt;= 4.2.3), `mpfr` (&gt;= 3.0.0), `fftw3`
(&gt;= 3.3), and `symphony` (&gt;= 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

Expand Down Expand Up @@ -181,21 +181,21 @@ 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))
```

<img src="man/figures/README-management_cost_plot-1.png" style="display: block; margin: auto;" />
<img src="man/figures/README-management_cost_plot-1.png" width="350" style="display: block; margin: auto;" />

``` r
# 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))
```

<img src="man/figures/README-survey_cost_plot-1.png" style="display: block; margin: auto;" />
<img src="man/figures/README-survey_cost_plot-1.png" width="350" style="display: block; margin: auto;" />

``` r
# plot survey data
Expand All @@ -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))
```

<img src="man/figures/README-n_plot-1.png" style="display: block; margin: auto;" />
<img src="man/figures/README-n_plot-1.png" width="800" style="display: block; margin: auto;" />

``` r
# plot survey results
Expand All @@ -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))
```

<img src="man/figures/README-f_plot-1.png" style="display: block; margin: auto;" />
<img src="man/figures/README-f_plot-1.png" width="800" style="display: block; margin: auto;" />

``` r
# plot modeled probability of occupancy data
Expand All @@ -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))
```

<img src="man/figures/README-p_plot-1.png" style="display: block; margin: auto;" />
<img src="man/figures/README-p_plot-1.png" width="800" style="display: block; margin: auto;" />

Next, we will load the `sim_features` object. This table contains
information on the conservation features (e.g. species). Specifically,
Expand Down Expand Up @@ -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))
```

<img src="man/figures/README-survey_scheme_plot-1.png" style="display: block; margin: auto;" />
<img src="man/figures/README-survey_scheme_plot-1.png" width="350" style="display: block; margin: auto;" />

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
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ authors:
href: https://josephrbennett.wordpress.com

template:
bootstrap: 5
params:
bootswatch: flatly

Expand Down
6 changes: 3 additions & 3 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -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,

Expand All @@ -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)
Expand Down
Loading
Loading