knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.align = "center") options(knitr.table.format = "html")
default_model <- SDMtune:::bm_maxent
In the previous article you have learned how to prepare the data for the analysis using the virtualSp dataset and the WorldClim environmental variables. Now it's time to train your first model, let's do it!
SDMtune
supports four methods for model training:
nnet
package [@Venables2002];gbm
package [@Greenwell2019];dismo
package [@Hijmans2017];maxnet
package [@Phillips2017b];randomForest
package [@Liaw2002].The code necessary to train a model is the same for all the implementations. We will show how to train a Maxent model, you can adapt the code for the other methods or check this article.
First we load the SDMtune package:
library(SDMtune)
We use the function train()
to train a Maxent model. We need to provide two arguments:
method
: "Maxent" in our case;data
: the SWD()
object with the presence and background locations that we created in the previous article.default_model <- SDMtune:::bm_maxent
default_model <- train(method = "Maxent", data = data)
The function trains the model using default settings that are:
We will see later how to change the default settings, for the moment let's have a look at the default_model
object.
The output of the function train()
is an object of class SDMmodel()
. Let's print it:
default_model
When we print an SDMmodel
object we get the following information:
An SDMmodel()
object has two slots:
slotNames(default_model)
SWD()
object with the presence absence/background locations used to train the model;Maxent()
object, in our case, with all the model configurations.The slot model
contains the configurations of the model plus other information used to make predictions.
slotNames(default_model@model)
For the moment the most important are: fc, reg and iter that contain the values of the model configuration. We will explore the others later in another article.
The function train()
accepts optional arguments that can be used to change the default model settings. In our previous example we could have trained the same model using:
default_model <- train(method = "Maxent", data = data, fc = "lqph", reg = 1, iter = 500)
Try to change the default settings and train a model using linear and hinge as feature class combination, 0.5 as regularization multiplier and 700 iterations. To see the solution highlight the next cell:
model <- train(method = "Maxent", data = data, fc = "lh", reg = 0.5, iter = 700)
By default Maxent models are trained using the arguments "removeduplicates=false" and "addsamplestobackground=false". The user should have the full control of the data used to train the model, so is expected that duplicated locations are already removed and that the presence locations are already included in the background locations, when desired. You can use the function thinData()
to remove duplicated locations and the function addSamplesToBg()
to add the presence locations to the background locations.
Train a model using the Maxnet method is as simple as changing the name of the method in the train()
function, the only difference here is that we cannot set the number of iteration.
Try to train a model using the Maxnet method. To see the solution highlight the following cell:
maxnet_model <- train("Maxnet", data = data)
In this article you have learned:
SDMmodel()
object;In the next article you will learn how to use the model that you have just trained to get the predicted value for new localities.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.