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
# \donttest{
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)
Run the code above in your browser using DataLab