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 = 50,
family = binomial(link = "logit"), penal = NULL,
mode = "prey", method = "stan_glm")
# We can now evaluate species probabilities of presence for the environmental conditions c(0.5, 0.5)
predict(m, Xnew = data.frame(X_1 = 0.5, X_2 = 0.5))
# Obtain 50 draws from the posterior predictive distribution of species (pred_samples = 10)
# using predicted presence-absences of species to predict their predators (prob.cov = TRUE)
# Since we don't specify Xnew, the function sets Xnew = X by default
Ypred = predict(m, fullPost = TRUE, pred_samples = 10, prob.cov = FALSE)
# We can ask the function to only give back posterior mean and 95% credible intervals with
# fullPost = F
# \donttest{
Ypred = predict(m, fullPost = TRUE, pred_samples = 30, prob.cov = FALSE)
# }
# 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 = predict(m, pred_samples = 1, prob.cov = FALSE)
Run the code above in your browser using DataLab