################################## # Keynes Data ################################## keynes = read.table("http://faculty.chicagobooth.edu/nicholas.polson/teaching/41000/keynes.txt",header=T) attach(keynes) # Plot the data plot(Year,Keynes,pch=20,col=34) plot(Market, Keynes, xlab="Market Return", ylab="Keynes Excess Return",col=20) # correlation matrix cor(cbind(Keynes,Market)) # Fit the least-squares line. model = lm(Keynes~Market) abline(model) title("Keynes vs Market") # Extract the model coefficients coef(model) summary(model) # 4-in-1 residual diagnostics layout(matrix(c(1,2,3,4),2,2)) plot(model,pch=20) # Calculate excess return Keynes = Keynes - Rate Market = Market - Rate # correlation matrix cor(cbind(Keynes,Market)) modelnew = lm(Keynes~Market) summary(modelnew)