Skip to content

Commit

Permalink
Version bump, partial 🔥 fix to gdb and parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Jung committed Jun 8, 2024
1 parent c60a791 commit 3b8f8fb
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 27 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: ibis.iSDM
Type: Package
Title: Modelling framework for integrated biodiversity distribution scenarios
Version: 0.1.3
Version: 0.1.4
Authors@R:
c(person(given = "Martin",
family = "Jung",
Expand Down
14 changes: 11 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# ibis.iSDM 0.1.3 (current dev branch)
# ibis.iSDM 0.1.4 (current dev branch)

#### New features

#### Minor improvements and bug fixes
* :bug: fix to `engine_gdb` also to support non-linear smooth functions (again).
* Small fix to support deprecated `field_occurrence` field in `validate` for convenience.
* :bug: fix that prevented `BART` models to be saved/loaded from disk #127.
* :bug: fixes related to `factor` handling for all engines.

# ibis.iSDM 0.1.3

#### New features
* Add functions that creates HTML file base on `DistributionModel`.
Expand All @@ -15,8 +25,6 @@
* Changed default output for netcdf files to multidimensional arrays #109
* :fire: hot fixes for scenario scaling and normalization issue #113
* :bug: fix so that projection works with different extents than used for inference.
* :bug: fix that prevented `BART` models to be saved/loaded from disk #127.
* :bug: fixes related to `factor` handling for all engines.

# ibis.iSDM 0.1.2

Expand Down
33 changes: 18 additions & 15 deletions R/engine_gdb.R
Original file line number Diff line number Diff line change
Expand Up @@ -631,20 +631,22 @@ engine_gdb <- function(x,
newdata = dummy_temp, which = v,
type = type, aggregate = 'sum'))

# Check duplicates. If bbs is present and non-linear, use bbs estimate
# MH: As far as I see it the pp will always only store the result of the
# current variable due to which = v, so we can just grab the first column
out[[v]] <- data.frame(variable = v, partial_effect = dummy_temp[, v], mean = pp[, 1])

# if(!self$settings$data$only_linear){
# # Combine with
# out[[v]] <- data.frame(variable = v, partial_effect = dummy_temp[, v],
# mean = pp[,grep(paste0("bbs\\(", v,"\\)"), colnames(pp))])
# } else {
# # Combine with
# out[[v]] <- data.frame(variable = v, partial_effect = dummy_temp[, v],
# mean = pp[,grep(v, colnames(pp))])
# }
# If bbs is present and non-linear, use bbs estimate. If model is fitted
# to non-linear then always the linear (bols, fitted by default) and smooth (bbs)
# is stored in bbs. In most cases the linear effect is stable and regularized out
# though.
# Propose to always take non-linear when found in settings
if(!settings$get("only_linear")){
# Combine with
out[[v]] <- data.frame(variable = v, partial_effect = dummy_temp[, v],
mean = pp[, 2] #pp[,grep(paste0("bbs\\(", v,"\\)"), colnames(pp))]
)
} else {
# Combine with
out[[v]] <- data.frame(variable = v, partial_effect = dummy_temp[, v],
mean = pp[, 1] #pp[,grep(v, colnames(pp))]
)
}
}

# bind to one data.frame
Expand All @@ -656,7 +658,8 @@ engine_gdb <- function(x,
ggplot2::theme_classic() +
ggplot2::geom_line(ggplot2::aes(y = mean)) +
ggplot2::facet_wrap(. ~ variable, scales = "free") +
ggplot2::labs(x = "Variable", y = "Partial effect")
ggplot2::labs(x = "Variable",
y = paste0("Partial effect (",ifelse(settings$get("only_linear"),"linear","smooth"),")"))
print(g)
}
return(out)
Expand Down
22 changes: 19 additions & 3 deletions R/validate.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#' @param point A [`sf`] object with type `POINT` or `MULTIPOINT`.
#' @param point_column A [`character`] vector with the name of the column containing
#' the independent observations. (Default: \code{'observed'}).
#' @param field_occurrence (Deprectated) A [`character`] field pointing to the name
#' of the independent observations. Identical to \code{"point_column"}
#' @param ... Other parameters that are passed on. Currently unused.
#'
#' @details The \code{'validate'} function calculates different validation
Expand Down Expand Up @@ -79,14 +81,14 @@ NULL
methods::setGeneric("validate",
signature = methods::signature("mod"),
function(mod, method = 'continuous', layer = "mean",
point = NULL, point_column = 'observed', ...) standardGeneric("validate"))
point = NULL, point_column = 'observed', field_occurrence = NULL, ...) standardGeneric("validate"))

