# Read data in data <- read.table("osmeterium.csv", header=T, sep=",") # There are 2 cases of NA, remove them data1 <- na.omit(data) # Convert variables mate (yes or no) and group (1, 2 or 3) into factors data1$fmate <- as.factor(data1$mate) data1$fgroup <- as.factor(data1$group) # Run GLM with binomial errors m1 <- glm(fmate ~ fgroup * sizeratio, family = binomial,data=data1) summary(m1) m2 <- update(m1,.~.-fgroup:sizeratio) anova(m2,m1, test="Chi") summary(m2) m3 <- update(m2,.~.-sizeratio) anova(m3,m2,test="Chi") summary(m3) # Residuals and normality look fine par(mfrow=c(2,2)) plot(m3) # Perform contrasts to compare brush vs no brush and brush+ vs brush- contrasts(data1$fgroup) <- cbind(c(1,1,-2),c(1,-1,0)) colnames(contrasts(data1$fgroup)) <- c("brush vs no brush", "brush+ vs brush-") # Run GLM with binomial errors using contrasts c1 <- glm(fmate ~ fgroup * sizeratio, family = binomial,data=data1) summary(c1) c2 <- update(c1,.~.-fgroup:sizeratio) anova(c2,c1, test="Chi") summary(c2) c3 <- update(c2,.~.-sizeratio) anova(c3,c2, test="Chi") summary(c3) # Extract only successful mating trials to compare copulation times of groups 1, 2 and 3 data2 <- data1[data1$fmate=="1",] # Run linear model t1 <- lm(cop.time ~ fgroup * sizeratio, data=data2) summary(t1) t2 <- update(t1, ~.-fgroup:sizeratio) anova(t1,t2) summary(t2) t3 <- update(t2, ~.-sizeratio) anova(t2,t3) summary(t3) # Residuals and normality look fine par(mfrow=c(2,2)) plot(t3)