There are several packages to fit generalized linear models (GLM) in R. However, people are probably more likely to use the glm
function that already comes in the base R.
To fit a model using the glm
function you need to pass the model formula, the distribution family you want to adjust (for example, binomial
for binary data, poisson
for count data, gaussian
for the traditional linear model, and so on) along with the link (for example, probit
, logit
or cloglog
to binomial
). If you do not specify the link, R will use the default for the chosen distribution.
Let's look at an example with logistic regression. Simulating some sample data:
set.seed(10)
x <- rnorm(1000)
prob <- plogis(-2*x)
y <- rbinom(1000, 1, prob)
And now adjusting the template:
glm(y ~ x, family = binomial(link = logit))
Call: glm(formula = y ~ x, family = binomial(link = logit))
Coefficients:
(Intercept) x
-0.01969 -1.94726
Degrees of Freedom: 999 Total (i.e. Null); 998 Residual
Null Deviance: 1386
Residual Deviance: 931.9 AIC: 935.9
Other packages that advance in generalized linear models are glmnet for glm
with penalty (L1, L2 or both), the lme4 for templates glm
com mixed effects, vgam for vector generalized linear models.
So to start you have to have an idea of which model (s) you want to adjust and more or less follow the ideas outlined above. In your case, your formula would be something like EVI ~ forest% + edge density + number of fragments + temperature + precipitation etc. or other more appropriate functional form ... meanwhile, explain what functional form you have to adopt, or which distribution or link you have to choose is something specific that involves statistical and substantive knowledge of your problem and runs away from the StackOverflow scope.