#MOTION ANALYSIS MODELS data <- read.table('damselmotion.csv', header=TRUE, sep=',') library(lme4) library(emmeans) data$trial <- as.factor(data$trial); data$orientation <- as.factor(data$orientation); data$angle <- as.factor(data$angle); data$size <- as.factor(data$size); data$fish=as.factor(data$fish); fit1=lmer((st)~ angle +size *orientation +(1|fish/trial), data=d) fit2=lmer((st)~ angle *size + orientation +(1|fish/trial), data=d) fit3=lmer((st)~ angle *size *orientation +(1|fish/trial), data=d) anova(fit1,fit3) # to test if interaction is significant anova(fit2,fit3) anova(fit3)#fit3 was best fit hist(residuals(fit3),40) #check normality of residuals plot(fit3) #check linearity of residuals qqnorm(residuals(fit3)) #more checking of residual normality qqline(residuals(fit3)) emmeans (fit3, specs = pairwise ~ angle * orientation*size, by= "angle",adjust = "bonf" )