### Transcriptome modulation during host shift is driven by secondary metabolites in desert Drosophila ### De Panis et al. ### Molecular Ecology, 2016 ### Developmental time analysis matrix<-read.csv("td_means.csv") head(matrix) library(lme4) # Mixed model # Selection of the model using AIC m1<-lmer(TD_mean~Cactus*Treatment+(1|Genotype), data=matrix) m2<-lmer(TD_mean~Cactus*Treatment+(1|Genotype:Treatment), data=matrix) m3<-lmer(TD_mean~Cactus*Treatment+(1|Genotype:Cactus), data=matrix) m4<-lmer(TD_mean~Cactus*Treatment+(1|Genotype)+(1|Genotype:Cactus), data=matrix) m5<-lmer(TD_mean~Cactus*Treatment+(1|Genotype)+(1|Genotype:Treatment), data=matrix) m6<-lmer(TD_mean~Cactus*Treatment+(1|Genotype:Cactus)+(1|Genotype:Treatment), data=matrix) m7<-lmer(TD_mean~Cactus*Treatment+(Treatment|Genotype)+(Cactus|Genotype), data=matrix) m8<-lmer(TD_mean~Cactus*Treatment+(Treatment|Genotype), data=matrix) m9<-lmer(TD_mean~Cactus*Treatment+(Cactus|Genotype), data=matrix) m10<-lmer(TD_mean~Cactus*Treatment+(Treatment:Cactus|Genotype), data=matrix) m11<-lmer(TD_mean~Cactus*Treatment+(Treatment|Genotype:Cactus)+(Cactus|Genotype:Treatment), data=matrix) AIC(m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11) #Best model: m6 M<-m6 # Tests of statistical assumptions # Homogeneity of variances res2<-resid(M) #res. fit2<-fitted(M) #pred. plot(fit2, res2) #res. vs. pred. rabs<-abs(res2) #abs. res. X<-as.factor(matrix$Cactus:matrix$Treatment) summary(aov(rabs~X)) #Levene #Normal distribution qqnorm(res2) #quant. obs. qqline(res2) #quant. library(car) qqPlot(res2) #qqplot shapiro.test(res2) #Shapiro hist(res2,breaks=10) #distribution has a slightly longer left tail (but ANOVA is robust to slight lack of normality) # Results summary(M) Anova(M, type="3") # random intercepts significance: m12<-lm(TD_mean~Cactus*Treatment, data=matrix) anova(M,m12)