How to assemble models for GLM in R

1

I would like to make a GLM with the following variables:

Variable response: EVI

Independent variables: % of forest, edge density, number of fragments, temperature and precipitation.

Someone could kindly help me mount the models, I have no idea how to proceed.

    
asked by anonymous 10.03.2017 / 01:22

2 answers

1

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.

    
14.03.2017 / 02:42
0

I'm trying to run here, but this message appears. I think the problem is in the assembly of the model that I'm not doing right.

The message that appears is this:

  

library (car)   plot (data)   Error in plot.window (...): finite values are required for 'xlim'   In addition: Warning messages:   1: In data.matrix (x): NAs introduced by coercion   2: In min (x): no non-missing arguments to min; returning Inf   3: In max (x): in non-missing arguments to max; returning -Inf   names   [1] "landscape" "forest" "evi" "ndvi" "db"
  [6] "pre" "solo"
  m.completo = glm (evi ~ forest + db + prec * solo, family = binomial)   Warning message:   In eval (expr, envir, enclos): # non-integer steps in a binomial glm!

My script is this: (at least the beginning of it until it gives the error)

################### GLM binomial distribution

View (data) attach summary library (car) plot (data)

forest = percentage of forest in each landscape

evi = improved vegetation index

ndvi = normalized difference vegetation index

db = edge density given in meters

prec = precipitation given in millimeters

solo = solo type

Construct a model to check which of the variables explains the response variable (EVI)

proportion data: link function logit = log (p / 1-p)

names m.completo = glm (evi ~ forest + db + prec * solo, family = binomial) m.n = glm (evi ~ forest) ~ 1, family = binomial) anova (m.completo, m.n, test="Chisq")

P.S. Help!

    
01.04.2017 / 01:25