View source: R/predictPotential.R
predictPotential | R Documentation |
Computes predicted values of the potential niches of species from the fitted trophicSDMfit model at environmental conditions specified by Xnew
. Predictions are obtained by setting preys to present when mode = "prey" or setting predators to absent when mode = "predator".
predictPotential(
tSDM,
Xnew = NULL,
pred_samples = NULL,
verbose = FALSE,
fullPost = TRUE
)
tSDM |
A trophicSDMfit object obtained with trophicSDM() |
Xnew |
a matrix specifying the environmental covariates for the predictions to be made. If NULL (default), predictions are done on the training dataset (e.g. by setting Xnew = tSDM$data$X). |
pred_samples |
Number of samples to draw from species posterior predictive distribution when method = "stan_glm". If NULL, set by the default to the number of iterations/10. |
verbose |
Whether to print advances of the algorithm. |
fullPost |
Optional parameter for stan_glm only. Whether to give back the full posterior predictive distribution (default, fullPost = TRUE) or just the posterior mean, and 2.5% and 97.5% quantiles. |
A list containing for each species the predicted value at each sites. If method = "stan_glm", then each element of the list is a sites x pred_samples matrix containing the posterior predictive distribution of the species at each sites.
Giovanni Poggiato and Jérémy Andréoletti
data(Y, X, G)
# define abiotic part of the model
env.formula = "~ X_1 + X_2"
# Run the model with bottom-up control using stan_glm as fitting method and no penalisation
# (set iter = 1000 to obtain reliable results)
m = trophicSDM(Y, X, G, env.formula, iter = 100,
family = binomial(link = "logit"), penal = NULL,
mode = "prey", method = "stan_glm")
# Obtain 100 draws from the posterior predictive distribution of species potential niche
# (pred_samples = 50)
# Since we don't specify Xnew, the function sets Xnew = X by default
Ypred = predictPotential(m, fullPost = TRUE, pred_samples = 50)
# We can ask the function to only give back posterior mean and 95% credible intervals with
# fullPost = FALSE
Ypred = predictPotential(m, fullPost = FALSE, pred_samples = 50)
#' We can now evaluate species probabilities of presence for the enviromental
# conditions c(0.5, 0.5)
predictPotential(m, Xnew = data.frame(X_1 = 0.5, X_2 = 0.5), pred_samples = 50)
# If we fit the model using in a frequentist way (e.g. glm)
m = trophicSDM(Y, X, G, env.formula,
family = binomial(link = "logit"), penal = NULL,
mode = "prey", method = "glm")
# We are obliged to set pred_samples = 1
# (this is done by default if pred_samples is not provided)
# In the frequentist case, fullPost is useless.
Ypred = predictPotential(m, pred_samples = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.