View source: R/machuruku_code.R
machu.1.tip.resp | R Documentation |
For each taxon, construct a Bioclim species distribution model and estimate a response curve for each climate variable.
machu.1.tip.resp(
occ,
clim,
sp.col = 1,
col.xy = 2:3,
plot = "n",
plot.points = F,
plot.asp = 16/9,
output.bioclim = F,
jitter = F,
verbose = F
)
occ |
Occurrence data for each species, formatted as a dataframe. Each species must have at least 10 points. |
clim |
A single RasterStack of present-day climate data. A SpatRaster object is also acceptable. |
sp.col |
Integer specifying which column of the input occurrence data corresponds to species ID. Default = 1. |
col.xy |
vector specifying long (x) and lat (y) of occurrence data. Default = 2:3. |
plot |
Whether and how to make plots of present-day Bioclim models for each taxon. "separate": plot each model in its own window. "together": plot all models in the same window, arranged dynamically at a given aspect ratio. "n": default (no plot). |
plot.points |
If TRUE, plot each taxon's occurrence data on top of its corresponding niche model. Default = F. |
plot.asp |
Aspect ratio used to calculate the best arrangement of plots when plot="together". Default = 16/9. |
output.bioclim |
If TRUE, output a Bioclim niche model raster for each taxon instead of climate response curves. |
jitter |
If TRUE, slightly jitter climate response values after sampling. Use this to avoid certain errors that arise from low-variability climate responses |
verbose |
If TRUE, print progress updates to the screen. |
This function uses the function dismo::bioclim() to construct present-day Bioclim niche models. It is only compatible with the older Raster package, so a SpatRaster object (from the newer Terra package) will automatically be converted before being passed to the rest of the function.
Unfortunately the constraints of the 'sn::selm()' function disallow any taxa having fewer than 10 occurrence points. To that end, this function contains a utility to randomly sample occurrence points within the minimum convex polygon comprised of the occurrence data for species, up to n=10. When the plotting functionality is activated (i.e. plot="s" or plot="t"), these random points are drawn in red. In this case, the output of the function will be a list that contains the normal output (response table or niche models) as well as the occurrence data table with the newly added random points. Obviously, it is better to have at least 10 real occurrence points; however for rare species, or range-limited species after spatial rarefication, that may be difficult or impossible.
The sn::selm function that is used to construct skew-normal distributions from sampled climate response values sometimes returns errors ("missing value where TRUE/FALSE needed") when the variation in the sampled climate responses is low. A simple workaround is to slightly jitter the climate response values, which introduces enough variation to let selm do its job, while only minimally affecting the result. Use jitter=T to turn this option on.
Table consisting of the response of each species to the climate data. Each response is represented by a skew-normal distribution. Alternatively, the function can output the actual Bioclim niche models.
## acceptable 'clim' formats
# Single RasterStack (raster) (preferred)
clim <- stack(list.files(rasterfolder, pattern="T0_", full.names=T))
# Single SpatRaster (terra)
clim <- c(rast(list.files(rasterfolder, pattern="T0_", full.names=T)))
# basic
response.table <- machu.1.tip.resp(occ, clim)
# plot all plots separately
response.table <- machu.1.tip.resp(occ, clim, plot="s")
# plot all plots together, with points, at an aspect ratio of 16:10 (you have a 1600p screen)
response.table <- machu.1.tip.resp(occ, clim, plot="t", plot.points=T, plot.asp=16/10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.