Learn R Programming

mopa (version 1.0.1)

mopaPredict: Model prediction

Description

Model projection into a RasterStack

Usage

mopaPredict(models, newClim)

Arguments

models

Model class object (e.g. "glm") or list of model class objects, e.g. as returned by function extractFromModel.

newClim

RasterStack or list of RasterStack objects with variables for projecting

Value

RasterStack of the projected probabilities

References

Iturbide, M., Bedia, J., Herrera, S., del Hierro, O., Pinto, M., Gutierrez, J.M., 2015. A framework for species distribution modelling with improved pseudo-absence generation. Ecological Modelling. DOI:10.1016/j.ecolmodel.2015.05.018.

See Also

mopaTrain, extractFromPrediction

Examples

Run this code
# NOT RUN {
# SHORT EXAMPLE
destfile <- tempfile()
data.url <- "https://raw.githubusercontent.com/SantanderMetGroup/mopa/master/data/biostack.rda"
download.file(data.url, destfile)
load(destfile, verbose = TRUE)

## Fitted models
data(mods)
?mods

## Model prediction
newClim <- lapply(1:4, function(x){
crop(biostack$future[[x]], extent(-10, 10, 35, 65))
})

prdRS.fut <- mopaPredict(models = mods, newClim = newClim)

# }
# NOT RUN {
# FULL WORKED EXAMPLE
## Load presence data
data(Oak_phylo2)

## Load climate data
destfile <- tempfile()
data.url <- "https://raw.githubusercontent.com/SantanderMetGroup/mopa/master/data/biostack.rda"
download.file(data.url, destfile)
load(destfile, verbose = TRUE)

## Spatial reference
r <- biostack$baseline[[1]]
## Create background grid
bg <- backgroundGrid(r)

## Generate pseudo-absences
RS_random <-pseudoAbsences(xy = Oak_phylo2, background = bg$xy, 
                           exclusion.buffer = 0.083*5, prevalence = -0.5, kmeans = FALSE)
## Model training
fittedRS <- mopaTrain(y = RS_random, x = biostack$baseline, 
                      k = 10, algorithm = "glm", weighting = TRUE)
## Extract fitted models
mods <- extractFromModel(models = fittedRS, value = "model")

## Model prediction
preds <- mopaPredict(models = mods, newClim = biostack$future)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab