math <- c(78.93,58.20,67.47,37.47,45.65,32.92,29.97) lsd <- c(1.17,2.97,3.26,4.69,5.83,6.00,6.41) # Fit the simple linear regression model with Y = math (score) and X = lsd (concentration) mathlsd.reg <- lm(math ~ lsd) #png("mathlsd1.png") # Plot the data and regression line (Note you enter X first, then Y in plot statement) plot(lsd,math) abline(mathlsd.reg) #dev.off() # Print out the estimates, standard errors and t-tests, R-Square, and F-test summary(mathlsd.reg) # Print out the ANOVA table (Sums of Squares and degrees of freedom) anova(mathlsd.reg) # Compute the correlation coefficient (r) and test if rho=0 cor(math,lsd) cor.test(math,lsd) #png("mathlsd2.png") # Plot Residuals versus Fitted Values plot(predict(mathlsd.reg),residuals(mathlsd.reg)) abline(h=0) #dev.off() # Print out standardized, studentized Residuals and Influence Measures round(rstandard(mathlsd.reg),4) round(rstudent(mathlsd.reg),4) influence.measures(mathlsd.reg)