Description Usage Arguments Author(s) Examples
View source: R/extractFromPrediction.R
Extrac objects from lists returned by function mopaPredict
.
1 | extractFromPrediction(predictions, value)
|
predictions |
Listed lists of objects (e.g. as returned by |
value |
Character pointing to the name of component/s in the list |
M. Iturbide
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | # 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))
})
names(newClim) <- names(biostack$future)[1:4]
prdRS.fut <- mopaPredict(models = mods, newClim = newClim)
names(newClim)
## Extract predictions for climate projection CNRM
predsMPI <- extractFromPrediction(predictions = prdRS.fut, value = "CNRM")
spplot(predsMPI)
# 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)
## Extract predictions for species climate projection MPI
predsMPI <- extractFromPrediction(predictions = preds, value = "MPI")
spplot(predsMPI)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.