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
# Increase the number of iterations to obtain reliable results.
m = trophicSDM(Y,X,G, env.formula, iter = 50,
family = binomial(link = "logit"), penal = NULL,
mode = "prey", method = "stan_glm")
print(m)
# Access local models (e.g. species "Y5")
m$model$Y5
coef(m$model$Y5)
# The fitted model can be plotted with `plot(m)`
# Fit a sparse model in the Bayesian framework with the horshoe prior
# \donttest{
m = trophicSDM(Y,X,G, env.formula,
family = binomial(link = "logit"), penal = "horshoe",
mode = "prey", method = "stan_glm")
# }
# Fit frequentist glm
m = trophicSDM(Y,X,G, env.formula,
family = binomial(link = "logit"), penal = NULL,
mode = "prey", method = "glm")
# With elasticnet penalty
m = trophicSDM(Y,X,G, env.formula,
family = binomial(link = "logit"), penal = "elasticnet",
mode = "prey", method = "glm")
#### Composite variables
# See vignette 'Composite variables' for a complete introduction to the use of composite variables
# Model species as a function of a quadratic polynomial of prey richness
m = trophicSDM(Y,X,G, env.formula,
family = binomial(link = "logit"), penal = NULL,
sp.formula = "richness + I(richness^2)",
mode = "prey", method = "glm")
m$form.all
# Notice that for predators that feed on a single prey (with presence-absence data),
# their richness and the square of their richness is exactly the same variable
# In this case, `trophicSDM()` removes the redundant variable but prints a warning message
# Model species as a function of a dummy variable saying whether they have at leaste one prey
m = trophicSDM(Y,X,G, env.formula,
family = binomial(link = "logit"), penal = NULL,
sp.formula = "I(richness>0)",
mode = "prey", method = "glm")
m$form.all
# Define group of preys and model species as a function of the richness (with a quadratic term)
# of these groups of preys separately
# Species Y1 and Y2 belong to the same group, species Y3 and Y4 are both alone in their group and
# species Y5 and Y6 form another group
sp.partition = list(c("Y1","Y2"),c("Y3"),c("Y4"), c("Y5","Y6"))
m = trophicSDM(Y,X,G, env.formula,
family = binomial(link = "logit"), penal = NULL,
sp.partition = sp.partition,
sp.formula = "richness + I(richness^2)",
mode = "prey", method = "glm")
m$form.all
Run the code above in your browser using DataLab