Skip to content

Commit

Permalink
Merge pull request #42 from adamlilith/solstice_2022_2023
Browse files Browse the repository at this point in the history
Add `trainESM()`
  • Loading branch information
adamlilith authored Apr 10, 2024
2 parents 746ecf8 + ca0c835 commit ba20b1e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
4 changes: 3 additions & 1 deletion R/trainESM.r
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ trainESM <- function(

}

list(models = models, tuning = tuning)
out <- list(models = models, tuning = tuning)
if (is.na(scale) || scale) out$scale <- scales
out

}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ You may need to install the `remotes` package first.
### Model training ###
* `trainByCrossValid` and `summaryByCrossValid`: Calibrate a distribution/niche model using cross-validation
* `trainBRT`: Boosted regression trees (BRTs)
* `trainESM`: Ensembles of small models (ESM)
* `trainESM`: Ensembles of small models (ESMs)
* `trainGAM`: Generalized additive models (GAMs)
* `trainGLM`: Generalized linear models (GLMs)
* `trainMaxEnt`: MaxEnt models
Expand Down
24 changes: 22 additions & 2 deletions man/examples/trainESM_examples.r
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# designed to work fast, not produce accurate, defensible models. They can
# take a few minutes to run.

library(mgcv)
library(sf)
library(terra)
set.seed(123)

Expand Down Expand Up @@ -79,3 +77,25 @@ esm2 <- trainESM(

str(esm2, 1)
esm2$tuning

### make a set of predictions to rasters
########################################

# center environmental rasters and divide by their SD
madClimScaled <- scale(madClim, center = esm2$scale$mean, scale = esm2$scale$sd)

# make one raster per model
predictions <- list()
for (i in 1:length(esm2$models)) {
predictions[[i]] <- predict(madClimScaled, esm2$models[[i]], type = 'response')
}

# combine into a "stack"
predictions <- do.call(c, predictions)
names(predictions) <- esm2$tuning$model
plot(predictions)

# calculate (unweighted) mean
prediction <- mean(predictions)
plot(prediction)
plot(occs, pch = 1, add = TRUE)
24 changes: 22 additions & 2 deletions man/trainESM.Rd

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

0 comments on commit ba20b1e

Please sign in to comment.