# Exercise Corsican Blue tip ### 1) CorsBT<-read.csv("Corsican_blue_tit.csv") CorsBT[,1:2]<-apply(CorsBT[,1:2],2,function(x){x<-as.Date(x, format = "%d %B %Y")}) CorsBT$Building=as.Date(CorsBT$Building,origin='1970-01-01') CorsBT$Laying=as.Date(CorsBT$Laying,origin='1970-01-01') BuildLayGap<-CorsBT$Laying-CorsBT$Building BuildLayGap<-as.numeric(BuildLayGap) ### first test for normality shapiro.test(BuildLayGap[1:6]) # Shapiro-Wilk normality test # #data: BuildLayGap[1:6] #W = 0.87257, p-value = 0.2367 # shapiro.test(BuildLayGap[7:12]) # Shapiro-Wilk normality test # #data: BuildLayGap[7:12] #W = 0.94146, p-value = 0.671 ##### Conclusion: Neither set of durations departs significantly from normal ### Now test for equal variance fligner.test(BuildLayGap~Location,data=CorsBT) # Fligner-Killeen test of homogeneity of variances # #data: BuildLayGap by Location #Fligner-Killeen:med chi-squared = 0.63518, df = 1, p-value = 0.4255 ### Both ok so we can apply a t-test CorsBT<-cbind(CorsBT,BuildLayGap) t.test(BuildLayGap[1:6],BuildLayGap[7:12],data=CorsBT) # Welch Two Sample t-test # #data: BuildLayGap[1:6] and BuildLayGap[7:12] #t = 4.8415, df = 8.9563, p-value = 0.000932 #alternative hypothesis: true difference in means is not equal to 0 #95 percent confidence interval: # 10.20454 28.12880 #sample estimates: #mean of x mean of y # 30.33333 11.16667 #### Conclusion: highly significant difference ### 2) D<-as.numeric(CorsBT$Laying-CorsBT$Building) a<-glm(D ~ CorsBT$Building*CorsBT$Location) summary(a) #Call: #glm(formula = D ~ CorsBT$Building * CorsBT$Location) # #Deviance Residuals: # Min 1Q Median 3Q Max #-8.569 -4.981 -1.873 4.923 10.402 # #Coefficients: # Estimate Std. Error t value Pr(>|t|) #(Intercept) 2.487e+01 7.312e+01 0.340 0.743 #CorsBT$Building -2.124e-03 1.132e-02 -0.188 0.856 #CorsBT$Locationmainland 1.845e+01 1.036e+02 0.178 0.863 #CorsBT$Building:CorsBT$Locationmainland 9.984e-05 1.609e-02 0.006 0.995 # #(Dispersion parameter for gaussian family taken to be 58.28636) # # Null deviance: 1572.25 on 11 degrees of freedom #Residual deviance: 466.29 on 8 degrees of freedom #AIC: 87.973 # #Number of Fisher Scoring iterations: 2 # #### conclusion: No interaction