#' @rdname validate
methods::setMethod(
"validate",
methods::signature(mod = "ANY"),
function(mod, method = 'continuous', layer = "mean",
point = NULL, point_column = 'observed', ...){
point = NULL, point_column = 'observed', field_occurrence = NULL,...){
assertthat::assert_that(
inherits(mod, "DistributionModel"),
inherits(point, 'sf') || is.null(point),
Expand All @@ -98,6 +100,11 @@ methods::setMethod(
assertthat::assert_that( "prediction" %in% mod$show_rasters(),msg = "No prediction of the fitted model found!" )
# Check that independent data is provided and if so that the used column is there
if(!is.null(point)){
# Use field occurrence if point column is not found or set
if(!utils::hasName(point, point_column) && !is.null(field_occurrence)){
point_column <- field_occurrence
}

assertthat::assert_that(is.character(point_column),
utils::hasName(point, point_column),
anyNA(point[[point_column]])==FALSE
Expand Down Expand Up @@ -250,7 +257,8 @@ methods::setMethod(
methods::setMethod(
"validate",
methods::signature(mod = "SpatRaster"),
function(mod, method = 'continuous', layer = NULL, point = NULL, point_column = 'observed', ...){
function(mod, method = 'continuous', layer = NULL, point = NULL,
point_column = 'observed', field_occurrence = NULL, ...){
assertthat::assert_that(
is.Raster(mod),
inherits(point, 'sf'),
Expand All @@ -259,6 +267,14 @@ methods::setMethod(
)
method <- match.arg(method, c("discrete", "continuous"),several.ok = FALSE)

# Use field occurrence if point column is not found or set
# Fallback arguement
if(!is.null(point)){
if(!utils::hasName(point, point_column) && !is.null(field_occurrence)){
point_column <- field_occurrence
}
}

# If mode truncate was used, also switch to continuous data
if(method == "discrete"){
# Get parameter if there
Expand Down
8 changes: 8 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Jung, Martin. 2023. “An Integrated Species Distribution Modelling Framework fo

## Contributors


<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
Expand All @@ -82,6 +83,12 @@ All contributions to this project are gratefully acknowledged using the [`allcon
</a><br>
<a href="https://github.com/iiasa/ibis.iSDM/commits?author=mhesselbarth">mhesselbarth</a>
</td>
<td align="center">
<a href="https://github.com/jeffreyhanson">
<img src="https://avatars.githubusercontent.com/u/3610005?v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/iiasa/ibis.iSDM/commits?author=jeffreyhanson">jeffreyhanson</a>
</td>
</tr>

</table>
Expand All @@ -90,3 +97,4 @@ All contributions to this project are gratefully acknowledged using the [`allcon
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->


17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,15 @@ Systems Analysis (IIASA), Austria.

## Contributors


<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->

All contributions to this project are gratefully acknowledged using the
[`allcontributors`
package](https://github.com/ropenscilabs/allcontributors) following the
[all-contributors](https://allcontributors.org) specification.
Contributions of any kind are welcome!
All contributions to this project are gratefully acknowledged using the [`allcontributors` package](https://github.com/ropenscilabs/allcontributors) following the [all-contributors](https://allcontributors.org) specification. Contributions of any kind are welcome!

<table>

<tr>
<td align="center">
<a href="https://github.com/Martin-Jung">
Expand All @@ -92,8 +90,17 @@ Contributions of any kind are welcome!
</a><br>
<a href="https://github.com/iiasa/ibis.iSDM/commits?author=mhesselbarth">mhesselbarth</a>
</td>
<td align="center">
<a href="https://github.com/jeffreyhanson">
<img src="https://avatars.githubusercontent.com/u/3610005?v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/iiasa/ibis.iSDM/commits?author=jeffreyhanson">jeffreyhanson</a>
</td>
</tr>

</table>

<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->

6 changes: 6 additions & 0 deletions man/validate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3b8f8fb

Please sign in to comment.