Soilution to Problem 6. ====================== > cathed = read.table(file="cathed.txt") names(cathed) = c("Town","Style","Height","Length") ### 25 x 4: first col is factor of town names > plot(cathed[,4], cathed[,3], type="n", xlab="Length (feet)", ylab="Height (feet)", main= "English Cathedral Heights vs Lengths, by Style") points(cathed[cathed[,2]==0,4],cathed[cathed[,2]==0,3], pch=5) points(cathed[cathed[,2]==1,4],cathed[cathed[,2]==1,3], pch=18) tm0 = lm(Height ~ Length, data=cathed[cathed[,2]==0,])$coef abline(tm0[1],tm0[2], lty=3) tm1 = lm(Height ~ Length, data=cathed[cathed[,2]==1,])$coef abline(tm1[1],tm1[2], lty=1) legend(locator(), legend=c("Romanesque","Gothic"), pch=c(5,18), lty=c(3,1)) ## A slightly more detailed fit and plot (not needed for HW): plot(cathed[,4], cathed[,3], type="n", xlab="Length (feet)", ylab="Height (feet)", main= "English Cathedral Heights vs Lengths, by Style") points(cathed[cathed[,2]==0,4],cathed[cathed[,2]==0,3], pch=5) points(cathed[cathed[,2]==1,4],cathed[cathed[,2]==1,3], pch=18) tm0 = lm(Height ~ Length + I(Length^2), data=cathed[cathed[,2]==0,]) tm1 = lm(Height ~ Length, data=cathed[cathed[,2]==1,]) ordR = order(cathed$Length[cathed$Style==0]) ordG = order(cathed$Length[cathed$Style==1]) lines(cathed$Length[cathed$Style==0][ordR],tm0$fit[ordR], lty=7) lines(cathed$Length[cathed$Style==1][ordG],tm1$fit[ordG], lty=2) legend(locator(), legend=c("Roman. obs","Gothic obs","Roman. fit", "Gothic fit"), pch=c(5,18,-1,-1), lty=c(0,0,7,2))