Here is a little background about my situation: my data refer to the number of prey successfully eaten by a predator. As the number of prey is limited (25 available) in each trial, I had a column "Sample" representing the number of available prey (so, 25 in each trial), and another called "Count" which was the number of success (how many prey were eaten). I based my analysis on the example from the R book on proportion data (page 578). The explanatory variables are Temperature (4 levels, which I treated as factor), and Sex of the predator (obviously, male or female). So I end up with this model:
model <- glm(y ~ Temperature + Sex + Temperature*Sex,
data=predator, family=quasibinomial)
After getting the Analysis of Deviance table, it turns out that Temperature and Sex (but not the interaction) have a significant effect on the consumption of prey. Now, my problem: I need to know which temperatures differ, i.e., I have to compare the 4 temperatures to each other. If I had a linear model, I would use the TukeyHSD
function, but as I am using a GLM I can't. I have been looking through the package MASS and trying to set up a contrast matrix but for some reason it doesn't work. Any suggestions or references?
Here's the summary I get from my model, if that helps making it clearer ...
y <- cbind(data$Count, data$Sample-data$Count)
model <- glm(y ~ Temperature + Sex + Temperature*Sex,
data=predator, family=quasibinomial)
> summary(model)
# Call:
# glm(formula = y ~ Temperature + Sex + Temperature * Sex,
family=quasibinomial, data=data)
# Deviance Residuals:
# Min 1Q Median 3Q Max
# -3.7926 -1.4308 -0.3098 0.9438 3.6831
# Coefficients:
# Estimate Std. Error t value Pr(>|t|)
# (Intercept) -1.6094 0.2672 -6.024 3.86e-08 ***
# Temperature8 0.3438 0.3594 0.957 0.3414
# Temperature11 -1.0296 0.4803 -2.144 0.0348 *
# Temperature15 -1.2669 0.5174 -2.449 0.0163 *
# SexMale 0.3822 0.3577 1.069 0.2882
# Temperature8:SexMale -0.2152 0.4884 -0.441 0.6606
# Temperature11:SexMale 0.4136 0.6093 0.679 0.4990
# Temperature15:SexMale 0.4370 0.6503 0.672 0.5033
# ---
# Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# (Dispersion parameter for quasibinomial family taken to be 2.97372)
# Null deviance: 384.54 on 95 degrees of freedom
# Residual deviance: 289.45 on 88 degrees of freedom
# AIC: NA
# Number of Fisher Scoring iterations: 5
glht
function in themultcomp
package. To perform TukeyHSD tests for temperature, use it like thatglht(my.glm, mcp(Temperature="Tukey"))
. And btw: Your model formula can be abbreviated to:model<-glm(y ~ Temperature*Sex data=predator, family=quasibinomial)
. With the asterisk ($*$) the interactions and the main effects are fitted. $\endgroup$Temperature
as a factor? Don't you have the actual numerical values? I would use them as a continuous variable & then this entire issue is moot. $\endgroup$