pdf("mathlsd.pdf") # Read in data from ASCII formatted (Fixed Width File) mathlsddat <- read.fwf("C:\\data\\mathlsd.dat", width=c(4,8), col.names=c("lsd","math")) # Create a dataset (frame) from input data mathlsd <- data.frame(mathlsddat) # Attach the dataset for analysis attach(mathlsd) mathlsd # Fit the simple linear regression model with dependent variable = math (score) # and independent variable = lsd (concentration) mathlsd.reg <- lm(math ~ lsd) # Plot the data and regression line (Note you enter X first, then Y in plot statement) plot(lsd,math) abline(mathlsd.reg) # 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 cor(math,lsd) # Test whether the population correlation coefficient is 0 (Identical to t-test for slope of regression line) cor.test(math,lsd) dev.off()