Skip to content

Commit

Permalink
modelSize() works for ranger models
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam B. Smith committed Oct 2, 2024
1 parent 87e18e3 commit 83d0c29
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 8 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
^\.Rproj\.user$
^\.github
^\.github$
^enmSdmX_workspace.code-workspace
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: enmSdmX
Type: Package
Title: Species Distribution Modeling and Ecological Niche Modeling
Version: 1.1.7
Date: 2024-08-02
Version: 1.1.8
Date: 2024-10-02
Authors@R:
c(
person(
Expand Down Expand Up @@ -57,7 +57,7 @@ Imports:
LazyData: true
LazyLoad: yes
URL: https://github.com/adamlilith/enmSdmX
BugReports: https://github.com/adamlilith/enmSdmX
BugReports: https://github.com/adamlilith/enmSdmX/issues
Encoding: UTF-8
License: MIT + file LICENSE
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# enmSdmX 1.1.8 2024-10-02
- `modelSize()` can now tell size of a `ranger` random forest.

# enmSdmX 1.1.7 2024-08-02
- Clarified mis-leading help in several functions, including all the `trainXYZ()` functions (thank you, PT!).

Expand Down
11 changes: 10 additions & 1 deletion R/modelSize.r
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ modelSize <- function(
NA
warning('Cannot determine number of presences and background sites for a MaxNet model.')

# random forest in ranger package
} else if (inherits(x, 'ranger')) {

as.numeric(x$predictions)

# random forest in party package
} else if (inherits(x, 'randomForest')) {

Expand All @@ -83,7 +88,11 @@ modelSize <- function(
stop('Cannot extract sample size from model object.')
}
} else if (binary) {
out <- c(sum(samples == 1), sum(samples == 0))
out <- if (inherits(x, 'ranger')) {
c(sum(samples == 1), sum(samples == 2))
} else {
c(sum(samples == 1), sum(samples == 0))
}
names(out) <- c('num1s', 'num0s')
if (out[1L] == 0 & out[2L] == 0) warning('Model does not seem to be using a binary response.', .immediate=TRUE)
} else {
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# enmSdmX
<!-- badges: start -->

[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![cran version](https://www.r-pkg.org/badges/version/enmSdmX)](https://cran.r-project.org/package=enmSdmX)
![R](https://img.shields.io/badge/r-%23276DC3.svg?style=for-the-badge&logo=r&logoColor=white) [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) [![cran version](https://www.r-pkg.org/badges/version/enmSdmX)](https://cran.r-project.org/package=enmSdmX) [![R-CMD-check](https://github.com/adamlilith/fasterRaster/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/adamlilith/fasterRaster/actions/workflows/R-CMD-check.yaml)

<!-- badges: end -->

<strong>Tools for modeling niches and distributions of species </strong>
Expand Down
29 changes: 29 additions & 0 deletions enmSdmX_workspace.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"folders": [
{
"path": "."
}
],
"settings": {
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#1f6fd0",
"activityBar.background": "#1f6fd0",
"activityBar.foreground": "#e7e7e7",
"activityBar.inactiveForeground": "#e7e7e799",
"activityBarBadge.background": "#ee90bb",
"activityBarBadge.foreground": "#15202b",
"commandCenter.border": "#e7e7e799",
"sash.hoverBorder": "#1f6fd0",
"statusBar.background": "#1857a4",
"statusBar.foreground": "#e7e7e7",
"statusBarItem.hoverBackground": "#1f6fd0",
"statusBarItem.remoteBackground": "#1857a4",
"statusBarItem.remoteForeground": "#e7e7e7",
"titleBar.activeBackground": "#1857a4",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveBackground": "#1857a499",
"titleBar.inactiveForeground": "#e7e7e799"
},
"peacock.color": "#1857a4"
}
}
2 changes: 1 addition & 1 deletion man/enmSdmX.Rd

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

0 comments on commit 83d0c29

Please sign in to comment.