Applications

You can do as many kinds of modelling in a GLM as in a linear model. Here we show examples of:

  • regression with binomial errors (continuous explanatory variables);
  • analysis of deviance with binomial errors (categorical explanatory variables);
  • analysis of covariance with binomial errors (both kinds of explanatory variables).

Logistic Regression with Binomial Errors

This example concerns sex ratios in insects (the proportion of all individuals that are males). In the species in question, it has been observed that the sex ratio is highly variable, and an experiment was set up to see whether population density was involved in determining the fraction of males.

numbers <-read.table("c:\\temp\\sexratio.txt",header=T)
numbers
   density  females  males
1        1        1      0
2        4        3      1
3       10        7      3
4       22       18      4
5       55       22     33
6      121       41     80
7      210       52    158
8      444       79    365

It certainly looks as if there are proportionally more males at high density, but we should plot the data as proportions to see this more clearly:

attach(numbers)
par(mfrow=c(1,2))
p<-males/(males+females)
plot(density,p,ylab="Proportion male")
plot(log(density),p,ylab="Proportion male")

Evidently, a logarithmic transformation of the explanatory variable is likely to improve the model fit. We shall see in a moment.

The question is whether increasing population density leads to a significant increase in the proportion of males in the population – or, more briefly, whether the sex ratio is density-dependent. It certainly looks from the plot as ...

Get The R Book now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.