Generalized linear models
When you have data that is "count" or "binary" in nature (e.g. not continuous numeric or Categorical covariates), you cannot use Linear models for modelling since these rely on an assumption that the data is continuously Gaussian distributed. We call this a Gaussian Observation Model.
Different kinds of observation models which are a better estimation of the true distribution must be used instead, and a "generalized linear model", which allows for other observation models, must be used. This is often the case with ecological data, when you are looking at counts or species density, so GLMs and GLMMs are often used.
Components of a GLM
Observation model vs likelihood function
An Observation model tells us how the data is distributed. This could be Gaussian, Binomial (Bernouilli), Poisson Distributions etc.
Likelihood function
This tells us the probability (likelihood) of having a certain mean or standard deviation value when treating the response and covariate data as fixed. In this case, in the frequentist approach, we are considering the mean and SD to be non-fixed. We just pick the optimal values in order for the probability to fit our fixed data the best.
Choosing a generalized linear model
- There is no standard workflow that tells us which model to use for any situation, but there are some general rules.
Steps to choose a model
- Define your research question mathematically. For example:
Do the populations of herring in the southern part of the north sea have a different mean length to the populations in the south? We define the population mean as a parameter and compare those two parameters.
Or:
Do current and past temperature and precipitation values have an affect on the count (abundance) of birds measured in standardized spring transects?
- Define the properties of your data formally.
- What type of values do the outcomes (response variable) take?
- What type of values do the covariates take? Numeric, categorical, count, binary?
- How and where was your data collected? Was it a transect, did you use different locations? This can affect whether you need to add Random Effects or other parameters.
- Define an initial model based on these definitions.
- Look through the literature to try and find similar problems, and possibly revise your model if needed. This is especially important if you have a strange kind of data.
Observation Models
List of Observation Models
Example - Bird Survey GLM
We are given an example of a bird survey
Model definition
Beta is considered a fixed effect (fixed at 1) for the covariates?
Implementation in R
# x1 to x4 are temp and precipitation for this year and last year
model = glm(Y ~ x1 + x2 + x3 + x4 + offset(log(TransectLength)), family=poisson, data=da)
We will talk more about Random Effects next week.
We are simplifying quite a bit here by just using transect length instead of defining an area. This is the point of using Random Effects, to include ecological covariates that are left out from the model because we don't have the data. For example, a more open site like on the sea or a field will have better visibility and allow you to see more birds that are further away than in a forest.
Some models have more complex ways to account for this - for example when surveying for whales in the ocean you might define a gradient where probability of observing a whale decreases as you get further from the boat.
What if we were just looking at occurrence instead of counts?
- If we instead of looking at the count of species and we instead were just interested in whether the species occurs or not in each transect, we can use the Bernoulli observation model
- We use the
of the sampled area as the log link function
In R:
model = glm(Y ~ x1 + x2 + x3 + x4 + log(TransectLength), family=binomial, data=da)
The main difference is not using the offset() function around the log(TransectLength), which is only used in count data models.
Model summary criteria in R
- When we are using a GLM with Poisson or another observation model, instead of being given r-squared, residuals, F-statistics and confidence intervals, we are given "Null deviance", "Residual deviance" and "AIC".
- This is because our data is no longer Gaussian so the predictors we used before don't work.
Deviance:
???
Null Deviance
- The deviance under the null model
Residual deviance
- The deviance under the model with the fixed effects
So, if you have a high null deviance and low residual deviance, this is an indication that you have a pretty good model.
AIC
- Residual sum of squares doesn't make sense in GLMs anymore. Instead we can use this AIC, which we will talk about more later. For now we can think of it as a similar metric to r-squared