# 10.1.1 library(MASS) head(faithful) install.packages("diptest") library(diptest) par(mfrow=c(1,2)) with(faithful,plot(waiting,eruptions,main="Faithful scatterplot",ylab="Eruption duration (mins)",xlab="Inter-ruption interval (mins)")) with(faithful,hist(eruptions,xlab="Eruption duration (mins)")) with(faithful,dip(waiting)) [1] 0.04143689 with(faithful,dip(eruptions)) [1] 0.09238103 ### We have a significant indication of bimodality in the intervals bet´ween eruptions ### we can use chi-squared splitting at the medians to see if there is a significant association topleft<-length(which(faithful$waiting < median(faithful$waiting) & faithful$eruptions > median(faithful$eruptions))) bottomleft<-length(which(faithful$waiting < median(faithful$waiting) & faithful$eruptions < median(faithful$eruptions))) topright<-length(which(faithful$waiting > median(faithful$waiting) & faithful$eruptions > median(faithful$eruptions))) bottomright<-length(which(faithful$waiting > median(faithful$waiting) & faithful$eruptions < median(faithful$eruptions))) chisq.test(matrix(c(topleft,bottomleft,topright,bottomright),nrow=2,byrow=FALSE)) # Chi-squared test for given probabilities # # data: matrix(c(bottomleft, topleft, bottomright, topright), nrow = TRUE, byrow = FALSE) # X-squared = 122.28, df = 3, p-value < 2.2e-16