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

!lecture_slides_week3, p.2

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

Steps to choose a model

  1. 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?

  1. 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.
  2. Define an initial model based on these definitions.
  3. 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

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.

More complex models

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?

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

Deviance:

D=−2log⁡(p(y|α,β))D=−2log⁡[12πσ2+(−∑i=1nyi−(α+βxi))2σ2]

???

Null Deviance

Residual deviance

So, if you have a high null deviance and low residual deviance, this is an indication that you have a pretty good model.

AIC