I’m using glm to see whether there is an association between zooplankton biomass (response) with two variables: 1) hours from high tide (high tide is zero, hours before are negative at one hourly intervals and hours after are positive at one hourly intervals) and 2) fish behaviour, which has three levels (feeding (F), not feeding (NF) and absent (A), where A is the reference category).
To account for the tide's circular nature (∼12-hr cycle), I have transformed the variable using a truncated Fourier series (a harmonic function of sines and cosines).
I used a gamma error structure and log-link function because zooplankton biomass is not normally distributed (while transforming zooplankton biomass using log10()
did give me a normal distribution, allowing the use of a Gaussian distribution, the model residuals were not normally distributed, so I decided it would be best to stick with gamma as I think they are acceptable)
A reproducible example is given below.
My questions are:
- Is it necessary to transform the tide variable using a truncated Fourier series?
- If yes to question 1, how should I test interactions between behaviour and the tide? For example, should I test the interactions of behaviour with all possible combinations of the sin and cos tide variables and select the most appropriate model using AICc?
- If the answer to question 1 is no, I have included an interaction effect between behaviour and tide in model3 below. I have used
exp(coef(model3))[2]
for the significant association between biomass and behaviourF, which gives me 4.35. Is it correct to say that zooplankton biomass is 4.35-fold higher when fish are feeding than when they are absent? If so, how do I interpret the interaction effect between tide and behaviourF?exp(coef(model3))[5]
for behaviourF:tide is 0.98.
#dataframe
tide_values <- c(1,1,-1,4,4,4,4,3,-4,-3,-2,4,5,1,-3,-6,-6,3,4,2,2,3,1,0,6,7,0,1,0,0,5,5,4,5,-2,2,2,-3,2,3,4,5,-3,-3,-2,-2,0,0,1,5,-3,5,3,-2,-1,-1,0,0,0,-3,6,5,6,5,0,0,2,-4,-4,1,3,-1,-4,5,-5,6,4,1,-4,-4,6,-6,0,4,2,1,-4,-2,-1)
biomass_values <- c(22.92,21.27,13.4,12.52,42.81,34.99,53.65,25.83,22.37,8.81,8.99,15.35,17.04,8.54,5.75,1.39,5.84,4.42,2.98,16.92,6.14,6.55,66.52,7.74,62.18,6.88,31,19.6,9.29,11.93,19.81,18.56,34.93,41.67,43.8,131.97,58.36,84.86,36.81,14.18,111.83,26.51,214.2,34.1,200.32,60.31,14.59,20.26,43.68,17.83,325.28,23.04,21.81,18.81,8.58,15.79,25.54,3.87,1.8,4.42,58.61,7.63,9.94,11.51,11.89,8.71,22.29,9.71,2.45,2.17,20.18,28.92,99.06,1.93,25.71,1.15,8.44,5.79,3.28,2.18,4.75,8.61,1.54,3.92,2.19,1.85,11.45,8.75,3.86)
behaviour<-c("A","A","F","F","F","F","F","F","A","A","F","F","F","A","NF","A","A","A","A","F","NF","NF","F","A","F","A","A","F","A","A","A","A","NF","NF","F","F","F","F","F","F","A","F","F","A","F","F","NF","F","F","F","F","F","F","NF","A","A","F","A","A","A","F","A","A","A","A","F","F","A","A","F","F","A","F","A","A","A","A","A","A","A","A","A","A","A","A","NF","F","F","F")
data <- data.frame(BIOMASS = biomass_values,tide = tide_values, behaviour = behaviour )
head(data)
#transform tide variable
# Define the number of harmonics to include
num_harmonics <- 3
# Create the Fourier series terms
for (k in 1:num_harmonics) {
data[[paste0("sin_", k)]] <- sin(2 * pi * k * data$tide / 12)
data[[paste0("cos_", k)]] <- cos(2 * pi * k * data$tide / 12)
}
head(data)
# Fit the GLM model with Gamma error structure and log link
#full model with tide transformation
model1<-glm(BIOMASS ~ behaviour + tide + sin_1 + sin_2 + sin_3 + cos_1 + cos_2 + cos_3, data = data, family = Gamma(link = "log"))
#model with interaction effect with tide transformation
model2<-glm(BIOMASS ~ behaviour * tide + sin_1 + sin_2 + sin_3 + cos_1 + cos_2 + cos_3, data = data, family = Gamma(link = "log"))
#model without tide transformation and intercation effect
model3<-glm(BIOMASS ~ behaviour * tide, data = data, family = Gamma(link = "log"))
summary(model3)
exp(coef(model3))[2] # zooplankton biomass is 4.35-fold higher when fish are feeding?
exp(coef(model3))[3] # = 0.98, how do I interpret this interaction effect